![]() |
XII Release 0.1.0
|
A class that represents position, rotation and scaling via a position vector, a quaternion and a scale vector. More...
#include <Transform.h>
Public Types | |
using | ComponentType = Type |
Public Member Functions | |
XII_DECLARE_POD_TYPE () | |
xiiTransformTemplate ()=default | |
Default constructor: Does not do any initialization. | |
xiiTransformTemplate (const xiiVec3Template< Type > &vPosition, const xiiQuatTemplate< Type > &qRotation=xiiQuatTemplate< Type >::MakeIdentity(), const xiiVec3Template< Type > &vScale=xiiVec3Template< 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 | ContainsNegativeScale () 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 xiiTransformTemplate &rhs) const |
Equality Check (bitwise) | |
bool | IsEqual (const xiiTransformTemplate &rhs, Type fEpsilon) const |
Equality Check with epsilon. | |
void | Invert () |
Inverts this transform. | |
const xiiTransformTemplate | GetInverse () const |
Returns the inverse of this transform. | |
xiiVec3Template< Type > | TransformPosition (const xiiVec3Template< Type > &v) const |
xiiVec3Template< Type > | TransformDirection (const xiiVec3Template< Type > &v) const |
void | operator+= (const xiiVec3Template< Type > &v) |
void | operator-= (const xiiVec3Template< Type > &v) |
const xiiMat4Template< Type > | GetAsMat4 () const |
Returns the transformation as a matrix. | |
Static Public Member Functions | |
static xiiTransformTemplate< Type > | Make (const xiiVec3Template< Type > &vPosition, const xiiQuatTemplate< Type > &qRotation=xiiQuatTemplate< Type >::MakeIdentity(), const xiiVec3Template< Type > &vScale=xiiVec3Template< Type >(1)) |
Creates a transform from the given position, rotation and scale. | |
static xiiTransformTemplate< Type > | MakeIdentity () |
Creates an identity transform. | |
static xiiTransformTemplate< Type > | MakeFromMat4 (const xiiMat4Template< Type > &mMat) |
Creates a transform from the given matrix. | |
static xiiTransformTemplate< Type > | MakeLocalTransform (const xiiTransformTemplate &globalTransformParent, const xiiTransformTemplate &globalTransformChild) |
Creates a transform that is the local transformation needed to get from the parent's transform to the child's. | |
static xiiTransformTemplate< Type > | MakeGlobalTransform (const xiiTransformTemplate &globalTransformParent, const xiiTransformTemplate &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 | |
xiiVec3Template< Type > | m_vPosition |
xiiQuatTemplate< Type > | m_qRotation |
xiiVec3Template< Type > | m_vScale |
A class that represents position, rotation and scaling via a position vector, a quaternion and a scale vector.
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 xiiTransformTemplate 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 xiiTransform'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.
|
staticnodiscard |
Creates a transform from the given matrix.