Commit 73005087 authored by unknown's avatar unknown Committed by jean-pierre charras

3d_viewer fix translation and rotation issues (patch from Mario Luzeiro)

parent 34b645da
......@@ -424,7 +424,7 @@ void EDA_3D_CANVAS::Redraw()
// Initialize Projection Matrix for Ortographic View
glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor,
-size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 100 );
-size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 10 );
}
else
{
......@@ -432,7 +432,7 @@ void EDA_3D_CANVAS::Redraw()
double ratio_HV = (double) size.x / size.y;
// Initialize Projection Matrix for Perspective View
gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 100 );
gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 10 );
}
// position viewer
......@@ -979,7 +979,7 @@ void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
if( g_Parm_3D_Visu.IsRealisticMode() )
{
SetGLEpoxyColor( 0.9 );
SetGLEpoxyColor( 1.0 );
if( g_Parm_3D_Visu.HightQualityMode() )
{
SetGLTexture( m_text_pcb, 35.0f );
......@@ -1400,7 +1400,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
m_glLists[GL_ID_BOARD] = glGenLists( 1 );
m_glLists[GL_ID_BODY] = glGenLists( 1 );
BuildBoard3DView(m_glLists[GL_ID_BOARD], m_glLists[GL_ID_BODY]);
CheckGLError( __FILE__, __LINE__ );
}
if( ! m_glLists[GL_ID_TECH_LAYERS] )
......@@ -1409,6 +1409,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
glNewList( m_glLists[GL_ID_TECH_LAYERS], GL_COMPILE );
BuildTechLayers3DView();
glEndList();
CheckGLError( __FILE__, __LINE__ );
}
if( ! m_glLists[GL_ID_AUX_LAYERS] )
......@@ -1417,9 +1418,9 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
glNewList( m_glLists[GL_ID_AUX_LAYERS], GL_COMPILE );
BuildBoard3DAuxLayers();
glEndList();
CheckGLError( __FILE__, __LINE__ );
}
// draw modules 3D shapes
if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] && g_Parm_3D_Visu.GetFlag( FL_MODULE ) )
{
......@@ -1434,14 +1435,16 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
BuildFootprintShape3DList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT],
m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT], false );
CheckGLError( __FILE__, __LINE__ );
m_glLists[GL_ID_SHADOW_FRONT] = glGenLists( 1 );
m_glLists[GL_ID_SHADOW_BACK] = glGenLists( 1 );
m_glLists[GL_ID_SHADOW_BOARD] = glGenLists( 1 );
BuildShadowList(m_glLists[GL_ID_SHADOW_FRONT], m_glLists[GL_ID_SHADOW_BACK], m_glLists[GL_ID_SHADOW_BOARD]);
}
// Test for errors
CheckGLError( __FILE__, __LINE__ );
CheckGLError( __FILE__, __LINE__ );
}
#ifdef PRINT_CALCULATION_TIME
unsigned endtime = GetRunningMicroSecs();
......
......@@ -51,12 +51,12 @@ static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data );
// 2 helper functions to set the current normal vector for gle items
static inline void SetNormalZpos()
{
glNormal3f( 0.0, 0.0, 1.0 );
//glNormal3f( 0.0, 0.0, 1.0 );
}
static inline void SetNormalZneg()
{
glNormal3f( 0.0, 0.0, -1.0 );
//glNormal3f( 0.0, 0.0, -1.0 );
}
void TransfertToGLlist( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits );
......@@ -185,6 +185,10 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
startContour = 0;
}
// https://www.opengl.org/sdk/docs/man2/xhtml/gluTessNormal.xml
gluTessNormal( tess, 0.0, 0.0, 0.0 );
v_data[0] = polylist.GetX( ii ) * aBiuTo3DUnits;
v_data[1] = -polylist.GetY( ii ) * aBiuTo3DUnits;
// gluTessVertex store pointers on data, not data, so do not store
......@@ -193,6 +197,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
// before calling gluDeleteTess
gluTessVertex( tess, v_data, &polylist[ii] );
if( polylist.IsEndContour( ii ) )
{
gluTessEndContour( tess );
......@@ -215,7 +220,9 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
gluDeleteTess( tess );
if( aThickness == 0 )
{
return;
}
// Build the 3D data : vertical side
Draw3D_VerticalPolygonalCylinder( polylist, aThickness, aZpos - (aThickness / 2.0), false, aBiuTo3DUnits );
......
......@@ -54,10 +54,10 @@ S3D_MATERIAL::S3D_MATERIAL( S3D_MASTER* father, const wxString& name ) :
void SetOpenGlDefaultMaterial()
{
glm::vec4 ambient( 0.2, 0.2, 0.2, 1.0 );
glm::vec4 ambient( 0.15, 0.15, 0.15, 1.0 );
glm::vec4 specular( 0.1, 0.1, 0.1, 1.0 );
glm::vec4 emissive( 0.1, 0.1, 0.1, 1.0 );
GLint shininess_value = 100;
GLint shininess_value = 80;
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
//glColor4f( 1.0, 1.0, 1.0, 1.0 );
......
......@@ -57,6 +57,8 @@ S3D_MESH::~S3D_MESH()
void S3D_MESH::openGL_RenderAllChilds()
{
//DBG( printf( "openGL_RenderAllChilds") );
glPushMatrix();
glTranslatef( m_translation.x, m_translation.y, m_translation.z );
glRotatef( m_rotation[3], m_rotation[0], m_rotation[1], m_rotation[2] );
......@@ -76,12 +78,13 @@ void S3D_MESH::openGL_RenderAllChilds()
SetOpenGlDefaultMaterial();
glPopMatrix();
}
void S3D_MESH::openGL_Render()
{
//DBG( printf( " render\n" ) );
//DBG( printf( "openGL_Render" ) );
if( m_Materials )
{
......@@ -90,6 +93,7 @@ void S3D_MESH::openGL_Render()
if( m_CoordIndex.size() == 0)
{
return;
}
......@@ -134,7 +138,7 @@ void S3D_MESH::openGL_Render()
{
for(unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ )
{
glm::vec3 normal = m_PerVertexNormalsNormalized[m_CoordIndex[idx][ii]];
glm::vec3 normal = m_PerVertexNormalsNormalized[m_NormalIndex[idx][ii]];
glNormal3fv( &normal.x );
glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
......@@ -176,6 +180,8 @@ void S3D_MESH::openGL_Render()
void S3D_MESH::calcPointNormalized ()
{
//DBG( printf( "calcPointNormalized\n" ) );
if( isPointNormalizedComputed == true )
{
return;
......@@ -221,8 +227,11 @@ bool IsClockwise(glm::vec3 v0, glm::vec3 v1, glm::vec3 v2)
void S3D_MESH::calcPerFaceNormals ()
{
//DBG( printf( "calcPerFaceNormals" ) );
if( isPerFaceNormalsComputed == true )
{
return;
}
isPerFaceNormalsComputed = true;
......@@ -230,6 +239,7 @@ void S3D_MESH::calcPerFaceNormals ()
if( m_PerVertexNormalsNormalized.size() > 0 )
{
return;
}
......@@ -317,12 +327,15 @@ void S3D_MESH::calcPerFaceNormals ()
}
}
}
// http://www.bytehazard.com/code/vertnorm.html
// http://www.emeyex.com/site/tuts/VertexNormals.pdf
void S3D_MESH::calcPerPointNormals ()
{
//DBG( printf( "calcPerPointNormals" ) );
if( isPerPointNormalsComputed == true )
{
return;
......
......@@ -66,6 +66,7 @@ public:
// Point and index list
std::vector< glm::vec3 > m_Point;
std::vector< std::vector<int> > m_CoordIndex;
std::vector< std::vector<int> > m_NormalIndex;
std::vector< glm::vec3 > m_PerFaceNormalsNormalized;
std::vector< glm::vec3 > m_PerVertexNormalsNormalized;
......
......@@ -167,6 +167,7 @@ private:
int read_IndexedFaceSet();
int read_Coordinate();
int read_Normal();
int read_NormalIndex();
int read_Color();
int read_coordIndex();
int read_colorIndex();
......
......@@ -68,6 +68,9 @@ void VRML1_MODEL_PARSER::Load( const wxString aFilename )
glShadeModel( GL_SMOOTH );
glEnable( GL_NORMALIZE );
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
glm::vec3 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y, GetMaster()->m_MatScale.z );
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y, GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y, GetMaster()->m_MatPosition.z );
......@@ -78,14 +81,11 @@ void VRML1_MODEL_PARSER::Load( const wxString aFilename )
//glPushMatrix();
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV );
glRotatef( matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef( matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef( matRot.x, 1.0f, 0.0f, 0.0f );
glRotatef(-matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef(-matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef(-matRot.x, 1.0f, 0.0f, 0.0f );
glScalef( matScale.x, matScale.y, matScale.z );
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
// Switch the locale to standard C (needed to print floating point numbers like 1.3)
SetLocaleTo_C_standard();
......
......@@ -70,6 +70,9 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
glm::vec3 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y, GetMaster()->m_MatScale.z );
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y, GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y, GetMaster()->m_MatPosition.z );
......@@ -80,14 +83,11 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
//glPushMatrix();
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV );
glRotatef( matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef( matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef( matRot.x, 1.0f, 0.0f, 0.0f );
glRotatef(-matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef(-matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef(-matRot.x, 1.0f, 0.0f, 0.0f );
glScalef( matScale.x, matScale.y, matScale.z );
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
// Switch the locale to standard C (needed to print floating point numbers like 1.3)
SetLocaleTo_C_standard();
......@@ -546,12 +546,10 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
read_Coordinate();
} else if( strcmp( text, "Normal" ) == 0 )
{
//read_Normal();
read_NotImplemented( m_file, '}' );
read_Normal();
} else if( strcmp( text, "normalIndex" ) == 0 )
{
//DBG( printf( " normalIndex NotImplemented\n" ) );
read_NotImplemented( m_file, ']' );
read_NormalIndex();
} else if( strcmp( text, "Color" ) == 0 )
{
read_Color();
......@@ -606,6 +604,38 @@ int VRML2_MODEL_PARSER::read_colorIndex()
}
int VRML2_MODEL_PARSER::read_NormalIndex()
{
//DBG( printf( " read_NormalIndex\n" ) );
m_model->m_NormalIndex.clear();
glm::ivec3 coord;
int dummy; // should be -1
std::vector<int> coord_list;
coord_list.clear();
while( fscanf (m_file, "%d, ", &dummy ) == 1 )
{
if( dummy == -1 )
{
m_model->m_NormalIndex.push_back( coord_list );
//DBG( printf( " size: %lu ", coord_list.size()) );
coord_list.clear();
} else
{
coord_list.push_back( dummy );
//DBG( printf( "%d ", dummy) );
}
}
//DBG( printf( " m_NormalIndex.size: %ld\n", m_model->m_NormalIndex.size() ) );
return 0;
}
int VRML2_MODEL_PARSER::read_coordIndex()
{
//DBG( printf( " read_coordIndex\n" ) );
......
......@@ -64,7 +64,7 @@ void VRML_MODEL_PARSER::Load( const wxString aFilename )
char line[12];
FILE* file;
// DBG( printf( "Load %s\n", static_cast<const char*>(aFilename.mb_str()) ) );
//DBG( printf( "Load %s", static_cast<const char*>(aFilename.mb_str()) ) );
file = wxFopen( aFilename, wxT( "rt" ) );
......@@ -86,7 +86,7 @@ void VRML_MODEL_PARSER::Load( const wxString aFilename )
{
//DBG( printf( "About to parser a #VRML V2.0 file\n" ) );
vrml2_parser->Load( aFilename );
return;
}
else if( stricmp( line, "#VRML V1.0" ) == 0)
......
......@@ -69,18 +69,23 @@ void X3D_MODEL_PARSER::Load( const wxString aFilename )
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
glm::vec3 matScale(GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y, GetMaster()->m_MatScale.z );
glm::vec3 matRot(GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y, GetMaster()->m_MatRotation.z );
glm::vec3 matPos(GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y, GetMaster()->m_MatPosition.z );
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
glm::vec3 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y, GetMaster()->m_MatScale.z );
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y, GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y, GetMaster()->m_MatPosition.z );
//glPushMatrix();
glTranslatef( matPos.x, matPos.y, matPos.z);
#define SCALE_3D_CONV ((IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB)
glRotatef( matRot.z, 0.0f, 0.0f, 1.0f);
glRotatef( matRot.y, 0.0f, 1.0f, 0.0f);
glRotatef( matRot.x, 1.0f, 0.0f, 0.0f);
//glPushMatrix();
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV );
glRotatef(-matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef(-matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef(-matRot.x, 1.0f, 0.0f, 0.0f );
glScalef( matScale.x, matScale.y, matScale.z );
// Switch the locale to standard C (needed to print floating point numbers)
......@@ -502,9 +507,6 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
//triplets.push_back(point);
double vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
point *= vrmlunits_to_3Dunits;
m_model->m_Point.push_back( point );
// VRML
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment