From 3a62a59514d9df80a500321e6d66f58a3649508d Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 12 Aug 2014 18:03:50 +0200 Subject: [PATCH] 3d viewer: fix a (minor) bug when run from cvpcb or modedit: the footprint is now centered on Z axis Better setup for lights, which gives a better rendering --- 3d-viewer/3d_canvas.cpp | 30 ++++++++++++++++++------------ 3d-viewer/info3d_visu.cpp | 11 +++++++---- utils/idftools/vrml_layer.cpp | 3 ++- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/3d-viewer/3d_canvas.cpp b/3d-viewer/3d_canvas.cpp index 76b6d78c35..7b4e28b857 100644 --- a/3d-viewer/3d_canvas.cpp +++ b/3d-viewer/3d_canvas.cpp @@ -567,28 +567,34 @@ void EDA_3D_CANVAS::InitGL() /* Initialize OpenGL light sources. */ void EDA_3D_CANVAS::SetLights() { - double light; - GLfloat light_color[4]; - /* set viewing projection */ - light_color[3] = 1.0; GLfloat Z_axis_pos[4] = { 0.0, 0.0, 30.0, 0.0 }; GLfloat lowZ_axis_pos[4] = { 0.0, 0.0, -30.0, 0.5 }; - /* activate light */ - light = 1.0; - light_color[0] = light_color[1] = light_color[2] = light; + // activate lights. 2 lights are used: + // One is above the xy plane, the other is below the xy plane + GLfloat light_color[4]; // color of lights (RGBA values) + light_color[3] = 1.0; + + // Light above the xy plane + // The default setting for GL_AMBIENT light intensity is (0.0, 0.0, 0.0, 1.0) glLightfv( GL_LIGHT0, GL_POSITION, Z_axis_pos ); + light_color[0] = light_color[1] = light_color[2] = 1.0; glLightfv( GL_LIGHT0, GL_DIFFUSE, light_color ); - light_color[0] = 0.3; - light_color[1] = 0.3; - light_color[2] = 0.4; + light_color[0] = light_color[1] = light_color[2] = 0.2; + glLightfv( GL_LIGHT0, GL_SPECULAR, light_color ); + // Light below the xy plane glLightfv( GL_LIGHT1, GL_POSITION, lowZ_axis_pos ); + light_color[0] = light_color[1] = light_color[2] = 0.4; glLightfv( GL_LIGHT1, GL_DIFFUSE, light_color ); - glEnable( GL_LIGHT0 ); // White spot on Z axis - glEnable( GL_LIGHT1 ); // White spot on Z axis ( bottom) + + light_color[0] = light_color[1] = light_color[2] = 0.1; + glLightfv( GL_LIGHT1, GL_SPECULAR, light_color ); + + glEnable( GL_LIGHT0 ); // White spot on Z axis ( top ) +// glEnable( GL_LIGHT1 ); // White spot on Z axis ( bottom ) glEnable( GL_LIGHTING ); } diff --git a/3d-viewer/info3d_visu.cpp b/3d-viewer/info3d_visu.cpp index a0417689b2..d096506049 100644 --- a/3d-viewer/info3d_visu.cpp +++ b/3d-viewer/info3d_visu.cpp @@ -85,14 +85,17 @@ INFO3D_VISU::~INFO3D_VISU() */ void INFO3D_VISU::InitSettings( BOARD* aBoard ) { + // Calculates the board bounding box + // First, use only the board outlines EDA_RECT bbbox = aBoard->ComputeBoundingBox( true ); + // If no outlines, use the board with items if( bbbox.GetWidth() == 0 && bbbox.GetHeight() == 0 ) - { - bbbox.SetWidth( Millimeter2iu( 100 ) ); - bbbox.SetHeight( Millimeter2iu( 100 ) ); - } + bbbox = aBoard->ComputeBoundingBox( false ); + // Gives a non null size to avoid issues in zoom / scale calculations + if( bbbox.GetWidth() == 0 && bbbox.GetHeight() == 0 ) + bbbox.Inflate( Millimeter2iu( 10 ) ); m_BoardSettings = &aBoard->GetDesignSettings(); diff --git a/utils/idftools/vrml_layer.cpp b/utils/idftools/vrml_layer.cpp index f8405afb10..2aa1345d13 100644 --- a/utils/idftools/vrml_layer.cpp +++ b/utils/idftools/vrml_layer.cpp @@ -1436,7 +1436,8 @@ void VRML_LAYER::glEnd( void ) double firstX = 0.0; double firstY = 0.0; - double lastX, lastY; + double lastX = 0.0; + double lastY = 0.0; double curX, curY; double area = 0.0;