Loading 3d-viewer/3d_canvas.cpp +25 −2 Original line number Original line Diff line number Diff line /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, you may find one here: * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * or you may search the http://www.gnu.org website for the version 2 license, * or you may write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ /** /** * @file 3d_canvas.cpp * @file 3d_canvas.cpp */ */ Loading Loading @@ -26,8 +49,8 @@ #include <trackball.h> #include <trackball.h> #include <3d_viewer_id.h> #include <3d_viewer_id.h> #include <textures/text_silk.c> #include <textures/text_silk.h> #include <textures/text_pcb.c> #include <textures/text_pcb.h> // ----------------- // ----------------- // helper function (from wxWidgets, opengl/cube.cpp sample // helper function (from wxWidgets, opengl/cube.cpp sample Loading 3d-viewer/3d_canvas.h +20 −6 Original line number Original line Diff line number Diff line Loading @@ -142,48 +142,62 @@ public: m_draw3dOffset.y = aPosY; m_draw3dOffset.y = aPosY; } } INFO3D_VISU& GetPrm3DVisu() const; private: private: /** /** * return true if we are in realistic mode render * return true if we are in realistic mode render */ */ bool isRealisticMode() const; bool isRealisticMode() const; /** /** * return true if aItem should be displayed * @return true if aItem should be displayed * @param aItem = an item of DISPLAY3D_FLG enum * @param aItem = an item of DISPLAY3D_FLG enum */ */ bool isEnabled( DISPLAY3D_FLG aItem ) const; bool isEnabled( DISPLAY3D_FLG aItem ) const; /* Helper function /** Helper function * @return true if aLayer should be displayed, false otherwise * @return true if aLayer should be displayed, false otherwise */ */ bool is3DLayerEnabled( LAYER_ID aLayer ) const; bool is3DLayerEnabled( LAYER_ID aLayer ) const; /** * @return the size of the board in pcb units */ wxSize getBoardSize() const; /** * @return the position of the board center in pcb units */ wxPoint getBoardCenter() const; /** /** * Helper function SetGLTechLayersColor * Helper function SetGLTechLayersColor * Initialize the color to draw the non copper layers * Initialize the color to draw the non copper layers * in realistic mode and normal mode. * in realistic mode and normal mode. */ */ void SetGLTechLayersColor( LAYER_NUM aLayer ); void setGLTechLayersColor( LAYER_NUM aLayer ); /** /** * Helper function SetGLCopperColor * Helper function SetGLCopperColor * Initialize the copper color to draw the board * Initialize the copper color to draw the board * in realistic mode (a golden yellow color ) * in realistic mode (a golden yellow color ) */ */ void SetGLCopperColor(); void setGLCopperColor(); /** /** * Helper function SetGLEpoxyColor * Helper function SetGLEpoxyColor * Initialize the color to draw the epoxy body board in realistic mode. * Initialize the color to draw the epoxy body board in realistic mode. */ */ void SetGLEpoxyColor( double aTransparency = 1.0 ); void setGLEpoxyColor( double aTransparency = 1.0 ); /** /** * Helper function SetGLSolderMaskColor * Helper function SetGLSolderMaskColor * Initialize the color to draw the solder mask layers in realistic mode. * Initialize the color to draw the solder mask layers in realistic mode. */ */ void SetGLSolderMaskColor( double aTransparency = 1.0 ); void setGLSolderMaskColor( double aTransparency = 1.0 ); /** /** * Function BuildBoard3DView * Function BuildBoard3DView Loading 3d-viewer/3d_draw.cpp +70 −78 Original line number Original line Diff line number Diff line Loading @@ -159,8 +159,8 @@ void EDA_3D_CANVAS::Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture, glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // move the board in order to draw it with its center at 0,0 3D coordinates // move the board in order to draw it with its center at 0,0 3D coordinates glTranslatef( -g_Parm_3D_Visu.m_BoardPos.x * g_Parm_3D_Visu.m_BiuTo3Dunits, glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits, -g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BiuTo3Dunits, -GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits, 0.0F ); 0.0F ); if( aDraw_body ) if( aDraw_body ) Loading Loading @@ -268,11 +268,11 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures() glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glLoadIdentity(); const double ZDIST_MAX = Millimeter2iu( 3.5 ) * g_Parm_3D_Visu.m_BiuTo3Dunits; const double ZDIST_MAX = Millimeter2iu( 3.5 ) * GetPrm3DVisu().m_BiuTo3Dunits; glOrtho( -g_Parm_3D_Visu.m_BoardSize.x * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, glOrtho( -GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, g_Parm_3D_Visu.m_BoardSize.x * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, -g_Parm_3D_Visu.m_BoardSize.y * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, -GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, g_Parm_3D_Visu.m_BoardSize.y * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, 0.0, ZDIST_MAX ); 0.0, ZDIST_MAX ); // Render FRONT shadow // Render FRONT shadow Loading @@ -295,10 +295,10 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures() // Render ALL BOARD shadow // Render ALL BOARD shadow glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glLoadIdentity(); glOrtho( -g_Parm_3D_Visu.m_BoardSize.x * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, glOrtho( -GetPrm3DVisu().m_BoardSize.x * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, g_Parm_3D_Visu.m_BoardSize.x * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.x * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, -g_Parm_3D_Visu.m_BoardSize.y * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, -GetPrm3DVisu().m_BoardSize.y * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, g_Parm_3D_Visu.m_BoardSize.y * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.y * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, 0.0, 6.0f * ZDIST_MAX ); 0.0, 6.0f * ZDIST_MAX ); glMatrixMode( GL_MODELVIEW ); glMatrixMode( GL_MODELVIEW ); Loading Loading @@ -366,23 +366,14 @@ void EDA_3D_CANVAS::Redraw() // Draw the background ( rectangle with color gradient) // Draw the background ( rectangle with color gradient) glBegin( GL_QUADS ); glBegin( GL_QUADS ); glColor4f( g_Parm_3D_Visu.m_BgColor_Top.m_Red, SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 ); g_Parm_3D_Visu.m_BgColor_Top.m_Green, g_Parm_3D_Visu.m_BgColor_Top.m_Blue, 1.0 ); glVertex2f( -1.0, 1.0 ); // Top left corner glVertex2f( -1.0, 1.0 ); // Top left corner glColor4f( g_Parm_3D_Visu.m_BgColor.m_Red, SetGLColor( GetPrm3DVisu().m_BgColor, 1.0 ); g_Parm_3D_Visu.m_BgColor.m_Green, g_Parm_3D_Visu.m_BgColor.m_Blue, 1.0 ); glVertex2f( -1.0,-1.0 ); // bottom left corner glVertex2f( -1.0,-1.0 ); // bottom left corner glVertex2f( 1.0,-1.0 ); // bottom right corner glVertex2f( 1.0,-1.0 ); // bottom right corner glColor4f( g_Parm_3D_Visu.m_BgColor_Top.m_Red, SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 ); g_Parm_3D_Visu.m_BgColor_Top.m_Green, g_Parm_3D_Visu.m_BgColor_Top.m_Blue, 1.0 ); glVertex2f( 1.0, 1.0 ); // top right corner glVertex2f( 1.0, 1.0 ); // top right corner glEnd(); glEnd(); Loading @@ -394,14 +385,14 @@ void EDA_3D_CANVAS::Redraw() glLoadIdentity(); glLoadIdentity(); #define MAX_VIEW_ANGLE 160.0 / 45.0 #define MAX_VIEW_ANGLE 160.0 / 45.0 if( g_Parm_3D_Visu.m_Zoom > MAX_VIEW_ANGLE ) if( GetPrm3DVisu().m_Zoom > MAX_VIEW_ANGLE ) g_Parm_3D_Visu.m_Zoom = MAX_VIEW_ANGLE; GetPrm3DVisu().m_Zoom = MAX_VIEW_ANGLE; if( Parent()->ModeIsOrtho() ) if( Parent()->ModeIsOrtho() ) { { // OrthoReductionFactor is chosen to provide roughly the same size as // OrthoReductionFactor is chosen to provide roughly the same size as // Perspective View // Perspective View const double orthoReductionFactor = 400 / g_Parm_3D_Visu.m_Zoom; const double orthoReductionFactor = 400 / GetPrm3DVisu().m_Zoom; // Initialize Projection Matrix for Ortographic View // Initialize Projection Matrix for Ortographic View glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor, glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor, Loading @@ -413,7 +404,7 @@ void EDA_3D_CANVAS::Redraw() double ratio_HV = (double) size.x / size.y; double ratio_HV = (double) size.x / size.y; // Initialize Projection Matrix for Perspective View // Initialize Projection Matrix for Perspective View gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 100 ); gluPerspective( 45.0 * GetPrm3DVisu().m_Zoom, ratio_HV, 1, 100 ); } } // position viewer // position viewer Loading @@ -434,12 +425,12 @@ void EDA_3D_CANVAS::Redraw() // Translate motion first, so rotations don't mess up the orientation... // Translate motion first, so rotations don't mess up the orientation... glTranslatef( m_draw3dOffset.x, m_draw3dOffset.y, 0.0F ); glTranslatef( m_draw3dOffset.x, m_draw3dOffset.y, 0.0F ); build_rotmatrix( mat, g_Parm_3D_Visu.m_Quat ); build_rotmatrix( mat, GetPrm3DVisu().m_Quat ); glMultMatrixf( &mat[0][0] ); glMultMatrixf( &mat[0][0] ); glRotatef( g_Parm_3D_Visu.m_Rot[0], 1.0, 0.0, 0.0 ); glRotatef( GetPrm3DVisu().m_Rot[0], 1.0, 0.0, 0.0 ); glRotatef( g_Parm_3D_Visu.m_Rot[1], 0.0, 1.0, 0.0 ); glRotatef( GetPrm3DVisu().m_Rot[1], 0.0, 1.0, 0.0 ); glRotatef( g_Parm_3D_Visu.m_Rot[2], 0.0, 0.0, 1.0 ); glRotatef( GetPrm3DVisu().m_Rot[2], 0.0, 0.0, 1.0 ); if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] ) if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] ) Loading @@ -449,8 +440,8 @@ void EDA_3D_CANVAS::Redraw() glCallList( m_glLists[GL_ID_AXIS] ); glCallList( m_glLists[GL_ID_AXIS] ); // move the board in order to draw it with its center at 0,0 3D coordinates // move the board in order to draw it with its center at 0,0 3D coordinates glTranslatef( -g_Parm_3D_Visu.m_BoardPos.x * g_Parm_3D_Visu.m_BiuTo3Dunits, glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits, -g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BiuTo3Dunits, -GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits, 0.0F ); 0.0F ); // draw all objects in lists // draw all objects in lists Loading @@ -467,7 +458,8 @@ void EDA_3D_CANVAS::Redraw() if( isEnabled( FL_SHOW_BOARD_BODY ) ) if( isEnabled( FL_SHOW_BOARD_BODY ) ) { { if( isEnabled( FL_SOLDERMASK ) || !isRealisticMode() ) if( !isEnabled( FL_RENDER_TEXTURES ) || isEnabled( FL_SOLDERMASK ) || !isRealisticMode() ) { { glDisable( GL_TEXTURE_2D ); glDisable( GL_TEXTURE_2D ); } } Loading @@ -488,9 +480,9 @@ void EDA_3D_CANVAS::Redraw() glEnable( GL_COLOR_MATERIAL ); glEnable( GL_COLOR_MATERIAL ); SetOpenGlDefaultMaterial(); SetOpenGlDefaultMaterial(); glm::vec4 specular( g_Parm_3D_Visu.m_CopperColor.m_Red * 0.3, glm::vec4 specular( GetPrm3DVisu().m_CopperColor.m_Red * 0.3, g_Parm_3D_Visu.m_CopperColor.m_Green * 0.3, GetPrm3DVisu().m_CopperColor.m_Green * 0.3, g_Parm_3D_Visu.m_CopperColor.m_Blue * 0.3, 1.0 ); GetPrm3DVisu().m_CopperColor.m_Blue * 0.3, 1.0 ); GLint shininess_value = 8; GLint shininess_value = 8; glMateriali ( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); glMateriali ( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); Loading Loading @@ -609,20 +601,20 @@ void EDA_3D_CANVAS::Redraw() void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList ) void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList ) { { // Use similar calculation as Grid limits, in 3D units // Use similar calculation as Grid limits, in 3D units wxSize brd_size = g_Parm_3D_Visu.m_BoardSize; wxSize brd_size = getBoardSize(); wxPoint brd_center_pos = g_Parm_3D_Visu.m_BoardPos; wxPoint brd_center_pos = getBoardCenter(); float xsize = brd_size.x; float xsize = brd_size.x; float ysize = brd_size.y; float ysize = brd_size.y; float scale = g_Parm_3D_Visu.m_BiuTo3Dunits; float scale = GetPrm3DVisu().m_BiuTo3Dunits; float xmin = (brd_center_pos.x - xsize / 2.0) * scale; float xmin = (brd_center_pos.x - xsize / 2.0) * scale; float xmax = (brd_center_pos.x + xsize / 2.0) * scale; float xmax = (brd_center_pos.x + xsize / 2.0) * scale; float ymin = (brd_center_pos.y - ysize / 2.0) * scale; float ymin = (brd_center_pos.y - ysize / 2.0) * scale; float ymax = (brd_center_pos.y + ysize / 2.0) * scale; float ymax = (brd_center_pos.y + ysize / 2.0) * scale; float zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Paste ); float zpos = GetPrm3DVisu().GetLayerZcoordBIU( F_Paste ); zpos *= g_Parm_3D_Visu.m_BiuTo3Dunits; zpos *= GetPrm3DVisu().m_BiuTo3Dunits; // Shadow FRONT // Shadow FRONT glNewList( aFrontList, GL_COMPILE ); glNewList( aFrontList, GL_COMPILE ); Loading @@ -640,8 +632,8 @@ void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint // Shadow BACK // Shadow BACK zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Paste ); zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Paste ); zpos *= g_Parm_3D_Visu.m_BiuTo3Dunits; zpos *= GetPrm3DVisu().m_BiuTo3Dunits; glNewList( aBacklist, GL_COMPILE ); glNewList( aBacklist, GL_COMPILE ); Loading @@ -661,7 +653,7 @@ void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint xsize = brd_size.x * SHADOW_BOARD_SCALE; xsize = brd_size.x * SHADOW_BOARD_SCALE; ysize = brd_size.y * SHADOW_BOARD_SCALE; ysize = brd_size.y * SHADOW_BOARD_SCALE; scale = g_Parm_3D_Visu.m_BiuTo3Dunits; scale = GetPrm3DVisu().m_BiuTo3Dunits; xmin = (brd_center_pos.x - xsize / 2.0) * scale; xmin = (brd_center_pos.x - xsize / 2.0) * scale; xmax = (brd_center_pos.x + xsize / 2.0) * scale; xmax = (brd_center_pos.x + xsize / 2.0) * scale; ymin = (brd_center_pos.y - ysize / 2.0) * scale; ymin = (brd_center_pos.y - ysize / 2.0) * scale; Loading Loading @@ -731,7 +723,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) CPOLYGONS_LIST currLayerHoles; // Contains holes for the current layer CPOLYGONS_LIST currLayerHoles; // Contains holes for the current layer bool throughHolesListBuilt = false; // flag to build the through hole polygon list only once bool throughHolesListBuilt = false; // flag to build the through hole polygon list only once LSET cu_set = LSET::AllCuMask( g_Parm_3D_Visu.m_CopperLayersCount ); LSET cu_set = LSET::AllCuMask( GetPrm3DVisu().m_CopperLayersCount ); #if 1 #if 1 LAYER_ID cu_seq[MAX_CU_LAYERS]; // preferred sequence, could have called CuStack() LAYER_ID cu_seq[MAX_CU_LAYERS]; // preferred sequence, could have called CuStack() Loading Loading @@ -774,7 +766,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) VIA *via = static_cast<VIA*>( track ); VIA *via = static_cast<VIA*>( track ); VIATYPE_T viatype = via->GetViaType(); VIATYPE_T viatype = via->GetViaType(); int holediameter = via->GetDrillValue(); int holediameter = via->GetDrillValue(); int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); int thickness = GetPrm3DVisu().GetCopperThicknessBIU(); int hole_outer_radius = (holediameter + thickness) / 2; int hole_outer_radius = (holediameter + thickness) / 2; if( viatype != VIA_THROUGH ) if( viatype != VIA_THROUGH ) Loading Loading @@ -875,12 +867,12 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) // Merge polygons, remove holes // Merge polygons, remove holes currLayerPolyset -= polysetHoles; currLayerPolyset -= polysetHoles; int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer ); if( realistic_mode ) if( realistic_mode ) { { SetGLCopperColor(); setGLCopperColor(); } } else else { { Loading @@ -894,7 +886,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) bufferPolys.ImportFrom( currLayerPolyset ); bufferPolys.ImportFrom( currLayerPolyset ); Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, thickness, thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); GetPrm3DVisu().m_BiuTo3Dunits ); if( isEnabled( FL_USE_COPPER_THICKNESS ) == true ) if( isEnabled( FL_USE_COPPER_THICKNESS ) == true ) { { Loading @@ -906,13 +898,13 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) if( bufferZonesPolys.GetCornersCount() ) if( bufferZonesPolys.GetCornersCount() ) Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos, Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos, thickness, thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); GetPrm3DVisu().m_BiuTo3Dunits ); throughHolesListBuilt = true; throughHolesListBuilt = true; } } if ( !isEnabled( FL_SHOW_BOARD_BODY ) ) if ( !isEnabled( FL_SHOW_BOARD_BODY ) ) { { SetGLCopperColor(); setGLCopperColor(); // Draw vias holes (vertical cylinders) // Draw vias holes (vertical cylinders) for( const TRACK* track = pcb->m_Track; track; track = track->Next() ) for( const TRACK* track = pcb->m_Track; track; track = track->Next() ) Loading @@ -938,7 +930,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) if( isRealisticMode() ) if( isRealisticMode() ) { { SetGLEpoxyColor( 0.95 ); setGLEpoxyColor( 0.95 ); } } else else { { Loading @@ -946,14 +938,14 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) SetGLColor( color, 0.7 ); SetGLColor( color, 0.7 ); } } float copper_thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); float copper_thickness = GetPrm3DVisu().GetCopperThicknessBIU(); // a small offset between substrate and external copper layer to avoid artifacts // a small offset between substrate and external copper layer to avoid artifacts // when drawing copper items on board // when drawing copper items on board float epsilon = Millimeter2iu( 0.01 ); float epsilon = Millimeter2iu( 0.01 ); float zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu ); float zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Cu ); float board_thickness = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Cu ) float board_thickness = GetPrm3DVisu().GetLayerZcoordBIU( F_Cu ) - g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu ); - GetPrm3DVisu().GetLayerZcoordBIU( B_Cu ); // items on copper layers and having a thickness = copper_thickness // items on copper layers and having a thickness = copper_thickness // are drawn from zpos - copper_thickness/2 to zpos + copper_thickness // are drawn from zpos - copper_thickness/2 to zpos + copper_thickness Loading Loading @@ -981,7 +973,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) if( bufferPcbOutlines.GetCornersCount() ) if( bufferPcbOutlines.GetCornersCount() ) { { Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0, Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0, board_thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); board_thickness, GetPrm3DVisu().m_BiuTo3Dunits ); } } glEndList(); glEndList(); Loading Loading @@ -1019,7 +1011,7 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() wxMessageBox( msg ); wxMessageBox( msg ); } } int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); int thickness = GetPrm3DVisu().GetCopperThicknessBIU(); // Add via holes // Add via holes for( VIA* via = GetFirstVia( pcb->m_Track ); via; for( VIA* via = GetFirstVia( pcb->m_Track ); via; Loading Loading @@ -1165,14 +1157,14 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() currLayerPolyset += polyset; currLayerPolyset += polyset; } } int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer ); if( layer == Edge_Cuts ) if( layer == Edge_Cuts ) { { thickness = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Cu ) thickness = GetPrm3DVisu().GetLayerZcoordBIU( F_Cu ) - g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu ); - GetPrm3DVisu().GetLayerZcoordBIU( B_Cu ); zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu ) zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Cu ) + (thickness / 2); + (thickness / 2); } } else else Loading @@ -1190,10 +1182,10 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() bufferPolys.RemoveAllContours(); bufferPolys.RemoveAllContours(); bufferPolys.ImportFrom( currLayerPolyset ); bufferPolys.ImportFrom( currLayerPolyset ); SetGLTechLayersColor( layer ); setGLTechLayersColor( layer ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); thickness, GetPrm3DVisu().m_BiuTo3Dunits ); } } } } Loading Loading @@ -1278,8 +1270,8 @@ void EDA_3D_CANVAS::BuildBoard3DAuxLayers() bufferPolys.ExportTo( polyset ); bufferPolys.ExportTo( polyset ); currLayerPolyset += polyset; currLayerPolyset += polyset; int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer ); // for Draw3D_SolidHorizontalPolyPolygons, // for Draw3D_SolidHorizontalPolyPolygons, // zpos it the middle between bottom and top sides. // zpos it the middle between bottom and top sides. // However for top layers, zpos should be the bottom layer pos, // However for top layers, zpos should be the bottom layer pos, Loading @@ -1292,10 +1284,10 @@ void EDA_3D_CANVAS::BuildBoard3DAuxLayers() bufferPolys.RemoveAllContours(); bufferPolys.RemoveAllContours(); bufferPolys.ImportFrom( currLayerPolyset ); bufferPolys.ImportFrom( currLayerPolyset ); SetGLTechLayersColor( layer ); setGLTechLayersColor( layer ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); thickness, GetPrm3DVisu().m_BiuTo3Dunits ); } } } } Loading @@ -1306,7 +1298,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List() wxBusyCursor dummy; wxBusyCursor dummy; // Build 3D board parameters: // Build 3D board parameters: g_Parm_3D_Visu.InitSettings( pcb ); GetPrm3DVisu().InitSettings( pcb ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); Loading @@ -1319,7 +1311,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List() m_glLists[GL_ID_GRID] = glGenLists( 1 ); m_glLists[GL_ID_GRID] = glGenLists( 1 ); glNewList( m_glLists[GL_ID_GRID], GL_COMPILE ); glNewList( m_glLists[GL_ID_GRID], GL_COMPILE ); Draw3DGrid( g_Parm_3D_Visu.m_3D_Grid ); Draw3DGrid( GetPrm3DVisu().m_3D_Grid ); glEndList(); glEndList(); } } Loading Loading @@ -1428,12 +1420,12 @@ void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas, // Read from disk and draws the footprint 3D shapes if exists // Read from disk and draws the footprint 3D shapes if exists S3D_MASTER* shape3D = m_3D_Drawings; S3D_MASTER* shape3D = m_3D_Drawings; double zpos = g_Parm_3D_Visu.GetModulesZcoord3DIU( IsFlipped() ); double zpos = glcanvas->GetPrm3DVisu().GetModulesZcoord3DIU( IsFlipped() ); glPushMatrix(); glPushMatrix(); glTranslatef( m_Pos.x * g_Parm_3D_Visu.m_BiuTo3Dunits, glTranslatef( m_Pos.x * glcanvas->GetPrm3DVisu().m_BiuTo3Dunits, -m_Pos.y * g_Parm_3D_Visu.m_BiuTo3Dunits, -m_Pos.y * glcanvas->GetPrm3DVisu().m_BiuTo3Dunits, zpos ); zpos ); if( m_Orient ) if( m_Orient ) Loading Loading @@ -1504,7 +1496,7 @@ bool EDA_3D_CANVAS::is3DLayerEnabled( LAYER_ID aLayer ) const case B_Cu: case B_Cu: case F_Cu: case F_Cu: return g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( aLayer ) return GetPrm3DVisu().m_BoardSettings->IsLayerVisible( aLayer ) || isRealisticMode(); || isRealisticMode(); break; break; Loading @@ -1514,7 +1506,7 @@ bool EDA_3D_CANVAS::is3DLayerEnabled( LAYER_ID aLayer ) const if( isRealisticMode() ) if( isRealisticMode() ) return false; return false; return g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( aLayer ); return GetPrm3DVisu().m_BoardSettings->IsLayerVisible( aLayer ); } } // The layer has a flag, return the flag // The layer has a flag, return the flag Loading 3d-viewer/3d_draw_basic_functions.cpp +7 −0 Original line number Original line Diff line number Diff line Loading @@ -130,6 +130,13 @@ void SetGLColor( EDA_COLOR_T color, double alpha ) glColor4f( red, green, blue, alpha ); glColor4f( red, green, blue, alpha ); } } void SetGLColor( S3D_COLOR& aColor, float aTransparency ) { glColor4f( aColor.m_Red, aColor.m_Green, aColor.m_Blue, aTransparency ); } static float m_texture_scale; static float m_texture_scale; void SetGLTexture( GLuint text_id, float scale ) void SetGLTexture( GLuint text_id, float scale ) Loading 3d-viewer/3d_draw_basic_functions.h +7 −0 Original line number Original line Diff line number Diff line Loading @@ -125,6 +125,13 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos, */ */ void SetGLColor( EDA_COLOR_T aColor, double aTransparency = 1.0 ); void SetGLColor( EDA_COLOR_T aColor, double aTransparency = 1.0 ); /** * Set the current 3D color from a S3D_COLOR color, with optional transparency * @param aColor = a S3D_COLOR RGB color index * @param aTransparency = the color transparency (default = 1.0 = no transparency) */ void SetGLColor( S3D_COLOR& aColor, float aTransparency ); /** /** * Set a texture id and a scale to apply when rendering the polygons * Set a texture id and a scale to apply when rendering the polygons Loading Loading
3d-viewer/3d_canvas.cpp +25 −2 Original line number Original line Diff line number Diff line /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, you may find one here: * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * or you may search the http://www.gnu.org website for the version 2 license, * or you may write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ /** /** * @file 3d_canvas.cpp * @file 3d_canvas.cpp */ */ Loading Loading @@ -26,8 +49,8 @@ #include <trackball.h> #include <trackball.h> #include <3d_viewer_id.h> #include <3d_viewer_id.h> #include <textures/text_silk.c> #include <textures/text_silk.h> #include <textures/text_pcb.c> #include <textures/text_pcb.h> // ----------------- // ----------------- // helper function (from wxWidgets, opengl/cube.cpp sample // helper function (from wxWidgets, opengl/cube.cpp sample Loading
3d-viewer/3d_canvas.h +20 −6 Original line number Original line Diff line number Diff line Loading @@ -142,48 +142,62 @@ public: m_draw3dOffset.y = aPosY; m_draw3dOffset.y = aPosY; } } INFO3D_VISU& GetPrm3DVisu() const; private: private: /** /** * return true if we are in realistic mode render * return true if we are in realistic mode render */ */ bool isRealisticMode() const; bool isRealisticMode() const; /** /** * return true if aItem should be displayed * @return true if aItem should be displayed * @param aItem = an item of DISPLAY3D_FLG enum * @param aItem = an item of DISPLAY3D_FLG enum */ */ bool isEnabled( DISPLAY3D_FLG aItem ) const; bool isEnabled( DISPLAY3D_FLG aItem ) const; /* Helper function /** Helper function * @return true if aLayer should be displayed, false otherwise * @return true if aLayer should be displayed, false otherwise */ */ bool is3DLayerEnabled( LAYER_ID aLayer ) const; bool is3DLayerEnabled( LAYER_ID aLayer ) const; /** * @return the size of the board in pcb units */ wxSize getBoardSize() const; /** * @return the position of the board center in pcb units */ wxPoint getBoardCenter() const; /** /** * Helper function SetGLTechLayersColor * Helper function SetGLTechLayersColor * Initialize the color to draw the non copper layers * Initialize the color to draw the non copper layers * in realistic mode and normal mode. * in realistic mode and normal mode. */ */ void SetGLTechLayersColor( LAYER_NUM aLayer ); void setGLTechLayersColor( LAYER_NUM aLayer ); /** /** * Helper function SetGLCopperColor * Helper function SetGLCopperColor * Initialize the copper color to draw the board * Initialize the copper color to draw the board * in realistic mode (a golden yellow color ) * in realistic mode (a golden yellow color ) */ */ void SetGLCopperColor(); void setGLCopperColor(); /** /** * Helper function SetGLEpoxyColor * Helper function SetGLEpoxyColor * Initialize the color to draw the epoxy body board in realistic mode. * Initialize the color to draw the epoxy body board in realistic mode. */ */ void SetGLEpoxyColor( double aTransparency = 1.0 ); void setGLEpoxyColor( double aTransparency = 1.0 ); /** /** * Helper function SetGLSolderMaskColor * Helper function SetGLSolderMaskColor * Initialize the color to draw the solder mask layers in realistic mode. * Initialize the color to draw the solder mask layers in realistic mode. */ */ void SetGLSolderMaskColor( double aTransparency = 1.0 ); void setGLSolderMaskColor( double aTransparency = 1.0 ); /** /** * Function BuildBoard3DView * Function BuildBoard3DView Loading
3d-viewer/3d_draw.cpp +70 −78 Original line number Original line Diff line number Diff line Loading @@ -159,8 +159,8 @@ void EDA_3D_CANVAS::Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture, glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // move the board in order to draw it with its center at 0,0 3D coordinates // move the board in order to draw it with its center at 0,0 3D coordinates glTranslatef( -g_Parm_3D_Visu.m_BoardPos.x * g_Parm_3D_Visu.m_BiuTo3Dunits, glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits, -g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BiuTo3Dunits, -GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits, 0.0F ); 0.0F ); if( aDraw_body ) if( aDraw_body ) Loading Loading @@ -268,11 +268,11 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures() glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glLoadIdentity(); const double ZDIST_MAX = Millimeter2iu( 3.5 ) * g_Parm_3D_Visu.m_BiuTo3Dunits; const double ZDIST_MAX = Millimeter2iu( 3.5 ) * GetPrm3DVisu().m_BiuTo3Dunits; glOrtho( -g_Parm_3D_Visu.m_BoardSize.x * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, glOrtho( -GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, g_Parm_3D_Visu.m_BoardSize.x * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, -g_Parm_3D_Visu.m_BoardSize.y * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, -GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, g_Parm_3D_Visu.m_BoardSize.y * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, 0.0, ZDIST_MAX ); 0.0, ZDIST_MAX ); // Render FRONT shadow // Render FRONT shadow Loading @@ -295,10 +295,10 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures() // Render ALL BOARD shadow // Render ALL BOARD shadow glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glLoadIdentity(); glOrtho( -g_Parm_3D_Visu.m_BoardSize.x * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, glOrtho( -GetPrm3DVisu().m_BoardSize.x * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, g_Parm_3D_Visu.m_BoardSize.x * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.x * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, -g_Parm_3D_Visu.m_BoardSize.y * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, -GetPrm3DVisu().m_BoardSize.y * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, g_Parm_3D_Visu.m_BoardSize.y * SHADOW_BOARD_SCALE * g_Parm_3D_Visu.m_BiuTo3Dunits / 2.0f, GetPrm3DVisu().m_BoardSize.y * SHADOW_BOARD_SCALE * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f, 0.0, 6.0f * ZDIST_MAX ); 0.0, 6.0f * ZDIST_MAX ); glMatrixMode( GL_MODELVIEW ); glMatrixMode( GL_MODELVIEW ); Loading Loading @@ -366,23 +366,14 @@ void EDA_3D_CANVAS::Redraw() // Draw the background ( rectangle with color gradient) // Draw the background ( rectangle with color gradient) glBegin( GL_QUADS ); glBegin( GL_QUADS ); glColor4f( g_Parm_3D_Visu.m_BgColor_Top.m_Red, SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 ); g_Parm_3D_Visu.m_BgColor_Top.m_Green, g_Parm_3D_Visu.m_BgColor_Top.m_Blue, 1.0 ); glVertex2f( -1.0, 1.0 ); // Top left corner glVertex2f( -1.0, 1.0 ); // Top left corner glColor4f( g_Parm_3D_Visu.m_BgColor.m_Red, SetGLColor( GetPrm3DVisu().m_BgColor, 1.0 ); g_Parm_3D_Visu.m_BgColor.m_Green, g_Parm_3D_Visu.m_BgColor.m_Blue, 1.0 ); glVertex2f( -1.0,-1.0 ); // bottom left corner glVertex2f( -1.0,-1.0 ); // bottom left corner glVertex2f( 1.0,-1.0 ); // bottom right corner glVertex2f( 1.0,-1.0 ); // bottom right corner glColor4f( g_Parm_3D_Visu.m_BgColor_Top.m_Red, SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 ); g_Parm_3D_Visu.m_BgColor_Top.m_Green, g_Parm_3D_Visu.m_BgColor_Top.m_Blue, 1.0 ); glVertex2f( 1.0, 1.0 ); // top right corner glVertex2f( 1.0, 1.0 ); // top right corner glEnd(); glEnd(); Loading @@ -394,14 +385,14 @@ void EDA_3D_CANVAS::Redraw() glLoadIdentity(); glLoadIdentity(); #define MAX_VIEW_ANGLE 160.0 / 45.0 #define MAX_VIEW_ANGLE 160.0 / 45.0 if( g_Parm_3D_Visu.m_Zoom > MAX_VIEW_ANGLE ) if( GetPrm3DVisu().m_Zoom > MAX_VIEW_ANGLE ) g_Parm_3D_Visu.m_Zoom = MAX_VIEW_ANGLE; GetPrm3DVisu().m_Zoom = MAX_VIEW_ANGLE; if( Parent()->ModeIsOrtho() ) if( Parent()->ModeIsOrtho() ) { { // OrthoReductionFactor is chosen to provide roughly the same size as // OrthoReductionFactor is chosen to provide roughly the same size as // Perspective View // Perspective View const double orthoReductionFactor = 400 / g_Parm_3D_Visu.m_Zoom; const double orthoReductionFactor = 400 / GetPrm3DVisu().m_Zoom; // Initialize Projection Matrix for Ortographic View // Initialize Projection Matrix for Ortographic View glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor, glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor, Loading @@ -413,7 +404,7 @@ void EDA_3D_CANVAS::Redraw() double ratio_HV = (double) size.x / size.y; double ratio_HV = (double) size.x / size.y; // Initialize Projection Matrix for Perspective View // Initialize Projection Matrix for Perspective View gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 100 ); gluPerspective( 45.0 * GetPrm3DVisu().m_Zoom, ratio_HV, 1, 100 ); } } // position viewer // position viewer Loading @@ -434,12 +425,12 @@ void EDA_3D_CANVAS::Redraw() // Translate motion first, so rotations don't mess up the orientation... // Translate motion first, so rotations don't mess up the orientation... glTranslatef( m_draw3dOffset.x, m_draw3dOffset.y, 0.0F ); glTranslatef( m_draw3dOffset.x, m_draw3dOffset.y, 0.0F ); build_rotmatrix( mat, g_Parm_3D_Visu.m_Quat ); build_rotmatrix( mat, GetPrm3DVisu().m_Quat ); glMultMatrixf( &mat[0][0] ); glMultMatrixf( &mat[0][0] ); glRotatef( g_Parm_3D_Visu.m_Rot[0], 1.0, 0.0, 0.0 ); glRotatef( GetPrm3DVisu().m_Rot[0], 1.0, 0.0, 0.0 ); glRotatef( g_Parm_3D_Visu.m_Rot[1], 0.0, 1.0, 0.0 ); glRotatef( GetPrm3DVisu().m_Rot[1], 0.0, 1.0, 0.0 ); glRotatef( g_Parm_3D_Visu.m_Rot[2], 0.0, 0.0, 1.0 ); glRotatef( GetPrm3DVisu().m_Rot[2], 0.0, 0.0, 1.0 ); if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] ) if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] ) Loading @@ -449,8 +440,8 @@ void EDA_3D_CANVAS::Redraw() glCallList( m_glLists[GL_ID_AXIS] ); glCallList( m_glLists[GL_ID_AXIS] ); // move the board in order to draw it with its center at 0,0 3D coordinates // move the board in order to draw it with its center at 0,0 3D coordinates glTranslatef( -g_Parm_3D_Visu.m_BoardPos.x * g_Parm_3D_Visu.m_BiuTo3Dunits, glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits, -g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BiuTo3Dunits, -GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits, 0.0F ); 0.0F ); // draw all objects in lists // draw all objects in lists Loading @@ -467,7 +458,8 @@ void EDA_3D_CANVAS::Redraw() if( isEnabled( FL_SHOW_BOARD_BODY ) ) if( isEnabled( FL_SHOW_BOARD_BODY ) ) { { if( isEnabled( FL_SOLDERMASK ) || !isRealisticMode() ) if( !isEnabled( FL_RENDER_TEXTURES ) || isEnabled( FL_SOLDERMASK ) || !isRealisticMode() ) { { glDisable( GL_TEXTURE_2D ); glDisable( GL_TEXTURE_2D ); } } Loading @@ -488,9 +480,9 @@ void EDA_3D_CANVAS::Redraw() glEnable( GL_COLOR_MATERIAL ); glEnable( GL_COLOR_MATERIAL ); SetOpenGlDefaultMaterial(); SetOpenGlDefaultMaterial(); glm::vec4 specular( g_Parm_3D_Visu.m_CopperColor.m_Red * 0.3, glm::vec4 specular( GetPrm3DVisu().m_CopperColor.m_Red * 0.3, g_Parm_3D_Visu.m_CopperColor.m_Green * 0.3, GetPrm3DVisu().m_CopperColor.m_Green * 0.3, g_Parm_3D_Visu.m_CopperColor.m_Blue * 0.3, 1.0 ); GetPrm3DVisu().m_CopperColor.m_Blue * 0.3, 1.0 ); GLint shininess_value = 8; GLint shininess_value = 8; glMateriali ( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); glMateriali ( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); Loading Loading @@ -609,20 +601,20 @@ void EDA_3D_CANVAS::Redraw() void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList ) void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList ) { { // Use similar calculation as Grid limits, in 3D units // Use similar calculation as Grid limits, in 3D units wxSize brd_size = g_Parm_3D_Visu.m_BoardSize; wxSize brd_size = getBoardSize(); wxPoint brd_center_pos = g_Parm_3D_Visu.m_BoardPos; wxPoint brd_center_pos = getBoardCenter(); float xsize = brd_size.x; float xsize = brd_size.x; float ysize = brd_size.y; float ysize = brd_size.y; float scale = g_Parm_3D_Visu.m_BiuTo3Dunits; float scale = GetPrm3DVisu().m_BiuTo3Dunits; float xmin = (brd_center_pos.x - xsize / 2.0) * scale; float xmin = (brd_center_pos.x - xsize / 2.0) * scale; float xmax = (brd_center_pos.x + xsize / 2.0) * scale; float xmax = (brd_center_pos.x + xsize / 2.0) * scale; float ymin = (brd_center_pos.y - ysize / 2.0) * scale; float ymin = (brd_center_pos.y - ysize / 2.0) * scale; float ymax = (brd_center_pos.y + ysize / 2.0) * scale; float ymax = (brd_center_pos.y + ysize / 2.0) * scale; float zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Paste ); float zpos = GetPrm3DVisu().GetLayerZcoordBIU( F_Paste ); zpos *= g_Parm_3D_Visu.m_BiuTo3Dunits; zpos *= GetPrm3DVisu().m_BiuTo3Dunits; // Shadow FRONT // Shadow FRONT glNewList( aFrontList, GL_COMPILE ); glNewList( aFrontList, GL_COMPILE ); Loading @@ -640,8 +632,8 @@ void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint // Shadow BACK // Shadow BACK zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Paste ); zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Paste ); zpos *= g_Parm_3D_Visu.m_BiuTo3Dunits; zpos *= GetPrm3DVisu().m_BiuTo3Dunits; glNewList( aBacklist, GL_COMPILE ); glNewList( aBacklist, GL_COMPILE ); Loading @@ -661,7 +653,7 @@ void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint xsize = brd_size.x * SHADOW_BOARD_SCALE; xsize = brd_size.x * SHADOW_BOARD_SCALE; ysize = brd_size.y * SHADOW_BOARD_SCALE; ysize = brd_size.y * SHADOW_BOARD_SCALE; scale = g_Parm_3D_Visu.m_BiuTo3Dunits; scale = GetPrm3DVisu().m_BiuTo3Dunits; xmin = (brd_center_pos.x - xsize / 2.0) * scale; xmin = (brd_center_pos.x - xsize / 2.0) * scale; xmax = (brd_center_pos.x + xsize / 2.0) * scale; xmax = (brd_center_pos.x + xsize / 2.0) * scale; ymin = (brd_center_pos.y - ysize / 2.0) * scale; ymin = (brd_center_pos.y - ysize / 2.0) * scale; Loading Loading @@ -731,7 +723,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) CPOLYGONS_LIST currLayerHoles; // Contains holes for the current layer CPOLYGONS_LIST currLayerHoles; // Contains holes for the current layer bool throughHolesListBuilt = false; // flag to build the through hole polygon list only once bool throughHolesListBuilt = false; // flag to build the through hole polygon list only once LSET cu_set = LSET::AllCuMask( g_Parm_3D_Visu.m_CopperLayersCount ); LSET cu_set = LSET::AllCuMask( GetPrm3DVisu().m_CopperLayersCount ); #if 1 #if 1 LAYER_ID cu_seq[MAX_CU_LAYERS]; // preferred sequence, could have called CuStack() LAYER_ID cu_seq[MAX_CU_LAYERS]; // preferred sequence, could have called CuStack() Loading Loading @@ -774,7 +766,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) VIA *via = static_cast<VIA*>( track ); VIA *via = static_cast<VIA*>( track ); VIATYPE_T viatype = via->GetViaType(); VIATYPE_T viatype = via->GetViaType(); int holediameter = via->GetDrillValue(); int holediameter = via->GetDrillValue(); int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); int thickness = GetPrm3DVisu().GetCopperThicknessBIU(); int hole_outer_radius = (holediameter + thickness) / 2; int hole_outer_radius = (holediameter + thickness) / 2; if( viatype != VIA_THROUGH ) if( viatype != VIA_THROUGH ) Loading Loading @@ -875,12 +867,12 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) // Merge polygons, remove holes // Merge polygons, remove holes currLayerPolyset -= polysetHoles; currLayerPolyset -= polysetHoles; int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer ); if( realistic_mode ) if( realistic_mode ) { { SetGLCopperColor(); setGLCopperColor(); } } else else { { Loading @@ -894,7 +886,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) bufferPolys.ImportFrom( currLayerPolyset ); bufferPolys.ImportFrom( currLayerPolyset ); Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, thickness, thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); GetPrm3DVisu().m_BiuTo3Dunits ); if( isEnabled( FL_USE_COPPER_THICKNESS ) == true ) if( isEnabled( FL_USE_COPPER_THICKNESS ) == true ) { { Loading @@ -906,13 +898,13 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) if( bufferZonesPolys.GetCornersCount() ) if( bufferZonesPolys.GetCornersCount() ) Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos, Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos, thickness, thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); GetPrm3DVisu().m_BiuTo3Dunits ); throughHolesListBuilt = true; throughHolesListBuilt = true; } } if ( !isEnabled( FL_SHOW_BOARD_BODY ) ) if ( !isEnabled( FL_SHOW_BOARD_BODY ) ) { { SetGLCopperColor(); setGLCopperColor(); // Draw vias holes (vertical cylinders) // Draw vias holes (vertical cylinders) for( const TRACK* track = pcb->m_Track; track; track = track->Next() ) for( const TRACK* track = pcb->m_Track; track; track = track->Next() ) Loading @@ -938,7 +930,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) if( isRealisticMode() ) if( isRealisticMode() ) { { SetGLEpoxyColor( 0.95 ); setGLEpoxyColor( 0.95 ); } } else else { { Loading @@ -946,14 +938,14 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) SetGLColor( color, 0.7 ); SetGLColor( color, 0.7 ); } } float copper_thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); float copper_thickness = GetPrm3DVisu().GetCopperThicknessBIU(); // a small offset between substrate and external copper layer to avoid artifacts // a small offset between substrate and external copper layer to avoid artifacts // when drawing copper items on board // when drawing copper items on board float epsilon = Millimeter2iu( 0.01 ); float epsilon = Millimeter2iu( 0.01 ); float zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu ); float zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Cu ); float board_thickness = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Cu ) float board_thickness = GetPrm3DVisu().GetLayerZcoordBIU( F_Cu ) - g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu ); - GetPrm3DVisu().GetLayerZcoordBIU( B_Cu ); // items on copper layers and having a thickness = copper_thickness // items on copper layers and having a thickness = copper_thickness // are drawn from zpos - copper_thickness/2 to zpos + copper_thickness // are drawn from zpos - copper_thickness/2 to zpos + copper_thickness Loading Loading @@ -981,7 +973,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList) if( bufferPcbOutlines.GetCornersCount() ) if( bufferPcbOutlines.GetCornersCount() ) { { Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0, Draw3D_SolidHorizontalPolyPolygons( bufferPcbOutlines, zpos + board_thickness/2.0, board_thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); board_thickness, GetPrm3DVisu().m_BiuTo3Dunits ); } } glEndList(); glEndList(); Loading Loading @@ -1019,7 +1011,7 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() wxMessageBox( msg ); wxMessageBox( msg ); } } int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); int thickness = GetPrm3DVisu().GetCopperThicknessBIU(); // Add via holes // Add via holes for( VIA* via = GetFirstVia( pcb->m_Track ); via; for( VIA* via = GetFirstVia( pcb->m_Track ); via; Loading Loading @@ -1165,14 +1157,14 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() currLayerPolyset += polyset; currLayerPolyset += polyset; } } int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer ); if( layer == Edge_Cuts ) if( layer == Edge_Cuts ) { { thickness = g_Parm_3D_Visu.GetLayerZcoordBIU( F_Cu ) thickness = GetPrm3DVisu().GetLayerZcoordBIU( F_Cu ) - g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu ); - GetPrm3DVisu().GetLayerZcoordBIU( B_Cu ); zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( B_Cu ) zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Cu ) + (thickness / 2); + (thickness / 2); } } else else Loading @@ -1190,10 +1182,10 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() bufferPolys.RemoveAllContours(); bufferPolys.RemoveAllContours(); bufferPolys.ImportFrom( currLayerPolyset ); bufferPolys.ImportFrom( currLayerPolyset ); SetGLTechLayersColor( layer ); setGLTechLayersColor( layer ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); thickness, GetPrm3DVisu().m_BiuTo3Dunits ); } } } } Loading Loading @@ -1278,8 +1270,8 @@ void EDA_3D_CANVAS::BuildBoard3DAuxLayers() bufferPolys.ExportTo( polyset ); bufferPolys.ExportTo( polyset ); currLayerPolyset += polyset; currLayerPolyset += polyset; int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer ); // for Draw3D_SolidHorizontalPolyPolygons, // for Draw3D_SolidHorizontalPolyPolygons, // zpos it the middle between bottom and top sides. // zpos it the middle between bottom and top sides. // However for top layers, zpos should be the bottom layer pos, // However for top layers, zpos should be the bottom layer pos, Loading @@ -1292,10 +1284,10 @@ void EDA_3D_CANVAS::BuildBoard3DAuxLayers() bufferPolys.RemoveAllContours(); bufferPolys.RemoveAllContours(); bufferPolys.ImportFrom( currLayerPolyset ); bufferPolys.ImportFrom( currLayerPolyset ); SetGLTechLayersColor( layer ); setGLTechLayersColor( layer ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); thickness, GetPrm3DVisu().m_BiuTo3Dunits ); } } } } Loading @@ -1306,7 +1298,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List() wxBusyCursor dummy; wxBusyCursor dummy; // Build 3D board parameters: // Build 3D board parameters: g_Parm_3D_Visu.InitSettings( pcb ); GetPrm3DVisu().InitSettings( pcb ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); Loading @@ -1319,7 +1311,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List() m_glLists[GL_ID_GRID] = glGenLists( 1 ); m_glLists[GL_ID_GRID] = glGenLists( 1 ); glNewList( m_glLists[GL_ID_GRID], GL_COMPILE ); glNewList( m_glLists[GL_ID_GRID], GL_COMPILE ); Draw3DGrid( g_Parm_3D_Visu.m_3D_Grid ); Draw3DGrid( GetPrm3DVisu().m_3D_Grid ); glEndList(); glEndList(); } } Loading Loading @@ -1428,12 +1420,12 @@ void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas, // Read from disk and draws the footprint 3D shapes if exists // Read from disk and draws the footprint 3D shapes if exists S3D_MASTER* shape3D = m_3D_Drawings; S3D_MASTER* shape3D = m_3D_Drawings; double zpos = g_Parm_3D_Visu.GetModulesZcoord3DIU( IsFlipped() ); double zpos = glcanvas->GetPrm3DVisu().GetModulesZcoord3DIU( IsFlipped() ); glPushMatrix(); glPushMatrix(); glTranslatef( m_Pos.x * g_Parm_3D_Visu.m_BiuTo3Dunits, glTranslatef( m_Pos.x * glcanvas->GetPrm3DVisu().m_BiuTo3Dunits, -m_Pos.y * g_Parm_3D_Visu.m_BiuTo3Dunits, -m_Pos.y * glcanvas->GetPrm3DVisu().m_BiuTo3Dunits, zpos ); zpos ); if( m_Orient ) if( m_Orient ) Loading Loading @@ -1504,7 +1496,7 @@ bool EDA_3D_CANVAS::is3DLayerEnabled( LAYER_ID aLayer ) const case B_Cu: case B_Cu: case F_Cu: case F_Cu: return g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( aLayer ) return GetPrm3DVisu().m_BoardSettings->IsLayerVisible( aLayer ) || isRealisticMode(); || isRealisticMode(); break; break; Loading @@ -1514,7 +1506,7 @@ bool EDA_3D_CANVAS::is3DLayerEnabled( LAYER_ID aLayer ) const if( isRealisticMode() ) if( isRealisticMode() ) return false; return false; return g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( aLayer ); return GetPrm3DVisu().m_BoardSettings->IsLayerVisible( aLayer ); } } // The layer has a flag, return the flag // The layer has a flag, return the flag Loading
3d-viewer/3d_draw_basic_functions.cpp +7 −0 Original line number Original line Diff line number Diff line Loading @@ -130,6 +130,13 @@ void SetGLColor( EDA_COLOR_T color, double alpha ) glColor4f( red, green, blue, alpha ); glColor4f( red, green, blue, alpha ); } } void SetGLColor( S3D_COLOR& aColor, float aTransparency ) { glColor4f( aColor.m_Red, aColor.m_Green, aColor.m_Blue, aTransparency ); } static float m_texture_scale; static float m_texture_scale; void SetGLTexture( GLuint text_id, float scale ) void SetGLTexture( GLuint text_id, float scale ) Loading
3d-viewer/3d_draw_basic_functions.h +7 −0 Original line number Original line Diff line number Diff line Loading @@ -125,6 +125,13 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos, */ */ void SetGLColor( EDA_COLOR_T aColor, double aTransparency = 1.0 ); void SetGLColor( EDA_COLOR_T aColor, double aTransparency = 1.0 ); /** * Set the current 3D color from a S3D_COLOR color, with optional transparency * @param aColor = a S3D_COLOR RGB color index * @param aTransparency = the color transparency (default = 1.0 = no transparency) */ void SetGLColor( S3D_COLOR& aColor, float aTransparency ); /** /** * Set a texture id and a scale to apply when rendering the polygons * Set a texture id and a scale to apply when rendering the polygons Loading