Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

3D Rotation

ShkaboinkaShkaboinka Member Posts: 79
How do you keep track of how something is rotated? I know hod to do rotation along 6 basic axis, but what I want to do is have a constant (static, doesnt change) position and re-calculate the angle every at re-draw. This keeps a figure from getting warped, AND makes it so you can rotate on a plane that has been rotated.

I noticed that the TI89 uses something called "eyes" to keep track of where the camera is around the figure and at what angle.

Can anybody tell me how to do this or any other strategy that will work? otherwise I will have to keep a list of every preiouvs rotation, which will slow things down more and more as it goes along

Comments

  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    : How do you keep track of how something is rotated? I know hod to do rotation along 6 basic axis, but what I want to do is have a constant (static, doesnt change) position and re-calculate the angle every at re-draw. This keeps a figure from getting warped, AND makes it so you can rotate on a plane that has been rotated.
    :
    : I noticed that the TI89 uses something called "eyes" to keep track of where the camera is around the figure and at what angle.
    :
    : Can anybody tell me how to do this or any other strategy that will work? otherwise I will have to keep a list of every preiouvs rotation, which will slow things down more and more as it goes along
    :
    Don't know what to tell you on the 89. I use GL and each object structure has three axis vars for storing the rotation values. Dunno' what your extra three axis are, unless you mean time, space, and something. Maybe you could explain what the fourth, fifth, and sixth dimensions are so we can better understand and help you?

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • chick80chick80 Member Posts: 349
    : Don't know what to tell you on the 89. I use GL and each object structure has three axis vars for storing the rotation values. Dunno' what your extra three axis are, unless you mean time, space, and something. Maybe you could explain what the fourth, fifth, and sixth dimensions are so we can better understand and help you?
    :
    I use the same method in DirectX: I have an object class and a Rotation 3D vector inside it, whose component are the current object angle.

    You can easily calculate the rotation matrix having the three angles simply multiplying the rotation matrices on each of the 3 axis.

    nICO

    [hr]
    [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


  • ShkaboinkaShkaboinka Member Posts: 79
    : Don't know what to tell you on the 89. I use GL and each object structure has three axis vars for storing the rotation values. Dunno' what your extra three axis are, unless you mean time, space, and something. Maybe you could explain what the fourth, fifth, and sixth dimensions are so we can better understand and help you?
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :

    Well on the TI83+, you have tto save mem / speed; it takes more to store +angle and -angle sin&cos values, so I just use a +angle; to rotate backwards though, you just switch the axis. Thus, I tell it to rotate along XY, XZ, YZ, YX, ZX, or ZY axis.

    What do you mean by storing angle values? I think I know, but then you must know which comes first. EX: rotating 5* on XY and then 5* on ZX is NOT the same as doing ZX and then XY rotation, so how does it compensate? Is one referenced from the other like one of those multi-axis spinny things that you get in the middle of and it spins on many axis at once?
  • ShkaboinkaShkaboinka Member Posts: 79
    : You can easily calculate the rotation matrix having the three angles simply multiplying the rotation matrices on each of the 3 axis.
    :
    : nICO
    :
    : [hr]
    : [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
    : JOHN KEATS
    :

    Can you say that in English? how you multiply what matrix on the axis? Just so you know, I am doing this all MANUALLY (I learned how to program in Java and do window components & Graphics; I figured out all the stuff I use for 3D stuff, I just tell Java to draw the 2D version of it all)
  • chick80chick80 Member Posts: 349
    :
    : Can you say that in English?
    how you multiply what matrix on the axis? Just so you know, I am doing this all MANUALLY (I learned how to program in Java and do window components & Graphics; I figured out all the stuff I use for 3D stuff, I just tell Java to draw the 2D version of it all)
    :

    It's not difficult...
    A 3D world can be defined by 3 axis, x, y and z.
    So, the rotation of the object can easily be stored with 3 params, that you can call rotx, roty and rotz and represent the rotation around the above axis.
    You can represent every transformation in the 3D space with a matrix that you can use to multiply the coordinates of a 3D point to get its transformed.

    That means that:

    [code]
    - -
    | M11 M12 M13 |
    [x' y' z'] = [x y z] * | M21 M22 M23 |
    | M31 M32 M33 |
    - -
    [/code]

    The rotation matrices are:

    [code]
    X rotation:

    - -
    | cos(rotx) -sin(rotx) 0 |
    | sin(rotx) cos(rotx) 0 |
    | 0 0 1 |
    - -

    Y rotation:

    - -
    | 1 0 0 |
    | 0 cos(roty) -sin(roty) |
    | 0 sin(roty) cos(roty) |
    - -

    Z rotation:

    - -
    | cos(rotz) 0 sin(rotz) |
    | 0 1 0 |
    | -sin(rotz) 0 cos(rotz) |
    - -

    [/code]

    So, if your object is rotated 20 degrees on x 30 on y and 50 on z you just calculate the sin and cos of the 3 angles, substitute them in the matrices, then do Mx * My * Mz (multiply the 3 matrices) and, at last, multiply your point 3D coords by the matrix you obtained.

    And that's all...

    PS: this is the best way I can express myself in English... if you don't understand I can always explain it to you in Italian!

    nICO

    [hr]
    [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


  • ShkaboinkaShkaboinka Member Posts: 79
    : It's not difficult...
    : A 3D world can be defined by 3 axis, x, y and z.
    : So, the rotation of the object can easily be stored with 3 params, that you can call rotx, roty and rotz and represent the rotation around the above axis.
    : You can represent every transformation in the 3D space with a matrix that you can use to multiply the coordinates of a 3D point to get its transformed.
    :
    : That means that:
    :
    : [code]
    : - -
    : | M11 M12 M13 |
    : [x' y' z'] = [x y z] * | M21 M22 M23 |
    : | M31 M32 M33 |
    : - -
    : [/code]
    :
    : The rotation matrices are:
    :
    : [code]
    : X rotation:
    :
    : - -
    : | cos(rotx) -sin(rotx) 0 |
    : | sin(rotx) cos(rotx) 0 |
    : | 0 0 1 |
    : - -
    :
    : Y rotation:
    :
    : - -
    : | 1 0 0 |
    : | 0 cos(roty) -sin(roty) |
    : | 0 sin(roty) cos(roty) |
    : - -
    :
    : Z rotation:
    :
    : - -
    : | cos(rotz) 0 sin(rotz) |
    : | 0 1 0 |
    : | -sin(rotz) 0 cos(rotz) |
    : - -
    :
    : [/code]
    :
    : So, if your object is rotated 20 degrees on x 30 on y and 50 on z you just calculate the sin and cos of the 3 angles, substitute them in the matrices, then do Mx * My * Mz (multiply the 3 matrices) and, at last, multiply your point 3D coords by the matrix you obtained.
    :
    : And that's all...
    :
    : PS: this is the best way I can express myself in English... if you don't understand I can always explain it to you in Italian!
    :
    : nICO
    :
    : [hr]
    : [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
    : JOHN KEATS
    :

    I am still a little confused... is there ONE matrix that you multiply [x,y,z] by? I guess each is found by it's corresponding rotation matrix, but how? you can't multiply [x] by a 3x3 Matrix; do I find the determinant of each to find the new coordinates?
  • chick80chick80 Member Posts: 349
    No, you multiply the 1*3 vector [x y z] by the 3*3 matrix obtained combining (=multiplying) the 3*3 matrices of the rotation about the 3 axis.

    Multiplying a 1*3 vector by a 3*3 matrix yealds to a 1*3 vector
    [x' y' z'] that contains the transformed point coords.

    nICO

    [hr]
    [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


  • ShkaboinkaShkaboinka Member Posts: 79
    ..so, do I multipy [x y z] by rotx, roty, and then rotz everytime?
    how do you keep the 3 angles updated? This better not be about simple rotation, which I can do; This IS about keeping track of 3 constantly changing transformation angles and finding each orientation from a constant postition, right?

    I don't see anything in there that explains how to keep track of this stuff, just some compicated steps for ONE rotation. Can you explain, or do you really know what I'm talking about?
    (thanks for your help)
  • ShkaboinkaShkaboinka Member Posts: 79
    Let me add this:

    lets say that you have 3 numbers to keep track of x,y, and z rotation.
    They start out at zero: rotate 30 degrees around the x-axis, and the xnumber is 30, but the y and z numbers are affected; then rotate around the y-axis 45 degrees: ynumber=45, and the other angles are affected... do this many times...
    now the figure has never really moved; to get it to the postion where it should be after all that, find where the angles meet or something...but then it may be rotated incorrectly around the axis described by these combined rotations (not sure); wouldn't that work?

    How would you rotate on WHICH plane(s) to get it in that orientation? I suppose any might work, as long as you re-figure it for every point...what can you say of any of this; is that what the whole matrices thing does?
  • chick80chick80 Member Posts: 349
    Well, I can tell you how I generally handle this problem, but there can be other solutions...

    I have a class CObj that contains 3 members: Pos, Rot and Scale, that are 3D vector, so that each of this member store 3 values, 1 for each axis.

    I also have a CApp class that contains a list of CObj objects, and also other stuff (like cameras, lights, textures and so on).

    The CObj class has various methods to set the position, the rotation and the scaling of the objects... so every time I change a value I recalculate the position, rotation and scaling matrices (position and scaling can be handled easily with matrices, like I told you for rotation). Note that I recalculate the matrices only when needed.
    I also store the pos*scale*rot matrix, so I don't have to calculate it for every frame; note that the multiplication of matrices is NOT commutative (ie. A*B is different from B*A) so the order matters and it's important to multiply the matrices in the correct order or you'll have wrong results.

    You should also calculate a perspective matrix, that corrects the trasformation obtained by the above matrix, taking in account the perspective (this matrix depends by the camera parameters).

    So... it's a lot of math stuff and it's not as easy as it seems!

    If you want to do something estetically good and in real-time I suggest you to use DirectX or OpenGL (the one which you prefer, they're both good) and to switch to C++.

    nICO

    [hr]
    [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


Sign In or Register to comment.