Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Rotations again !

  1. #1
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    Rotations again !

    Hi there.

    I am developping some kind of basic 3D modeller which imports various formats and exports to my own format for my own viewer (my format is quite OpenGL-oriented as you can imagine !).

    I wanted to implement in the modeller the kind of rotation you have in 3D Studio Max.
    Basically, the object will always rotate around the world axes........

    But I am stuck on how to reproduce that !

    I wanted to keep track of the X_Angle,Y_Angle,Z_Angle and then use the 3 different rotation matrices to obtain the full rotation matrix. Of course it does not work (OK, I should have thought about that before !).

    Let me explain... I wanted to use three rotations around X,Y,Z. I had three matrices Rx,Ry,Rz and I thought Rx*Ry*Rz=R would be my final matrix.... The problem is that when I apply Ry, it applies to my world coordinates system transformed by Rz !

    Does anyone know how I can rotate my object about any of the X,Y,Z of the WORLD coordinates system ????

    Just some precision : at the moment, for each object, I have a GLfloat m_TransformMatrix[16] (loaded with glLoadMatrix when rendering) and I keep track of the m_XRotationAngle, m_YRotationAngle and m_ZRotationAngle......

    I am not afraid of complicated maths so you can go !

    I would prefer an algorithm on how to build the transformation matrix based on my 3 angles but if I must use Euler angles and/or quaternions, please tell me !

    Hope someone can save my life !!!

    Eric

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    Re: Rotations again !

    I was thinking : could it be possible with the data I have to find the corresponding rotation of an angle a0 around an axis (x0,y0,z0) ???

    Eric

  3. #3

    Re: Rotations again !

    Ummm.. I'm not sure if I got it right, but..

    Basically you have object location and rotation in world space and rotation in object space. First you rotate the object in object space. Then you translate the object space coordinates into world space coordinates. After this, the rotations take place in world space.

    With 3ds exported models you get the transformation matrices, but you have to notice that the object vertices are in world space.

    Hope it helps...

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    Re: Rotations again !

    Yes, I know that (thanks anyway !).

    But if we forget that I import 3DS models, I would like to be able to rotate my object around one of the principal axes of my 3D World.... I guess I should transform my array of vertices each time I apply a rotation instead of trying to build a rotation matrix for the object...

    Anyone can help ????????????????

    Eric

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Rotations again !

    Hello

    First I want to ask you, do you mean to rotate the objects about the world origin just to be able to view the object(s) from different angles?

    If so, here is a solution.

    First you set up a camera with
    gluLookAt(cx, cy, cz, 0, 0, 0, u1, u2, u3);
    ... where cx,cy,cz is camera position, u1,u2, u3 is upvectors.
    If you want to be able to rotate, you can place the camera on a sphere with origin at (0,0,0) in world coordinates, and with radius large enough to enclose all objects.

    Then you translate object(s) to their position in worldcoordinates, and then draw them.

    If you want to, I can post the equations for setting cameracoordinates on a sphere.

    Bob

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    Re: Rotations again !

    Hi Bob !

    Actually, I want to rotate the objects around "their" world origin... I mean, when I load them, I center them on their gravity centre. Then, to display them, I just have to FIRST rotate and THEN translate....

    I can not use a camera there coz' I have got many objects in the scene and I want to rotate them individually !

    Well, I've been thinking of a way to simplify my problem....

    Let's take a coordinate system R(i,j,k) where i=(1,0,0) , j=(0,1,0) and k=(0,0,1).

    Then, I know that I want to rotate my vertices around i,j, and k with the angle a,b,c.

    Basically, my first technique is OK if I do the transformation myself i.e. I transform my vertex (x,y,z) with Rx(i,a) then Ry(j,b) and finally Rz(k,c) (or whatever order coz with this technique, I do not modify the rotation axes !!!!!).

    When it comes to using the OpenGL MODEL_VIEW matrix, it doesn't work because my first rotation will rotate the axes I use for the other rotations !

    So I was wondering if there is a way to find a rotation matrix depending on (a,b,c) that would rotate my object properly if I laod it as my MODEL_VIEW matrix......

    Thanks to anyone who can help !

    Eric

  7. #7

    Re: Rotations again !

    You CAN use camera AND rotate objects individually. Use glPushMatrix, glPopMatrix and glLoadIdentity to fiddle around with the current model view matrix. If you need to multiply the current matrix by your own use glMultMatrix. Or then do ALL transformations yourself and use glLoadMatrix.

  8. #8

    Re: Rotations again !

    Just something else... Are you sure you are multiplying the matrices in correct order?-)

  9. #9
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    Re: Rotations again !

    Well, the order of the matrices isn't so important for that problem : whatever the order, the first one will rotate the axes I want to use for the others rotations !

    The thing is, I AM OK TO DO THE ROTATION MATRIX MYSELF ! I am just looking for how to compute it !!!!!

    If I build it with multiplying R(i,a),R(j,b) and R(k,c) it won't work ! I am not sure of the english word but in french, it is called "Matrice de Passage". Those matrices are used when you change from one coordinate system to another... I believe I have to use them for my problem but I can't see how...

    Well, shame I studied only Maths and Physics for three years plus three others of engineering only and I do not remember anything..........................

    By the way, am I wrong or any combination of N rotations is equivalent to one rotation around an axis with a specified angle ?????

    I know I learnt to extract this axis and the angle from any rotation matrix but can not remember the method..........

    Well, just to let you know, I have implemented the method that consists of modifying my vertex arrays instead of using the modelview matrix and it works....

    And the reason is still the same : if you say :

    1) I want to rotate around X with angle a
    2) I want to rotate around Y with angle b
    3) I want to rotate around Z with angle c

    When using OpenGL and glRotate or whatever, when you do step 2, YOUR Y AXIS IS NOT THE ONE YOU HAD BEFORE step 1 !!!! Same when you reach step 3.....

    In fact I have a solution but it's gonna be quite time-consuming :

    When reaching step 2, I can find the coordinates of my Y axis in the new coordinates system.
    Then in step 3, I can find the coordinates of my Z axis in the new new ( ) coordinate system....

    The only thing that bothers me is : HOW YOU GUYS DO ??? Even if this problem doesn't arise for games, I have seen many people here saying they were developing some kind of CAD tool. So they must have ran into the same problem than me ! Do they rotate their vertices as I am doing now ? Or did they find the magic formula for building this bloody matrix from a,b and c ?????????

    Well, thanks anyway to all those who try to help me !!!

    Eric

  10. #10
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    Re: Rotations again !

    Sorry Hude, I think I did not understand what you said quite right !

    I thought you were asking if I was using glRotate in the correct order while I believe now that you were talking about my own matrix multiplications... And I must confess you were right...

    When doing my matrix product Rx*Ry*Rz, I calculated (Rx*Ry)*Rz while it must be Rx*(Ry*Rz) (Calculate Ry*Rx and then Rx*Result)........

    Basically I have the solution to my problem : instead of trying to use glRotate with X,Y and Z successively, I build my own Rotation / Translation matrix and use glMultMatrix to upload it to OpenGL....

    Thanks to everyone who helped me and sorry again Hude, I should have thought about what you said sooner (or at least understand what you meant !!!).

    Eric

Page 1 of 2 12 LastLast

Similar Threads

  1. Rotations- help?
    By cloudy in forum OpenGL: Linux
    Replies: 4
    Last Post: 08-07-2009, 10:52 PM
  2. rotations
    By michi in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-06-2008, 05:09 AM
  3. rotations
    By ThunderSoul in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-09-2005, 12:45 PM
  4. Rotations...
    By mkardesci in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-19-2003, 01:06 PM
  5. Rotations
    By jhc in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-03-2003, 07:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean