Code:
void MODEL_DTP::DrawModel ( void )
{
ROTATE_DTP rotate; //the current rotation that needs to be done
bool isRotate = false;
//Push the matrix for rotation purposes
glPushMatrix ( );
//Do the rotations that need to be done on the rotation stack
while ( !rotation.empty() )
{
rotate = rotation.top();
rotation.pop();
if ( rotate.entireModel ) //if the rotation is being done on the entire 3d model
{
//glTranslatef ( rotate.pivotX, rotate.pivotY, rotate.pivotZ );
glRotatef ( rotate.rotateDeg, (rotate.rotateAxis == X),
(rotate.rotateAxis == Y), (rotate.rotateAxis == Z) );
}
else if ( rotate.isRotationBlock ) //if the rotation is being done on a group of meshes
{
glPushMatrix ( );
glTranslatef ( rotate.pivotX, rotate.pivotY, rotate.pivotZ );
glRotatef ( rotate.xRot, 1.0, 0.0, 0.0 );
glRotatef ( rotate.yRot, 0.0, 1.0, 0.0 );
glRotatef ( rotate.zRot, 0.0, 0.0, 1.0 );
for ( int n = 0; n < UnitModel.GetMeshCount(); n++ )
{
if ( rotate.rotationBlockMeshID[n] )
{
glBindTexture ( GL_TEXTURE_2D, texture [MECH_METAL] );
LMesh &mesh = UnitModel.GetMesh(n);
// Texturing Contour Anchored To The Object
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
// Texturing Contour Anchored To The Object
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
glEnable(GL_TEXTURE_GEN_S); // Auto Texture Generation
glEnable(GL_TEXTURE_GEN_T); // Auto Texture Generation
glVertexPointer(4, GL_FLOAT, 0, &mesh.GetVertex(0));
glNormalPointer(GL_FLOAT, 0, &mesh.GetNormal(0));
glColorPointer(3, GL_FLOAT, 0, &mesh.GetBinormal(0));
glDrawElements(GL_TRIANGLES, mesh.GetTriangleCount()*3,
GL_UNSIGNED_SHORT, &mesh.GetTriangle(0));
//set the master list variable to true for this mesh
//so we know not to draw this mesh in the main drawing loop
rotationBlockMeshIDMasterList[n] = true;
}
}
glPopMatrix ( );
}
else //if the rotation is only being done on a single mesh
{
rotateMeshMatrix[rotate.rotateMeshID][rotate.rotateAxis] = rotate;
}
}
//Do the drawing of the model after the rotating has been done
for (uint i= 0; i<UnitModel.GetMeshCount(); i++)
{
isRotate = (!rotateMeshMatrix[i][0].entireModel) ||
(!rotateMeshMatrix[i][1].entireModel) ||
(!rotateMeshMatrix[i][2].entireModel);
//Skip the drawing of this mesh, if it was part of a rotation block
//and no more rotations need to be done to it.
if ( rotationBlockMeshIDMasterList[i] )
{
rotationBlockMeshIDMasterList[i] = false; //resets it for the next frame
continue;
}
if ( isRotate )
{
glPushMatrix ( );
if ( !rotateMeshMatrix[i][0].entireModel )
glRotatef ( rotateMeshMatrix[i][0].rotateDeg,
1.0f, 0.0f, 0.0f );
if ( !rotateMeshMatrix[i][1].entireModel )
glRotatef ( rotateMeshMatrix[i][1].rotateDeg,
0.0f, 1.0f, 0.0f );
if ( !rotateMeshMatrix[i][2].entireModel )
glRotatef ( rotateMeshMatrix[i][2].rotateDeg,
0.0f, 0.0f, 1.0f );
}
glBindTexture ( GL_TEXTURE_2D, texture [MECH_METAL] );
LMesh &mesh = UnitModel.GetMesh(i);
// Texturing Contour Anchored To The Object
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
// Texturing Contour Anchored To The Object
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
glEnable(GL_TEXTURE_GEN_S); // Auto Texture Generation
glEnable(GL_TEXTURE_GEN_T); // Auto Texture Generation
glVertexPointer(4, GL_FLOAT, 0, &mesh.GetVertex(0));
glNormalPointer(GL_FLOAT, 0, &mesh.GetNormal(0));
glColorPointer(3, GL_FLOAT, 0, &mesh.GetBinormal(0));
glDrawElements(GL_TRIANGLES, mesh.GetTriangleCount()*3,
GL_UNSIGNED_SHORT, &mesh.GetTriangle(0));
if ( isRotate )
glPopMatrix ( );
}
glDisable ( GL_TEXTURE_GEN_S );
glDisable ( GL_TEXTURE_GEN_T );
//Pop off the matrix
glPopMatrix ( );
}
If you want to see the entire .cpp file, I will attatch it. Of course it will not compile because it needs the rest of the project to be able to do that, but it might be helpful to look at.