Thread: Silvercord: Rotate around an arbitrary axis

  1. #1
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    Silvercord: Rotate around an arbitrary axis

    I addressed this to SC but anybody who can help is welcome since I'm frickin' lost. What I want to do seems fairly simple but I just can't seem to get it right.

    I have a vector that I want to rotate about (0, 0, 0); kind of like a clock hand rotating. Here's what I tried:

    original vector: (0, 1, 0)
    angle to rotate 90
    rotating around z axis at (0, 0, 0)

    rotated vector.x = cos(90) * original.x + sin(90) * original.y
    rotated vector.y = cos(90) * original.y - sin(90) * original.x

    I'm sure that I'm just doing something wrong in my algorithm or missing a step somewhere.

    Thanks in advance for your help.

    Jason

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Thanks, FYB. I wasn't converting from degrees to radians. That fixed it.

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Also, your Z axis would be <0,0,1>, not (0,0,0)
    Away.

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I assumed he meant that the object was centered at 0, 0, 0. You do need a center point in addition to a vector to do an arbitrary axis rotation.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    I am centered around (0,0,0). I probably worded my original question wrong. I am doing a rotation just like a clock hand rotating around the center of the screne. It's working fine now. Thanks again.

  7. #7
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I'm confused, because an arbitrary axis rotation shouldn't refer to x or y components, in fact I was always under the impression that there is no x or y, that the x is really the component of the vector you are trying to rotate perpendicular to the axis you are rotating about, and the 'y' is really the crossproduct between the perpendicular component and the axis. I'll draw a picture:

    http://www.thedevelopersalliance.com...aarotation.JPG

    EDIT: and here's how you calculate parallel and perpendicular components.

    the parallel component of vector P onto vector A (A means Axis) is:
    (DotProduct(A, P) / ||A|| ^ 2) * A
    if they are already unit vectors (as they SHOULD be!) it boils down to:

    DotProduct(A, P) * A

    Interestingly the dotproduct between two unit vectors is the cosine of the angle between the two

    The perpendicular component is P - the parallel component

    P` = P - (DotProduct(A, P)*A)

    EDIT1: and jdinger you are completely right about being centered at the origin, that's how I always perform these rotations, in fact almost every pertinent calculation for games whether it be BSP traversal by examining plane normals or bounding box offset calculations are all done at the origin. (with plane normals you do need a real distance from the origin so that you can determine if your real position is in front or behind a plane that isn't actually at the origin, but the plane normal itself is at the origin)
    Last edited by Silvercord; 08-17-2003 at 04:43 PM.

  8. #8
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Silvercord, that's a dead link. Remember, your hosting site is cAsE sEnSiTiVe.
    Away.

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Originally posted by confuted
    Silvercord, that's a dead link. Remember, your hosting site is cAsE sEnSiTiVe.
    link works fine for me.

  10. #10
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Yeah, it's fine now. Odd...
    Away.

  11. #11
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    and wasn't google not working for you a while ago? seems like ur internet is screway confuted!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Camera rotate to function
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 11-15-2008, 12:22 PM
  2. How to rotate child objects in 3D
    By Arianiv in forum Game Programming
    Replies: 11
    Last Post: 04-03-2008, 05:09 AM
  3. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  4. AXIS and C++
    By bman1176 in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2006, 11:00 AM
  5. Camera problem: rolling
    By darksaidin in forum Game Programming
    Replies: 37
    Last Post: 08-15-2003, 08:49 AM