ezEngine Release 26.3
Loading...
Searching...
No Matches
ezTransformTemplate< Type > Class Template Reference

Represents position, rotation and scaling using separate components for efficient hierarchical transformations. 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 HasOnlyUniformScaling () const
 Returns whether this transform contains only uniform scaling (including scale == 1).
 
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
 Transforms a position vector by this transform (applies scale, rotation, and translation).
 
ezVec3Template< Type > TransformDirection (const ezVec3Template< Type > &v) const
 Transforms a direction vector by this transform (applies scale and rotation, but not translation).
 
void operator+= (const ezVec3Template< Type > &v)
 Translates the transform by the given vector in global space.
 
void operator-= (const ezVec3Template< Type > &v)
 Translates the transform by the negative of the given vector in global space.
 
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 using decomposition.
 
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 >

Represents position, rotation and scaling using separate components for efficient hierarchical transformations.

Transform operations follow the order: Scale → Rotation → Translation (SRT). This ensures that scale and rotation are applied in local space, while translation occurs in global space. This makes the translation component represent the global center position around which objects rotate.

Hierarchical transformation support:

  • MakeLocalTransform(): Creates the local transformation difference between parent and child
  • MakeGlobalTransform(): Combines parent's global transform with child's local transform
  • Useful for editing entities in hierarchical structures where you need to factor in parent transforms

Limitations:

  • Cannot represent shearing transformations
  • Non-uniform scaling across hierarchies uses simplified component-wise multiplication
  • When these limitations are problematic, use ezMat3 or ezMat4T instead

Performance characteristics:

  • More memory efficient than 4x4 matrices (7 floats vs 16)
  • Faster interpolation and concatenation than matrices
  • Suitable for real-time animation and game object hierarchies

Member Function Documentation

◆ HasMirrorScaling()

template<typename Type >
EZ_ALWAYS_INLINE bool ezTransformTemplate< Type >::HasMirrorScaling ( ) const

Returns whether this transform contains negative scaling aka mirroring.

Checks if any scale component is negative, which indicates mirroring along that axis. Important for correct normal vector transformations and culling operations.

◆ HasOnlyUniformScaling()

template<typename Type >
EZ_ALWAYS_INLINE bool ezTransformTemplate< Type >::HasOnlyUniformScaling ( ) const

Returns whether this transform contains only uniform scaling (including scale == 1).

Returns true if all three scale components have the same absolute value.

◆ MakeFromMat4()

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

Creates a transform from the given matrix using decomposition.

Attempts to decompose the matrix into separate translation, rotation, and scale components. The operation always succeeds but may produce unexpected results with invalid matrices.

Note
Matrices containing shearing cannot be accurately represented as transforms. Mirroring (negative determinant) may not be preserved correctly. Zero or near-zero matrices will produce degenerate transforms.

◆ MakeGlobalTransform()

template<typename Type >
EZ_ALWAYS_INLINE ezTransformTemplate< Type > ezTransformTemplate< Type >::MakeGlobalTransform ( const ezTransformTemplate< Type > &  globalTransformParent,
const ezTransformTemplate< Type > &  localTransformChild 
)
static

Creates a transform that is the global transform, that is reached by applying the child's local transform to the parent's global one.

Computes: globalTransform = globalTransformParent * localTransformChild

◆ MakeLocalTransform()

template<typename Type >
ezTransformTemplate< Type > ezTransformTemplate< Type >::MakeLocalTransform ( const ezTransformTemplate< Type > &  globalTransformParent,
const ezTransformTemplate< Type > &  globalTransformChild 
)
static

Creates a transform that is the local transformation needed to get from the parent's transform to the child's.

Computes: localTransform = inverse(globalTransformParent) * globalTransformChild


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