Click to See Complete Forum and Search --> : Rotating objects [solved]
Fox
Sep 3rd, 2002, 03:26 AM
I have these values for a rotation:
X = 0.000
Y = 0.707
Z = -0.707
Angle = 0.157
(Angle is in rad) Now how can I rotate something with these values? Need formula or D3DX function...
Thanks in advance.
Evil_Giraffe
Sep 3rd, 2002, 04:35 AM
Need clarification:
X,Y,Z define a unit vector that the rotation is around yes?
And the rotation angle is left or right handed?
And you want the answer as a what? I would imagine a transition matrix would be the simplest. It would also make it fairly easy to introduce an offset, so the centre of rotation was definable as well.
The steps you would take are:
1) [Optional] Offset so centre of rotation is at the origin
2) Rotate around the Z axis so rotational axis is in the XZ plane (i.e. Y=0)
3) Rotate around Y so that rotational axis coincides with X axis (Z=0)
4) Rotate around X the required angle
5) Invert the rotation around Y
6) Invert the rotation around Z
7) [Optional] Translate back to original position.
Fox
Sep 3rd, 2002, 04:49 AM
I know the steps, I just need the formula. I'm not good in public mathematics so I don't know the terms. X/Y/Z/Angle is the rotation angle. Sample:
The rotation angle is 90° in X axis would be displayed like this:
X: 1.0
Y: 0.0
Z: 0.0
Angle: 0.0785
Wonder why 0.0785? Me too, it's just the way 3DS saves rotations. This has to do with Pi, so it's in radiant I think... 360° would be 0.3142, see?
So how can I rotate a point using this x/y/z/angle thingy?
Evil_Giraffe
Sep 3rd, 2002, 06:18 AM
What functions can you use? I'll assume you have the basic rotation around each axis. The thing about angles seems really odd - that's half radians. 360 degrees = 2*pi radians!?
1) [Optional] Offset so centre of rotation is at the origin
Sounds like this isn't needed, so move on.
2) Rotate around the Z axis so rotational axis is in the XZ plane (i.e. Y=0)
This step is looking at the XY plane, so ignore the Z dimension and the Angle.
We have a vector (X,Y) that needs to be rotated so that Y=0
|Y /
| /A
|/____X
The angle A is arctan(Y/X). Remember that rotations go from X to Y when rotating around the Z axis, so we need to rotate by a angle of -arctan(Y/X). Don't forget that if X is zero, you will have to just look at Y and rotate it by +/-90, rather than get lovely divide by zero errors.
3) Rotate around Y so that rotational axis coincides with X axis (Z=0)
Now we need to do the same, but in the XZ plane. Don't forget that the value of X has changed! Doing the same formula replacing Y with Z yields an angle of arctan(Z/X). But this rotation will go from Z to X, so it's already going in the correct direction. That is, rotate by arctan(Z/X). Don't use the negative, and remember to watch for divide-by-zero again.
4) Rotate around X the required angle
The only difficult bit here is figureing out how much that angle really should be - do you need to double it?
5) Invert the rotation around Y
Did I mention to remember what the values you rotated around were? Stick a minus on the front of it and rotate around the same angle.
6) Invert the rotation around Z
Like 5.
Hope this is of some use.
Fox
Sep 3rd, 2002, 03:21 PM
Um, thanks, sounds great. Althought I don't really understand any word -.- I'll try to figure it out for the moment.. I'm programming in D3D as mentioned before, so I can use the D3DX rotation functions but I'm not sure if they'll work on this...
Fox
Sep 3rd, 2002, 04:31 PM
Wait a second.. I found out it's indeed in radians, the angle's just added to the last frame's rotation. This may help me solving this damn thing.
OK guys, thanks for help.. got it :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.