3d rotational displacement formula?

This is a discussion on 3d rotational displacement formula? within the Game Programming forums, part of the General Programming Boards category; I only recently started programing and after reading a little about vertices and polygons I was trying to figure out ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    26

    3d rotational displacement formula?

    I only recently started programing and after reading a little about vertices and polygons I was trying to figure out how rotations of vertices are calculated. I figure that if an object is composed of polygons, and polygons are composed of vertices then an object could be described as,
    Code:
     struct strobject{
              Struct strpolygon[var1];
              // other relevant members
    }
    Struct strpolygon{
              Struct strvert[3];
    }
    struct strvert{
              Float x;
              Float y;
              Float z;
    Moving the object in 3D space would be easy, just apply an offset to all of the members of polygons; but how would you re- orient the object?

  2. #2
    Registered User
    Join Date
    Jan 2012
    Posts
    26
    X=xCos(angle)-ySin(angle)
    Y=xSin(angle)+yCos(angle)
    Z=xSin(angle)+zCos(angle)

    I think, so i'm just working with two axis to find a third axis.

  3. #3
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Time to brush up on that linear algebra (Rotation Matrix - Wikipedia)

    There's also a set of articles about rotations on this website.
    Consider this post signed

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    You will be concatenating matrices for this operation. However note that if you use the standard Rotation = Z * Y * X it will gimbal lock. You will need to look into using either quaternions or axis-angle rotation matrices to resolve the gimbal lock.

    Once you get the final rotation matrix R your final world matrix is:

    W = Root * S * R* T

    Where Root is either the parent matrix or the identity matrix, S is scale, and T is translation.

  5. #5
    Registered User
    Join Date
    Jan 2012
    Posts
    26
    Yes, I will have too look into quaternions, I read a little about it on wikipedia but I don't understand it yet. I ran into a similar problem with "dev superman mode" camera movements but I was able to solve it with the above formulas and map keys to tilt up/down pan left/right and move forward/backward on the camera/camera focus axis. I haven't ran into any issues with it yet but I do need to put a restriction on (opposite of azimuth, going brain dead) since "flying" can get confusing with out it.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Eh? Not sure I understand what you said. Gimbal lock occurs when a rotation about one axis results in an unintended rotation about another axis or quite simply one axis of rotation is mapped onto another axis of rotation.

    This is what you should be doing for translations and rotations:

    Strafe = translate along camera / object right vector
    Fly = translate along camera / object up vector
    Walk = translate along camera / object look vector

    Yaw = rotate around camera / object up vector
    Pitch = rotate around camera / object right vector
    Roll = rotate around camera / object look vector

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help on formula?
    By Radox in forum C Programming
    Replies: 3
    Last Post: 03-04-2011, 08:14 PM
  2. Anyone know how to use this formula?
    By gator6688 in forum C++ Programming
    Replies: 3
    Last Post: 11-09-2007, 09:42 PM
  3. Parsing a formula
    By ashkya in forum C Programming
    Replies: 2
    Last Post: 02-27-2006, 07:39 AM
  4. Formula for Pi
    By zowen in forum C++ Programming
    Replies: 7
    Last Post: 10-12-2003, 05:17 AM
  5. formula
    By pete in forum C++ Programming
    Replies: 7
    Last Post: 05-26-2003, 08:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21