Graphics Reference
In-Depth Information
inline void Node :: SetGlobalTranslation ( float x , float y , float z )
{
localTranslation =
Vector3 ( Vector4 ( x , y , z ,1.0 f ) ￿
GetGlobalMatrixWithoutLocalMatrix () . GetInversed ());
UpdateLocalMatrix () ;
}
Listing 3.3. Node::SetGlobalTranslation .
WithoutLocalMatrix , deserves a little bit more attention and will be discussed in
the context of the SetGlobalTranslation function, whose implementation is in
Listing 3.3. This method finds the node's local-to-global transform matrix but
does not take the node's local transform into account (only its ancestors). Tak-
ing the inverse of this matrix creates a transform that goes from the global space
to the node's parent space. Now, if we had some global coordinates and multi-
plied them by this matrix, we would find out what these coordinates are in the
node parent's local space. This is exactly what we understand as setting global
translation and this function implements that.
3.3.3 Demo Application
The demo application accompanying this chapter makes extensive use of the Node
class that has just been described. The application can render up to four unit
cubes whose local components we can change (through standard input; select
each cube with keys 1 , 2 , 3 ,or 4 ). We can also change parent-child relationships.
The aforementioned four cubes can be reset to one of four initial coordinate
configurations. The first configuration ( F1 key) depicts the skew problem. When
the green object's parent is set to 0 (no parent), the skew is gone. The remaining
three configurations (keys F2 , F3 ,and F4 ) all set local components to the same
values but differ in the moment when the parent-child relationships are deter-
mined. Have a look at the code to examine those cases and see how they affect
the global transforms of the objects.
One more interesting thing in the demo isthewaythefreecameramovement
is implemented. It uses Node class and needs very few easy-to-understand code
lines to achieve the desired effect.
3.4 Conclusions
Managing transformations in hierarchy is one of the most fundamental aspects
of every 3D engine. In this chapter we have thoroughly described a TRS system
that is quite easy to both understand and implement and offers a lot of flexibility,
while at the same time minimizing drawbacks related to using nonuniform scale.
Search WWH ::




Custom Search