Game Development Reference
In-Depth Information
if(m_pTarget.valid())
{
Mat4x4 mat = (*m_pTarget)->VGet()->ToWorld();
Vec4 at = m_CamOffsetVector;
Vec4 atWorld = mat.Xform(at);
Vec3 pos = mat.GetPosition() + Vec3(atWorld);
mat.SetPosition(pos);
VSetTransform(&mat);
}
return S_OK;
}
The simple example above also implements a bare-bones third-person follow
camera
s position and orientation are sucked from the target scene
node and moved based on the m_CamOffsetVector . This is the classic
the camera
'
technique, which actually works fairly well considering it involves only the complex-
ity of a single vector offset. Of course, a real third-person camera would detect
environment geometry and have all kinds of interpolators to make sure the camera
movement was smooth and pleasing to the player. I
pole cam
'
ll leave that happy work as an
exercise for you, but if you are smart you ' ll reserve a few months for it! It ' s much
more complicated than you think.
Putting Lights in Your Scene
Lighting has been described previously, but not in the context of being an object that
sits in the scene graph. In the
example at the beginning of this chap-
ter, you could imagine that those men carried torches. As the boat slid by objects on
the shore, you would expect those torches to affect those objects, making them more
visible as the boat approached and fading into darkness as it continued. This task is
easily accomplished by making a light part of the scene graph, so that whenever it
moves or its parent node moves or reorients, it will affect objects in the way that
you would expect.
Since the base class, SceneNode , already defines a material color as a part of Sce-
neNodeProperties , the LightNode class only needs to define lighting specific
properties, which are stored in the LightProperties structure:
men on boats
struct LightProperties
{
float m_Attenuation[3]; /* Attenuation coefficients */
float m_Range;
float m_Falloff;
float m_Theta;
 
 
Search WWH ::




Custom Search