Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: mat4 transformation chain

  1. #1
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    443

    mat4 transformation chain

    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":
    Code cpp:
    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_ht...ctai_node.html
    http://assimp.sourceforge.net/lib_ht...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" ?
    Last edited by john_connor; 10-04-2017 at 05:13 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,516
    Quote Originally Posted by john_connor View Post
    to get the final "mat4 world_transform":
    Code cpp:
    		inverse(inverse(Animation) * inverse(Transform) * inverse(m_parent->WorldTransform())) :
    Note that the above is just an inefficient way of writing
    Code cpp:
    		m_parent->WorldTransform() * Transform * Animation
    For any matrices A, B: (AB)-1=B-1A-1.

    Quote Originally Posted by john_connor View Post
    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.

  3. #3
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    443
    thanks for your help! it seems to work now

    Quote Originally Posted by GClements View Post
    Note that the above is just an inefficient way of writing
    Code cpp:
    		m_parent->WorldTransform() * Transform * Animation
    For any matrices A, B: (AB)-1=B-1A-1.
    seems that i need a little practice with matrices again


    Quote Originally Posted by GClements View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •