Game Development Reference
In-Depth Information
private boolean m_Visible = true;
In the Object3d class's constructor, we have to create a new Physics object.
m_Physics = new Physics(iContext);
We then have to add functions that set and test the visibility. The SetVisibility() function sets if
the object is visible or not.
void SetVisibility(boolean value) { m_Visible = value; }
The IsVisible() function returns true if the object is visible false otherwise.
boolean IsVisible() { return m_Visible; }
We also have to add in the GetObjectPhysics() function that allows access to the m_Physics object
from outside the class.
Physics GetObjectPhysics() { return m_Physics; }
The UpdateObjectPhysics() function calls the UpdatePhysicsObject() function with the orientation of
the object to do the actual physics update.
The UpdateObject3d() is the main entry point for updating the physics of our object. If the object is
visible, the physics of that object are updated. (See Listing 5-12.)
Listing 5-12. The Physics Update Entry Point in the Object3d Class
void UpdateObjectPhysics()
{
m_Physics.UpdatePhysicsObject(m_Orientation);
}
void UpdateObject3d()
{
if (m_Visible)
{
UpdateObjectPhysics();
}
}
Finally, the DrawObject() function draws the object if the object is visible. The additions to this
function from previous examples are shown in bold in Listing 5-13.
Listing 5-13. Drawing an Object If It's Visible
void DrawObject(Camera Cam, PointLight light)
{
if (m_Visible)
{
DrawObject(Cam,
light,
 
Search WWH ::




Custom Search