Results 1 to 6 of 6

Thread: Rotating objects [solved]

  1. #1

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Rotating objects [solved]

    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.
    Last edited by Fox; Sep 3rd, 2002 at 05:14 PM.

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555
    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.

  3. #3

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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?

  4. #4
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555
    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
    Code:
    |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.

  5. #5

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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...

  6. #6

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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.

    [edit] OK guys, thanks for help.. got it [/edit]
    Last edited by Fox; Sep 3rd, 2002 at 05:14 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width