The matrix is ​​multiplied by position, quaternion components and scale

Part of my code stores the equivalent of a 4x3 matrix, preserving the xyz position, xyz scale, and quaternion. The following is a snippet of code:

class tTransform { // data tVector4f m_Position; tQuaternion m_Rotation; tVector4f m_Scale; }; 

I want to multiply two of these objects together (as if it were a matrix to multiply), and I am wondering if there is a faster / better way to do this than convert each to a matrix, multiply this path, and then retrieve the resulting position, rotation again and scaling back?

+4
source share
2 answers

Security warning as it is from memory and not fully verified. You need to define or replace operators for tQuaternion and tVector4 s.

 class tTransform { // data tVector4f m_Position; tQuaternion m_Rotation; tVector4f m_Scale; public: // World = Parent * Local (*this == parent) tTransform operator * (const tTransform& localSpace) { tTransform worldSpace; worldSpace.m_Position = m_Position + m_Rotation * (localSpace.m_Position * m_Scale); worldSpace.m_Rotation = m_Rotation * localSpace.m_Rotation; worldSpace.m_Scale = m_Scale * (m_Rotation * localSpace.m_Scale); return worldSpace; } // Local = World / Parent (*this = World) tTransform operator / (const tTransform& parentSpace) { tTransform localSpace; tQuaternion parentSpaceConjugate = parentSpace.m_Rotation.conjugate(); localSpace.m_Position = (parentSpaceConjugate * (m_Position - parentSpace.m_Position)) / parentSpace.m_Scale; localSpace.m_Rotation = parentSpaceConjugate * m_Rotation; localSpace.m_Scale = parentSpaceConjugate * (m_Scale / parentSpace.m_Scale); return localSpace; } }; 
+3
source

I was told that this is not possible in the general case. See https://gamedev.stackexchange.com/questions/167287/combine-two-translation-rotation-scale-triplets-without-matrices

The problem is that the structure cannot represent the shift that may be required after combining the rotations and uneven scaling.

Please correct me if I am wrong.

-1
source

Source: https://habr.com/ru/post/1387429/


All Articles