ezEngine  Milestone 9
ezTransformTemplate< Type > Class Template Reference

A class that represents position, rotation and scaling via a position vector, a quaternion and a scale vector. More...

#include <Transform.h>

Public Member Functions

 EZ_DECLARE_POD_TYPE ()
 
 ezTransformTemplate ()
 Default constructor: Does not do any initialization.
 
 ezTransformTemplate (const ezVec3Template< Type > &vPosition, const ezQuatTemplate< Type > &qRotation=ezQuatTemplate< Type >::IdentityQuaternion(), const ezVec3Template< Type > &vScale=ezVec3(1.0f))
 Sets position and rotation.
 
void SetFromMat4 (const ezMat4 &mat)
 Attempts to extract position, scale and rotation from the matrix. Negative scaling and shearing will get lost in the process.
 
void SetIdentity ()
 Sets the position to be zero and the rotation to identity.
 
bool IsIdentical (const ezTransformTemplate &rhs) const
 Equality Check (bitwise)
 
bool IsEqual (const ezTransformTemplate &rhs, Type fEpsilon) const
 Equality Check with epsilon.
 
void Invert ()
 Inverts this transform.
 
const ezTransformTemplate GetInverse () const
 Returns the inverse of this transform.
 
ezVec3 TransformPosition (const ezVec3 &v) const
 
ezVec3 TransformDirection (const ezVec3 &v) const
 
void operator+= (const ezVec3 &v)
 
void operator-= (const ezVec3 &v)
 
void SetLocalTransform (const ezTransformTemplate &GlobalTransformParent, const ezTransformTemplate &GlobalTransformChild)
 Sets this transform to be the local transformation needed to get from the parent's transform to the child's.
 
void SetGlobalTransform (const ezTransformTemplate &GlobalTransformParent, const ezTransformTemplate &LocalTransformChild)
 Sets this transform to the global transform, that is reached by applying the child's local transform to the parent's global one.
 
const ezMat4Template< Type > GetAsMat4 () const
 Returns the transformation as a matrix.
 

Static Public Member Functions

static const ezTransformTemplate< Type > IdentityTransform ()
 Returns an Identity Transform.
 

Public Attributes

ezVec3Template< Type > m_vPosition
 
ezQuat m_qRotation
 
ezVec3Template< Type > m_vScale
 

Detailed Description

template<typename Type>
class ezTransformTemplate< Type >

A class that represents position, rotation and scaling via a position vector, a quaternion and a scale vector.

Todo:
Fix docs and unit tests

Scale is applied first, then rotation and finally translation is added. Thus scale and rotation are always in 'local space', i.e. applying a rotation to the ezTransformTemplate will rotate objects in place around their local center. Since the translation is added afterwards, the translation component is always the global center position, around which objects rotate.

The functions SetLocalTransform() and SetGlobalTransform() allow to create transforms that either represent the full global transformation of an object, factoring its parent's transform in, or the local transformation that will get you from the parent's global transformation to the current global transformation of a child (i.e. only the difference). This is particularly useful when editing entities in a hierarchical structure.

This representation cannot handle shearing, which means rotations and scalings cannot be combined correctly. Many parts of game engine cannot handle shearing or non-uniform scaling across hierarchies anyway. Therefore this class implements a simplified way of combining scalings when multiplying two ezTransform's. Instead of rotating scale into the proper space, the two values are simply multiplied component-wise.

In situations where this is insufficient, use a 3x3 or 4x4 matrix instead. Sometimes it is sufficient to use the matrix for the computation and the result can be stored in a transform again.


The documentation for this class was generated from the following files: