• Advertisement
Sign in to follow this  

Bone alignment

This topic is 4347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have an actor and a landscape (a mesh) in a directx game. I am currently working on positioning the actor on the mesh by getting the vertical position of the land mesh. I would like to rotate the foot bone so it is aligned with the face orientation of the land mesh at that specific point so it actually looks like the actor is standing on the ground. Can someone give me a hint on how to do this? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
To expand on what Maverikou said:

You want to build a rotation matrix for the ankle joint. This requires just building a frame that's in the space of the triangle. Take the triangle's normal as the up vector, the players facing direction as the forward vector and cross the up with the forward vector to get the right vector.

Then those three vectors will represent the rotation matrix for the ankle.

Share this post


Link to post
Share on other sites
Thanks both, I was afraid this would have to do with matrices, I looked at it yesterday but the concept of a matrix with respect to a bone/joint was a bit confusing. Let's look at this again, your posts will definetely help me with this.

Share this post


Link to post
Share on other sites
It shouldn't be too confusing because a bone represents a transformation, and the best way to represent a transformation is a matrix.

Just build a matrix off those 3 vectors and you should be able to simply set the ankle bone to those 3 vectors.

What part are you confused about? I can help you with the details if ya ask.

Share this post


Link to post
Share on other sites
Thanks for offering to help met with matrices but I admit I only looked half a second at it because I thought I had to use matrices for the bone rotation. So I did a quick search. I didn't had time at that moment to really get into it, But for what I read a matrix is built up something like this:

0 1 2 3
1 2 3 0
2 3 0 1
3 0 1 2

(the values I put in are just chosen for this example, maybe this is not even a valid matrix!)

Now, as I don't know anything about matrices yet, I can't see what these 4 rows and columns reflect and certainly not how they represent a bone transformation? That is why it is confusing to understand how 3 vectors (having 3 values each) can be transformed into a matrix (4x4)?

Share this post


Link to post
Share on other sites
You have two parts of your matrix: Rotation and Translation (actually there's skew and scale in there, but we will ignore them).

- The 3x3 part of the matrix represents the rotation
- The last row* represents the translation

Your 3x3 rotation matrix is constructed by a frame, or orthogonormal matrix, and it looks like this.

Right Vector[Rx,Ry,Rz]
Up Vector[Ux,Uy,Uz]
Forward Vector[Fx,Fy,Fz]

Add in the last row for your translation

[rotation matrix][0]
[rotation matrix][0]
[rotation matrix][0]
[Tx, Ty, Tz][1]

That gives you a 4x4 transformation matrix. Most importantly though, is that bones store transformations(4x4 matrices, or perhaps quaternions), so you can replace the transformation with your newly triangle aligned transform.

* The matrix may be row or column major depending on the api. I believe off the top of my head, DX, uses row major but if it doesn't you'll just have to take the transpose, or simply put, flip the vectors so they are verticle.

Share this post


Link to post
Share on other sites
Thanks! I was just reading this http://www.mindcontrol.org/~hplus/graphics/matrix-layout.html and was about to use this for the answers in this thread. You already gave them by explaining which vector represents which part in the matrix!

So I guess I indeed do need the row vector for dx. The thing that is not clear from the article and also not clear from your latest post is where do Tx, Ty and Tz come from, or is this what is returned in the matrix from the 3 input vectors and should I keep this at 0 when defining the matrix?

and another one from your first post:
Quote:

cross the up with the forward vector to get the right vector


is this the sum of both vectors values divided by 2?

Share this post


Link to post
Share on other sites
Quote:
Original post by safra
Quote:

cross the up with the forward vector to get the right vector


is this the sum of both vectors values divided by 2?

Nope. That'll be the cross product: a vector operation that, when used on 2 vectors, yields a third vector that's orthogonal on both the others. See http://en.wikipedia.org/wiki/Cross_product

About any library that implements vectors will have a function for this.

Share this post


Link to post
Share on other sites
Also, if your using DirectX they should have a cross product function. Off the top of my head D3DXVec3CrossProduct

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement