PDA

View Full Version : mat4 transformation chain



john_connor
10-04-2017, 05:02 AM
hi,

i'm having problem to correctly animate separate nodes of a model. the nodes are hierarchically structured, and each node has a "mat4 Transform" (relative to its parent). to animate nodes, each nodes has an additional member "mat4 Animation" (relative to the base transform "mat4 Transform").

to get the final "mat4 world_transform":
mat4 Node::WorldTransform() const
{
return
m_parent ?
inverse(inverse(Animation) * inverse(Transform) * inverse(m_parent->WorldTransform())) :
Transform * Animation;
}
that works fine, but the "assimp" library i use to load models delivers the "mat4 Animation" as absolute transform relative to the node's parent.

in other words:
--> assimp gives me [Transform * Animation] and [Transform]
--> i want [Animation] only (separated)

how do i do that ??

http://assimp.sourceforge.net/lib_html/structai_node.html
http://assimp.sourceforge.net/lib_html/structai_node_anim.html


beside that:
is it better to pre-calculate all the possible animation matrices for each "key frame tick" or just do the calculations "on-the-fly" ?

GClements
10-04-2017, 12:10 PM
to get the final "mat4 world_transform":

inverse(inverse(Animation) * inverse(Transform) * inverse(m_parent->WorldTransform())) :


Note that the above is just an inefficient way of writing

m_parent->WorldTransform() * Transform * Animation

For any matrices A, B: (AB)-1=B-1A-1.



that works fine, but the "assimp" library i use to load models delivers the "mat4 Animation" as absolute transform relative to the node's parent.

in other words:
--> assimp gives me [Transform * Animation] and [Transform]
--> i want [Animation] only (separated)

how do i do that ??

Animation = inverse(Transform) * [Transform * Animation]

Matrix multiplication is associative: A(BC)=(AB)C, the product of a matrix with its inverse is the identity matrix: AA-1=A-1A=I, and the identity matrix is both a left identity: IA=A and a right identity: AI=A. So A-1(AB)=(A-1A)B=IB=B.

john_connor
10-04-2017, 03:32 PM
thanks for your help! it seems to work now


Note that the above is just an inefficient way of writing

m_parent->WorldTransform() * Transform * Animation

For any matrices A, B: (AB)-1=B-1A-1.

:doh: seems that i need a little practice with matrices again :)



Animation = inverse(Transform) * [Transform * Animation]

Matrix multiplication is associative: A(BC)=(AB)C, the product of a matrix with its inverse is the identity matrix: AA-1=A-1A=I, and the identity matrix is both a left identity: IA=A and a right identity: AI=A. So A-1(AB)=(A-1A)B=IB=B.

i was unsure where to add the "inverse(Transform)" to remove the "Transform"-part of the mat4, at the end or at the beginning .. thanks again for pointing that out