SED
10-28-2000, 06:08 PM
Ive put together a simple *.stl viewer. Im loading a std::vector in
the format:
stlVertices[0] == normal
stlVertices[1] == vertex1
stlVertices[2] == vertex2
stlVertices[3] == vertex3
stlVertices[4] == normal
stlVertices[5] == vertex1
stlVertices[6] == vertex2
stlVertices[7] == vertex3
...
...
...
then I loop thru rendering each:
glBegin(GL_TRIANGLES);
for (int i=0; i<stlVertices.size(); i+=4)
{
glNormal3f( stlVertices[i]->m_pt[X] ,
stlVertices[i]->m_pt[Y],
stlVertices[i]->m_pt[Z]);
glVertex3f( stlVertices[i+1]->m_pt[X] ,
stlVertices[i+1]->m_pt[Y],
stlVertices[i+1]->m_pt[Z]);
glVertex3f( stlVertices[i+2]->m_pt[X] ,
stlVertices[i+2]->m_pt[Y],
stlVertices[i+2]->m_pt[Z]);
glVertex3f( stlVertices[i+3]->m_pt[X] ,
stlVertices[i+3]->m_pt[Y],
stlVertices[i+3]->m_pt[Z]);
}
glEnd();
This will give you an idea of what Im looking at: http://personal.lig.bellsouth.net/lig/s/_/s_dolan/stl_capture.jpg
Do I have to use a normal on a per vertex basis to get a smoother
model, instead of a per triangle basis? I sort of understand how to do
this. You average the normals of the surrounding faces per vertex,
correct?
I think the stl formats triangle winding is reverse of what OpenGL
uses by default. If I reverse the winding as I load the vector and
remove the normal,is there a way OpenGL will smooth the normals for
me?
Sean
the format:
stlVertices[0] == normal
stlVertices[1] == vertex1
stlVertices[2] == vertex2
stlVertices[3] == vertex3
stlVertices[4] == normal
stlVertices[5] == vertex1
stlVertices[6] == vertex2
stlVertices[7] == vertex3
...
...
...
then I loop thru rendering each:
glBegin(GL_TRIANGLES);
for (int i=0; i<stlVertices.size(); i+=4)
{
glNormal3f( stlVertices[i]->m_pt[X] ,
stlVertices[i]->m_pt[Y],
stlVertices[i]->m_pt[Z]);
glVertex3f( stlVertices[i+1]->m_pt[X] ,
stlVertices[i+1]->m_pt[Y],
stlVertices[i+1]->m_pt[Z]);
glVertex3f( stlVertices[i+2]->m_pt[X] ,
stlVertices[i+2]->m_pt[Y],
stlVertices[i+2]->m_pt[Z]);
glVertex3f( stlVertices[i+3]->m_pt[X] ,
stlVertices[i+3]->m_pt[Y],
stlVertices[i+3]->m_pt[Z]);
}
glEnd();
This will give you an idea of what Im looking at: http://personal.lig.bellsouth.net/lig/s/_/s_dolan/stl_capture.jpg
Do I have to use a normal on a per vertex basis to get a smoother
model, instead of a per triangle basis? I sort of understand how to do
this. You average the normals of the surrounding faces per vertex,
correct?
I think the stl formats triangle winding is reverse of what OpenGL
uses by default. If I reverse the winding as I load the vector and
remove the normal,is there a way OpenGL will smooth the normals for
me?
Sean