Graphics Reference
In-Depth Information
public :
string name ;
private :
Node ￿ parent ;
vector < Node ￿ > children ;
Vector3 localTranslation ;
Quaternion localRotation ;
Vector3 localScale ;
Matrix localMatrix ;
Listing 3.1. Node class fields.
private so the class's users don't need to know what is actually stored inside the
class; the implementation is up to us. Note, however, that the interface (dis-
cussed in the next section) exhibits functionality to set/get both local and global
transforms. Choosing rotation representation in the form of a quaternion is also
our implementation choice. Nothing prevents us from using here a 3
3 rota-
tion matrix, but that would obviously be a waste of memory (four floats against
nine). We could actually save one more float by storing Euler angles instead of
a quaternion. However, quaternions are much neater to work with (in terms of
composition and interpolation). More on this can be found in a thorough case
study in [Dunn and Parberry 02].
The last field, localMatrix , is here to act as a sort of cache. It is expensive in
terms of memory to store such a big matrix, but given how often we need to find
the local matrix in code, we decided to have it here and recompute only when
needed. Obviously, if memory is more precious to us than computations, we can
remove this field and always compute the local matrix on the fly.
×
3.3.2 Class Interface
Listing 3.2 presents a list of public methods Node class exposes. Some have been
skipped (marked with [...] comment) so that we can focus on functions that are
of greatest interest to us as well as for compactness reasons.
There are two functions for altering the local translation vector. The dif-
ference is that SetLocalTranslation resets the old translation vector to com-
pletely new values while LocalTranslate just adds a new vector to the current
localTranslation . The same scheme goes for local rotation functions.
There is also a SetLocalScale function, which does exactly what we can expect
from it. However, there is no SetGlobalScale function. That is because when
using the TRS system with nonuniform scale, there is just no single global scale
value. Global scale is a combination of both local scales and local rotations
of all nodes in the hierarchy. We can, however, get the global scale (function
GetGlobalLossyScale ) just as we did in Section 3.2.4.
Search WWH ::




Custom Search