# Transformations

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

## Recommended Posts

Hey. il try to explain my question as wel as i can but please bear with me my terminology might not be that great. lets say i have two points in 3D space. point A(0,0,0) and point B(10,10,10). Point B is thus 17.32 units away from point A (pythagoras). i can get from point A to point B if i translate by (10,10,10). But i need to get to point B by first aplying a rotation and then with translating by (0,0,17.32) instead (17.32 on the Z axis). How would i acuretley calculate the required rotation? Hope that makes sense. Thnx in Advance!

##### Share on other sites
Any rotation that rotates the z axis to lie along the vector between b and a is sufficient.
If you just want some arbitrary one, you can get it by setting the 3rd row of the matrix equal to r=normalize(b-a), then, let y=1,0,0. Then, let s=normalize(cross(r,y))
and t = cross(r,s)

then, set your matrix up so that the first row is s, the second row is t, and the third row is r

done.

##### Share on other sites
Quote:
 Oritignal post by EternityZAlets say i have two points in 3D space. point A(0,0,0) and point B(10,10,10). Point B is thus 17.32 units away from point A (pythagoras). i can get from point A to point B if i translate by (10,10,10). But i need to get to point B by first aplying a rotation and then with translating by (0,0,17.32) instead (17.32 on the Z axis). How would i acuretley calculate the required rotation?
Well, IMHO there is no solution possible with the given constraints at all.

The OP requests a transformation (here written using column vectors)
P' := T * R * P
where a point P is rotated by R, and the rotated point is then translated by T, so that a given P' is the end-result.

Hence the rotation can be expressed as
R * P = T-1 * P' = P' - t
where t denotes the direction vector that is equivalent to T.

Until here we have a formula that hints at how to solve the problem in general. See the comment at the bottom of this post. But especially in the OP's example the following parts are constraint:
P == ( 0, 0, 0 )t // i.e. point A in the OP
P' == ( 10, 10, 10 )t // i.e. point B in the OP
t == ( 0, 0, 17.32 )t // i.e. the requested translation in the OP
where the superscripted t means the transpose operator.

That means to solve
R * ( 0, 0, 0 )t = ( 10, 10, -7.32 )t
for R (going to affine co-ordinates here for simplicity).

Now, on the left we have a rotation matrix, and such a matrix is ever a ortho-normal basis. Applying such a rotation to 0 means that the result will ever be 0! BTW: That is the reason why 0 is called the center of rotation, and why every rotation axis (or plane, to be correct) passes throught 0.

Hence the problem is independend on R, and we got
( 0, 0, 0 )t = ( 10, 10, -7.32 )t
what obviously is not correct! In fact, a rotation can map a point to another point if and only if both points have the same distance from 0.

Maybe that the given numbers are just a miserable example. However, one general solution to the above problem is to use the cross-product and dot-product to compute a axis/angle rotation representation, and to convert that into a matrix or whatever representationis needed.

##### Share on other sites
Simply put, no matter how you try to rotate (0,0,0), you always end up with (0,0,0). So there isn't any way to just rotate and get (10,10,-7.32), which will give you (10,10,10) once you add (0,0,17.32).

Without much context, it doesn't really make sense what you're trying to do... perhaps you could give us some more details?

##### Share on other sites
ok

I posted my actual problem here about 2 days ago (Subject: malformed keyframes) it should stil be on the front page. This is just me trying to solve it. Here goes:

i think i found the reason for my keyframes being all messed up. when i export my models from blender i only save a (x,y,z) translation to represent the transformation from parent bone to child bone. I think (with my limited understanding of math) that the reason my keyframes are malformed is because the bones in my model dont have any rotation in their rest position. So i thought that i could maybe fix it if i convert my (x,y,z) translation to a rotation and a (0,0,z) translation or more simply put a direction and a distance. as Steve123 said i want the rotation to make the z-axis lie along the vector between B and A. Am i going about this the right way?

[Edited by - EternityZA on May 4, 2010 4:11:49 AM]

##### Share on other sites
Here is an example of using cross products to align a matrix axis to some vector:

http://www.gamedev.net/community/forums/topic.asp?topic_id=544271&whichpage=1�

Alternatively you can use Steve132's suggestion and use a cross product but it will not give you as much control over the resultant orientation. In other words, the your z axis will align but most likely the orientation will be tilted slightly, or rolled. You need to specify another axis of reference such as the up vector to keep it level. This is most easily achieved by using the method in the above link.

But to use a cross product it would work like this:

Vec3 axis = Cross( Vec3::ZAxis, targetZAxis ).Normalize( );
float angle = acos( Dot( Vec3::ZAxis, targetZAxis ) );

AxisAngle aa( axis, angle );
Quaternion q( aa );
Matrix m( q );

These are two viable methods for doing what you are asking to do. How ever what you're asking to do may not be what you need to do. Though is a good skill.

Animation is difficult, it has lots of bits and pieces and coordinate space and relative transforms and forward and inverse transforms. You really need to keep your head straight and understand exactly what is going on at all times/stages of the transformation process.

##### Share on other sites
yip i was the OP in that thread as wel :P i did use that method allready (to have my arrows and other projectiles point in the right direction) but in that post you said

"Which unfortunately is a completely arbitrary process. It's just like using LookAt when creating a view matrix. Lots of people just use the world Up vector which will work but can lead itself to artifacts in some cases, such as if the view direction and up direction align."

so i thought it might not be completely suitable but il try it now. Thnx!

just one more question. How should i define the transformation from a parent bone to a child bone? Am i correct in asuming it should be a oriantation and a distance like i explained in my previous post?

##### Share on other sites
It would just be a matrix.

myBone.ParentRelative = myBone.Parent.BinePoseObjectSpace.Inverse( ) * myBone.BinePoseObjectSpace;

Then you can obtain the new bone position using that and a delta

myBone.OutputObjectSpace = myBone.Parent.OutputObjectSpace * myBone.ParentRelative * myBone.AnimationDeltaFromBindPose;

The orientation of the bones is irrelevant. The above computation will work for bones in any orientation. The only time you'd need to orient the bones is if you needed to decompose the orientation into euler angles or some other constraint.

##### Share on other sites
k Thnx. That makes a little sense to me :P i think i know where to start with this (with the first step probely being to just export the bones matrix straight from blender instead of trying to export rotations and translations seperatley)

##### Share on other sites
I (and i think most people) use a generic transform serialize function. Which would read and write the matrix to the model/animation file. Internally this usually breaks the transform down into affine components. I usually do it for readability but it saves a little space too.

It really doesnt matter how you store the transform, just as long as it's 100% reliable in replicating the transform when it gets into the game.

It's also very important that you're able to draw the bones in your game. Draw 3 lines for each bone, representing its XYZ basis vectors. This is the only way you can be sure that things are exactly as you expect.

1. 1
Rutin
30
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632961
• Total Posts
3009494
• ### Who's Online (See full list)

There are no registered users currently online

×