ezEngine  Release 25.03
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
 Default constructor: Does not do any initialization.
 
 ezTransformTemplate (const ezVec3Template< Type > &vPosition, const ezQuatTemplate< Type > &qRotation=ezQuatTemplate< Type >::MakeIdentity(), const ezVec3Template< Type > &vScale=ezVec3Template< Type >(1))
 Initializes the transform from the given position, rotation and scale.
 
void SetIdentity ()
 Sets the position to be zero and the rotation to identity.
 
Type GetMaxScale () const
 Returns the scale component with maximum magnitude.
 
bool HasMirrorScaling () const
 Returns whether this transform contains negative scaling aka mirroring.
 
bool ContainsUniformScale () const
 Returns whether this transform contains uniform scaling.
 
bool IsValid () const
 Checks that all components are valid (no NaN, only finite numbers).
 
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.
 
ezVec3Template< Type > TransformPosition (const ezVec3Template< Type > &v) const
 
ezVec3Template< Type > TransformDirection (const ezVec3Template< Type > &v) const
 
void operator+= (const ezVec3Template< Type > &v)
 
void operator-= (const ezVec3Template< Type > &v)
 
const ezMat4Template< Type > GetAsMat4 () const
 Returns the transformation as a matrix.
 

Static Public Member Functions

static ezTransformTemplate< Type > Make (const ezVec3Template< Type > &vPosition, const ezQuatTemplate< Type > &qRotation=ezQuatTemplate< Type >::MakeIdentity(), const ezVec3Template< Type > &vScale=ezVec3Template< Type >(1))
 Creates a transform from the given position, rotation and scale.
 
static ezTransformTemplate< Type > MakeIdentity ()
 Creates an identity transform.
 
static ezTransformTemplate< Type > MakeFromMat4 (const ezMat4Template< Type > &mMat)
 Creates a transform from the given matrix. More...
 
static ezTransformTemplate< Type > MakeLocalTransform (const ezTransformTemplate &globalTransformParent, const ezTransformTemplate &globalTransformChild)
 Creates a transform that is the local transformation needed to get from the parent's transform to the child's.
 
static ezTransformTemplate< Type > MakeGlobalTransform (const ezTransformTemplate &globalTransformParent, const ezTransformTemplate &localTransformChild)
 Creates a transform that is the global transform, that is reached by applying the child's local transform to the parent's global one.
 

Public Attributes

ezVec3Template< Type > m_vPosition
 
ezQuatTemplate< Type > 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.

Member Function Documentation

◆ MakeFromMat4()

template<typename Type >
ezTransformTemplate< Type > ezTransformTemplate< Type >::MakeFromMat4 ( const ezMat4Template< Type > &  mMat)
static

Creates a transform from the given matrix.

Note
This operation always succeeds, even though the matrix may be complete garbage (e.g. a zero matrix) or may not be representable as a transform (containing shearing). Also be careful with mirroring. The transform may or may not be able to represent that.

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