Manually select changes from Mario Luzeiro's branch to fix model lighting in the preview window.
This commit is contained in:
parent
bf3d2b252e
commit
86635aeb23
|
@ -24,7 +24,9 @@
|
|||
|
||||
/**
|
||||
* @file c3d_model_viewer.cpp
|
||||
* @brief Implements a model viewer canvas
|
||||
* @brief Implements a model viewer canvas. The propose of model viewer is to
|
||||
* render 3d models that come in the original data from the files without any
|
||||
* transformations.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
@ -159,17 +161,17 @@ void C3D_MODEL_VIEWER::ogl_initialize()
|
|||
// Setup light
|
||||
// https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
const GLfloat ambient[] = { 0.1f, 0.1f, 0.1f, 1.0f };
|
||||
const GLfloat ambient[] = { 0.01f, 0.01f, 0.01f, 1.0f };
|
||||
const GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
const GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
const GLfloat position[] = { 0.0f, 0.0f, 1.0f, 0.0f }; // defines a directional light that points along the negative z-axis
|
||||
const GLfloat lmodel_ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
|
||||
const GLfloat position[] = { 0.0f, 0.0f, 2.0f * RANGE_SCALE_3D, 0.0f }; // defines a directional light that points along the negative z-axis
|
||||
const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
|
||||
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
|
||||
glLightfv( GL_LIGHT0, GL_SPECULAR, specular );
|
||||
glLightfv( GL_LIGHT0, GL_POSITION, position );
|
||||
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
||||
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
|
||||
}
|
||||
|
||||
|
||||
|
@ -253,36 +255,19 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
|
|||
// Render Model
|
||||
if( m_ogl_3dmodel )
|
||||
{
|
||||
/*
|
||||
ogl_set_arrow_material();
|
||||
|
||||
glColor3f( 0.9f, 0.0f, 0.0f );
|
||||
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
||||
SFVEC3F( RANGE_SCALE_3D / 1.0f, 0.0f, 0.0f ),
|
||||
0.2f );
|
||||
|
||||
glColor3f( 0.0f, 0.9f, 0.0f );
|
||||
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
||||
SFVEC3F( 0.0f, RANGE_SCALE_3D / 1.0f, 0.0f ),
|
||||
0.2f );
|
||||
|
||||
glColor3f( 0.0f, 0.0f, 0.9f );
|
||||
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
||||
SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 1.0f ),
|
||||
0.2f );
|
||||
*/
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
double modelunit_to_3d_units_factor = m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
|
||||
|
||||
glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor, modelunit_to_3d_units_factor);
|
||||
|
||||
// Center model in the render viewport
|
||||
const SFVEC3F model_center = m_ogl_3dmodel->GetBBox().GetCenter();
|
||||
glTranslatef( -model_center.x, -model_center.y, -model_center.z );
|
||||
|
||||
// !TODO: draw transparent models
|
||||
m_ogl_3dmodel->Draw_opaque();
|
||||
//m_ogl_3dmodel->Draw_transparent();
|
||||
m_ogl_3dmodel->Draw_transparent();
|
||||
//m_ogl_3dmodel->Draw_bboxes();
|
||||
|
||||
glPopMatrix();
|
||||
|
@ -299,8 +284,8 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
|
|||
glMatrixMode( GL_MODELVIEW );
|
||||
glLoadIdentity();
|
||||
|
||||
glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f), SFVEC3F( 0.0f, 0.0f, -RANGE_SCALE_3D ) );
|
||||
glm::mat4 ViewMatrix = TranslationMatrix * m_trackBallCamera.GetRotationMatrix();
|
||||
const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f), SFVEC3F( 0.0f, 0.0f, -RANGE_SCALE_3D ) );
|
||||
const glm::mat4 ViewMatrix = TranslationMatrix * m_trackBallCamera.GetRotationMatrix();
|
||||
|
||||
glLoadMatrixf( glm::value_ptr( ViewMatrix ) );
|
||||
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
|
||||
/**
|
||||
* @file c3d_model_viewer.h
|
||||
* @brief Implements a model viewer canvas
|
||||
* @brief Implements a model viewer canvas. The propose of model viewer is to
|
||||
* render 3d models that come in the original data from the files without any
|
||||
* transformations.
|
||||
*/
|
||||
|
||||
#ifndef _C3D_MODEL_VIEWER_H_
|
||||
|
|
|
@ -116,6 +116,7 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel )
|
|||
|
||||
if( mesh.m_Color != NULL )
|
||||
{
|
||||
// This enables the use of the Color Pointer information
|
||||
glEnable( GL_COLOR_MATERIAL );
|
||||
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
|
||||
}
|
||||
|
@ -133,6 +134,8 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel )
|
|||
// /////////////////////////////////////////////////////////
|
||||
glDrawElements( GL_TRIANGLES, mesh.m_FaceIdxSize, GL_UNSIGNED_INT, mesh.m_FaceIdx );
|
||||
|
||||
glDisable( GL_COLOR_MATERIAL );
|
||||
|
||||
glEndList();
|
||||
|
||||
// Disable arrays client states
|
||||
|
@ -196,7 +199,10 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel )
|
|||
// Compile the model display list
|
||||
glNewList( m_ogl_idx_list_transparent, GL_COMPILE );
|
||||
|
||||
// Render each mesh display list (opaque first)
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
|
||||
// Render each mesh display list
|
||||
// /////////////////////////////////////////////////////////
|
||||
for( unsigned mesh_i = 0; mesh_i < a3DModel.m_MeshesSize; ++mesh_i )
|
||||
{
|
||||
|
@ -211,6 +217,8 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel )
|
|||
}
|
||||
}
|
||||
|
||||
glDisable( GL_BLEND );
|
||||
|
||||
glEndList();
|
||||
}
|
||||
else
|
||||
|
@ -279,3 +287,14 @@ void C_OGL_3DMODEL::Draw_bboxes() const
|
|||
for( unsigned int mesh_i = 0; mesh_i < m_nr_meshes; ++mesh_i )
|
||||
OGL_draw_bbox( m_meshs_bbox[mesh_i] );
|
||||
}
|
||||
|
||||
bool C_OGL_3DMODEL::Have_opaque() const
|
||||
{
|
||||
return glIsList( m_ogl_idx_list_opaque );
|
||||
}
|
||||
|
||||
|
||||
bool C_OGL_3DMODEL::Have_transparent() const
|
||||
{
|
||||
return glIsList( m_ogl_idx_list_transparent );
|
||||
}
|
||||
|
|
|
@ -66,6 +66,16 @@ public:
|
|||
*/
|
||||
void Draw_bboxes() const;
|
||||
|
||||
/**
|
||||
* @brief Have_opaque - return true if have opaque meshs to render
|
||||
*/
|
||||
bool Have_opaque() const;
|
||||
|
||||
/**
|
||||
* @brief Have_transparent - return true if have transparent meshs to render
|
||||
*/
|
||||
bool Have_transparent() const;
|
||||
|
||||
/**
|
||||
* @brief GetBBox - Get main bbox
|
||||
* @return the main model bbox
|
||||
|
|
|
@ -117,7 +117,7 @@ GLuint OGL_LoadTexture( const CIMAGE &aImage )
|
|||
void OGL_SetMaterial( const SMATERIAL & aMaterial )
|
||||
{
|
||||
const SFVEC4F ambient = SFVEC4F( aMaterial.m_Ambient, 1.0f );
|
||||
const SFVEC4F diffuse = SFVEC4F( aMaterial.m_Diffuse, 1.0f );
|
||||
const SFVEC4F diffuse = SFVEC4F( aMaterial.m_Diffuse - aMaterial.m_Transparency, 1.0f );
|
||||
const SFVEC4F specular = SFVEC4F( aMaterial.m_Specular, 1.0f );
|
||||
const SFVEC4F emissive = SFVEC4F( aMaterial.m_Emissive, 1.0f );
|
||||
|
||||
|
@ -125,5 +125,5 @@ void OGL_SetMaterial( const SMATERIAL & aMaterial )
|
|||
glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
|
||||
glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
|
||||
glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, &emissive.r );
|
||||
glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, (aMaterial.m_Shininess > 128.0f)?128.0f:aMaterial.m_Shininess );
|
||||
glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 128.0f * ((aMaterial.m_Shininess > 1.0f)?1.0f:aMaterial.m_Shininess) );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue