Game Development Reference
In-Depth Information
The constructor for the Object3d class must also be modified to account for the addition of the new
Mesh variable. See changes in bold in Listing 7-3.
Listing 7-3. Object3d Constructor
Object3d(Context iContext
, Mesh iMesh
, MeshEx iMeshEx, Texture[] iTextures, Material iMaterial,
Shader iShader)
{
m_Context = iContext;
m_Mesh = iMesh;
// REst of Code
}
The
GetRadius()
function is modified to return the radius of the object's
m_Mesh
variable, if it exists.
(See Listing 7-4.) The object's mesh can now be held in either a Mesh or a MeshEx.
Listing 7-4.
GetRadius()
Function Modifications
float GetRadius()
{
if (m_Mesh != null)
{
return m_Mesh.GetRadius();
}
if (m_MeshEx != null)
{
return m_MeshEx.GetRadius();
}
return -1;
}
The
DrawObject()
function, which draws the actual object's mesh, is modified to test to see if the
m_Mesh
variable contains a valid object. If it does, the Mesh's
DrawMesh()
function is called to do the
actual rendering of the object. (See Listing 7-5.)
Listing 7-5. Modifying the
DrawObject()
Function
void DrawObject(Camera Cam,PointLight light,Vector3 iPosition,Vector3 iRotationAxis,Vector3 iScale)
{
// Activate and set up the Shader and Draw Object's mesh
// Generate Needed Matrices for Object
GenerateMatrices(Cam, iPosition,iRotationAxis,iScale);
// Add program to OpenGL environment
m_Shader.ActivateShader();
// Get Vertex Attribute Info in preparation for drawing the mesh
GetVertexAttribInfo();