jeffkingdev 787 Report post Posted January 29, 2012 Hello, I have a skinned + animated model. It's a character model. I'm trying to get his head to look at an object in world space. This is the problem. If I take his head local matrix and build a matrix that looks at the world space object, that doesn't work. This is because when the matrix gets combined with the parent the matrix isn't looking in the right direction. My final matrix looks like this.. Final = InvBindPose * LocalBone * CombinedParents; So, how do I get my localBone matrix to be the correct one to look at an object in world space? Do I need to invert the combinedParents matrix and then re-translate it from the combinedParents matrix? to get it in the right position after the look at is applied? Any help or ideas would be helpful Thanks 0 Share this post Link to post Share on other sites
clb 2147 Report post Posted January 29, 2012 From your equation, I assume you are using the v*M notation, and will use the same below. First, compute a standard LookAt matrix that orients the front vector in the local bone space towards the desired world space direction. For reference, see e.g. MathGeoLib [url="http://clb.demon.fi/MathGeoLib/docs/float3x4_LookAt.php"]float3x4::LookAt[/url], and its [url="http://clb.demon.fi/MathGeoLib/docs/float3x3.cpp_code.html#612"]derivation[/url]. Let's denote the lookat matrix by L. We want this matrix L to be the local->world matrix for the bone, but since the bone has parent nodes, we have a sequence local->parent->world. The problem is to compute such a local->parent matrix M for the bone, so that the local->world matrix for that bone will end up to be L. You say you know the parent->world transform (your CombinedParents matrix), so let's denote that by P. Then, we have the equation local->world == local->parent * parent->world, or in terms of matrices above L == M * P, where we solve for the desired M, M = L * P^(-1). Therefore, compute the local->world LookAt matrix L, then compute the world transform of the parent, P, inverse it, and compute L * P^(-1), and set that as the local->parent matrix M for the bone. In your terms, you will then have Final = InvBindPose * M. 1 Share this post Link to post Share on other sites
jeffkingdev 787 Report post Posted January 29, 2012 Clb, Fantastic response. I am able to build a look at matrix and place it in the right position from the inverse parent transform. So I do... newLocalBone = LookAt * InvCombinedParents; That works perfect. Now, I'm having trouble converting my world space pos into the (at) position in my LookAt matrix. Do I transform my world space point by what to get a point relative to my Bone matrix? Then I can subtract my localbone pos to get the foward vector ? Any ideas would be great. Thanks 0 Share this post Link to post Share on other sites
jeffkingdev 787 Report post Posted January 30, 2012 As a test I am setting up my Look at as... LookAt = Eye(0,0,0) , At(0,0,1) , Up(0,1,0); The head is correctly facing forward always... however as I rotate the character in the world, his head is always forward facing on the body. I am trying to get him to look down world Z instead of model/mesh space Z. So, I tried multiplying LookAt * InvWorld, but that didn't work. What should I do with my WorldMatrix to multiiply it with my new LookAt to get it in world space always? Thanks 0 Share this post Link to post Share on other sites
clb 2147 Report post Posted January 31, 2012 Your bone matrix transforms from the bone's local space to its parent space. If you combine the transforms W*B1*B2*B3*...*BN, you will get a matrix which transforms from the local space of bone BN to the world space. W is a matrix that transforms from the local space of the object to the world space. B1 is the root bone's local->parent matrix. (Depending on your setup, you may or may not have a separate matrix W, and might just treat B1 as W). To transform from world space to the bone's local space, compute the matrix M^-1, where M = W*B1*B2*B3*...*BN. That matrix will take world space points/direction vectors into the local space of bone BN. If that's still not working, try pasting some code if someone can spot something that's off. 1 Share this post Link to post Share on other sites
jeffkingdev 787 Report post Posted February 1, 2012 clb, That worked perfect. Just knowing what I am doing is correct helped a lot as I could focus on other stuff that may have been wrong. I think the biggest thing is my model is coming from max which has a different coordinate system. So, I'm basically trying to figure out how to change my look at matrix to match it's coordinate system in the bind pose so the face is facing the right direction. I think I can take it from here. I'll PM you if I have any other questions. You've been a great help! Thanks! 0 Share this post Link to post Share on other sites