diff --git a/3d-viewer/3d_draw.cpp b/3d-viewer/3d_draw.cpp index 1d2609f6f9..4f102a4ffc 100644 --- a/3d-viewer/3d_draw.cpp +++ b/3d-viewer/3d_draw.cpp @@ -241,7 +241,7 @@ void EDA_3D_CANVAS::Draw3D_Zone( ZONE_CONTAINER* aZone ) if( layer == LAST_COPPER_LAYER ) layer = g_Parm_3D_Visu.m_CopperLayersCount - 1; - int zpos = KiROUND( g_Parm_3D_Visu.m_LayerZcoord[layer] / g_Parm_3D_Visu.m_BiuTo3Dunits ); + int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); SetGLColor( color ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); @@ -460,7 +460,7 @@ void EDA_3D_CANVAS::Draw3D_Track( TRACK* aTrack ) if( layer == LAST_COPPER_LAYER ) layer = g_Parm_3D_Visu.m_CopperLayersCount - 1; - int zpos = KiROUND( g_Parm_3D_Visu.m_LayerZcoord[layer] / g_Parm_3D_Visu.m_BiuTo3Dunits ); + int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); SetGLColor( color ); glNormal3f( 0.0, 0.0, (layer == LAYER_N_BACK) ? -1.0 : 1.0 ); @@ -485,7 +485,7 @@ void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) // Drawing horizontal thick rings: for( layer = bottom_layer; layer < g_Parm_3D_Visu.m_CopperLayersCount; layer++ ) { - int zpos = KiROUND( g_Parm_3D_Visu.m_LayerZcoord[layer] / biu_to_3Dunits ); + int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); if( layer < g_Parm_3D_Visu.m_CopperLayersCount - 1 ) { @@ -518,7 +518,7 @@ void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) color = g_ColorsSettings.GetItemColor( VIAS_VISIBLE + via->m_Shape ); SetGLColor( color ); int height = g_Parm_3D_Visu.GetLayerZcoordBIU(top_layer) - - g_Parm_3D_Visu.m_LayerZcoord[bottom_layer] - thickness; + g_Parm_3D_Visu.GetLayerZcoordBIU( bottom_layer ) - thickness; int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU(bottom_layer) + thickness/2; Draw3D_ZaxisCylinder( via->m_Start, inner_radius + thickness/2, height, @@ -625,7 +625,7 @@ void EDA_3D_CANVAS::Draw3D_DrawText( TEXTE_PCB* text ) int color = g_ColorsSettings.GetLayerColor( layer ); SetGLColor( color ); - s_Text3DZPos = KiROUND( g_Parm_3D_Visu.m_LayerZcoord[layer] / g_Parm_3D_Visu.m_BiuTo3Dunits ); + s_Text3DZPos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); s_Text3DWidth = text->GetThickness(); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); wxSize size = text->m_Size; @@ -681,13 +681,19 @@ void MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) S3D_MASTER* Struct3D = m_3D_Drawings; bool As3dShape = false; - if (g_Parm_3D_Visu.m_DrawFlags[g_Parm_3D_Visu.FL_MODULE]) + if( g_Parm_3D_Visu.m_DrawFlags[g_Parm_3D_Visu.FL_MODULE] ) { + double zpos; + if( m_Layer == LAYER_N_BACK ) + zpos = g_Parm_3D_Visu.GetModulesZcoord3DIU( true ); + else + zpos = g_Parm_3D_Visu.GetModulesZcoord3DIU( false ); + glPushMatrix(); glTranslatef( m_Pos.x * g_Parm_3D_Visu.m_BiuTo3Dunits, -m_Pos.y * g_Parm_3D_Visu.m_BiuTo3Dunits, - g_Parm_3D_Visu.m_LayerZcoord[m_Layer] ); + zpos ); if( m_Orient ) { diff --git a/3d-viewer/3d_draw_basic_functions.cpp b/3d-viewer/3d_draw_basic_functions.cpp index 08af97d0a4..7aa2831ce9 100644 --- a/3d-viewer/3d_draw_basic_functions.cpp +++ b/3d-viewer/3d_draw_basic_functions.cpp @@ -59,8 +59,8 @@ static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data ); * Used to create the vertical sides of 3D horizontal shapes with thickness. */ static void Draw3D_VerticalPolygonalCylinder( const std::vector& aPolysList, - int aHeight, - int aZpos, double aBiuTo3DUnits ) + int aHeight, int aZpos, + bool aInside, double aBiuTo3DUnits ) { if( aHeight == 0 ) return; @@ -69,8 +69,16 @@ static void Draw3D_VerticalPolygonalCylinder( const std::vector& aPolys coords.resize( 4 ); // Init Z position of the 4 points of a GL_QUAD - coords[0].z = aZpos; - coords[1].z = aZpos + aHeight; + if( aInside ) + { + coords[0].z = aZpos; + coords[1].z = aZpos + aHeight; + } + else + { + coords[0].z = aZpos + aHeight; + coords[1].z = aZpos; + } coords[2].z = coords[1].z; coords[3].z = coords[0].z; @@ -87,12 +95,12 @@ static void Draw3D_VerticalPolygonalCylinder( const std::vector& aPolys } // Build the 4 vertices of each GL_QUAD - coords[0].x = aPolysList[jj].x; - coords[0].y = -aPolysList[jj].y; + coords[0].x = aPolysList[ii].x; + coords[0].y = -aPolysList[ii].y; coords[1].x = coords[0].x; coords[1].y = coords[0].y; // only z change - coords[2].x = aPolysList[ii].x; - coords[2].y = -aPolysList[ii].y; + coords[2].x = aPolysList[jj].x; + coords[2].y = -aPolysList[jj].y; coords[3].x = coords[2].x; coords[3].y = coords[2].y; // only z change @@ -192,7 +200,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const std::vector& aPolysList, return; // Build the 3D data : vertical side - Draw3D_VerticalPolygonalCylinder( polylist, aThickness, aZpos, aBiuTo3DUnits ); + Draw3D_VerticalPolygonalCylinder( polylist, aThickness, aZpos, false, aBiuTo3DUnits ); glNormal3f( 0.0, 0.0, 1.0 ); } @@ -203,7 +211,8 @@ void Draw3D_SolidHorizontalPolyPolygons( const std::vector& aPolysList, * See Draw3D_SolidHorizontalPolyPolygons for more info */ void Draw3D_SolidHorizontalPolygonWithHoles( const std::vector& aPolysList, - int aZpos, int aThickness, double aBiuTo3DUnits ) + int aZpos, int aThickness, + double aBiuTo3DUnits ) { std::vector polygon; @@ -225,7 +234,7 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius, std::vector outer_cornerBuffer; TransformCircleToPolygon( outer_cornerBuffer, aCenterPos, - aRadius + (aThickness / 2), SEGM_PER_CIRCLE ); + aRadius + (aThickness / 2), slice ); std::vector coords; coords.resize( 4 ); @@ -239,11 +248,11 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius, { // Draw the vertical outer side Draw3D_VerticalPolygonalCylinder( outer_cornerBuffer, - aHeight, aZpos, aBiuTo3DUnits ); + aHeight, aZpos, false, aBiuTo3DUnits ); if( aThickness ) // Draws the vertical inner side (hole) Draw3D_VerticalPolygonalCylinder( inner_cornerBuffer, - aHeight, aZpos, aBiuTo3DUnits ); + aHeight, aZpos, true, aBiuTo3DUnits ); } if( aThickness ) @@ -286,32 +295,37 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos, // Build the points to approximate oblong cylinder by segments std::vector outer_cornerBuffer; - int width = aThickness + aRadius * 2; + int segm_width = (aRadius * 2) + aThickness; TransformRoundedEndsSegmentToPolygon( outer_cornerBuffer, aAxis1Pos, - aAxis2Pos, slice, width ); + aAxis2Pos, slice, segm_width ); // Draw the oblong outer cylinder if( aHeight ) - Draw3D_VerticalPolygonalCylinder( outer_cornerBuffer, aHeight, aZpos, aBiuTo3DUnits ); + Draw3D_VerticalPolygonalCylinder( outer_cornerBuffer, aHeight, aZpos, + false, aBiuTo3DUnits ); if( aThickness ) { std::vector inner_cornerBuffer; - width = aThickness - aRadius * 2; + segm_width = aRadius * 2; TransformRoundedEndsSegmentToPolygon( inner_cornerBuffer, aAxis1Pos, - aAxis2Pos, slice, width ); + aAxis2Pos, slice, segm_width ); // Draw the oblong inner cylinder if( aHeight ) Draw3D_VerticalPolygonalCylinder( inner_cornerBuffer, aHeight, - aZpos, aBiuTo3DUnits ); + true, aZpos, aBiuTo3DUnits ); + + // Build the horizontal full polygon shape + // (outer polygon shape - inner polygon shape) + outer_cornerBuffer.insert( outer_cornerBuffer.end(), + inner_cornerBuffer.begin(), + inner_cornerBuffer.end() ); + + std::vector polygon; + ConvertPolysListWithHolesToOnePolygon( outer_cornerBuffer, polygon ); // draw top (front) horizontal side (ring) - outer_cornerBuffer.insert( outer_cornerBuffer.end(), - inner_cornerBuffer.begin(), inner_cornerBuffer.end() ); - std::vector polygon; - - ConvertPolysListWithHolesToOnePolygon( outer_cornerBuffer, polygon ); glNormal3f( 0.0, 0.0, 1.0 ); Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits ); diff --git a/3d-viewer/info3d_visu.h b/3d-viewer/info3d_visu.h index 618387a9f3..5677cc9a55 100644 --- a/3d-viewer/info3d_visu.h +++ b/3d-viewer/info3d_visu.h @@ -78,7 +78,7 @@ public: double m_Quat[4]; // orientation of 3D view double m_Rot[4]; // rotation parameters of 3D view double m_Zoom; // 3D zoom value - double m_3D_Grid; // 3D grid valmue, in mm + double m_3D_Grid; // 3D grid value, in mm S3D_COLOR m_BgColor; bool m_DrawFlags[FL_LAST]; // Enable/disable flags (see DISPLAY3D_FLG list) wxPoint m_BoardPos; // center board actual position in board units @@ -90,10 +90,10 @@ public: double m_BiuTo3Dunits; // Normalization scale to convert board // internal units to 3D units // to scale 3D units between -1.0 and +1.0 - double m_LayerZcoord[LAYER_COUNT]; // Z position of each layer (normalized) double m_CurrentZpos; // temporary storage of current value of Z position, // used in some calculation private: + double m_LayerZcoord[LAYER_COUNT]; // Z position of each layer (normalized) double m_CopperThickness; // Copper thickness (normalized) double m_EpoxyThickness; // Epoxy thickness (normalized) double m_NonCopperLayerThickness; // Non copper layers thickness @@ -108,6 +108,21 @@ public: INFO3D_VISU(); */ void InitSettings( BOARD* aBoard ); + /** + * function GetModulesZcoord3DIU + * @return the Z coordinate of the module, in 3D Units + * @param aIsFlipped: true for modules on Front (top) layer, false + * if on back (bottom) layer + * Used to know the Z position of 3D shapes + */ + double GetModulesZcoord3DIU( bool aIsFlipped ) + { + if( aIsFlipped ) + return m_LayerZcoord[ADHESIVE_N_BACK] - m_NonCopperLayerThickness; + else + return m_LayerZcoord[ADHESIVE_N_FRONT] + m_NonCopperLayerThickness; + } + /** * function GetLayerZcoordBIU * @return the Z coordinate of the layer aLayer, in Board Internal Units