Results 1 to 5 of 5

Thread: Local Axis of an object with a rotationMatrix

  1. #1
    Member Newbie
    Join Date
    Jun 2009
    Posts
    47

    Local Axis of an object with a rotationMatrix

    Hi there if i have an object that has a rotationMatrix

    r00 r04 r08 .0
    r01 r05 r09 .0
    r02 r06 r10 .0
    .0...0...0...1

    and global x y z coordinates

    and i want to find out the local-x-axis and use it to translate the local motion into global positions

    how would the code be? if i want increment the localxmovement by 1.0f

    tried something like this
    x += r00 + r04*r08;
    y += r01 + r05*r09;
    z += r02 + r06*r10;

    and in which way do i have normalize the rotationMatrix and the globalpositionincrements if i do so?
    this way? 1 0 0
    or this way?
    1
    0
    0

    Having some trouble with skewed picture and incorrect local-motions

  2. #2
    Member Newbie
    Join Date
    Jun 2009
    Posts
    47

    Re: Local Axis of an object with a rotationMatrix

    What does the rotationMatrix really represent?

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,653

    Re: Local Axis of an object with a rotationMatrix

    Quote Originally Posted by ColacX
    What does the rotationMatrix really represent?
    A linear combination of X, Y, and Z, for each of X, Y, and Z.

    You need to crack open a good intro to 3D graphics book and read up on matrices. I don't understand several of your questions.

    Also, to one of your previous questions expressing puzzlement as to whether to use row or column vectors:

    1 0 0

    vs.

    1
    0
    0

    You can use either, but because you're trying using OpenGL (which is column-major operator-on-the-left -- i.e. M*v1=v2), and you're probably trying to use it from C/C++ (which is row-major), then you want to use the row-major operator-on-the-right convention in your code (v1*M=v2). This implies row vectors.

    However, given some random matrix of values like the above, the provider needs to tell you which conventions is being followed. It could be either, and if you presume incorrectly, you'll just get garbage.

    Now given your rotation matrix:
    Code :
    r00 r04 r08 .0
    r01 r05 r09 .0
    r02 r06 r10 .0
    .0...0...0...1
    If we presume operator-on-the-right convention (v1*M=v2), then you can see that the local X axis v1=(1,0,0,0) maps to v2=(r00,r04,r08,0) in the destination space. This may answer one of your other questions.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: Local Axis of an object with a rotationMatrix

    A solution which might be easier than messing around with the orientation matrix is to order your GL calls as follows -
    Code :
    glLoadIdentity ();
    glMultmatrix (R);
    glTranslate (xo, 0.0, 0.0);
    Draw_Object ();
     
    Where R is your orientation matrix and xo is the distance
    you want to move the object along it's X axis. Is there a
    reason you can't take this approach?
    Am I doing your homework for you?

  5. #5
    Member Newbie
    Join Date
    Jun 2009
    Posts
    47

    Re: Local Axis of an object with a rotationMatrix

    Quote Originally Posted by MaxH
    A solution which might be easier than messing around with the orientation matrix is to order your GL calls as follows -
    Code :
    glLoadIdentity ();
    glMultmatrix (R);
    glTranslate (xo, 0.0, 0.0);
    Draw_Object ();
     
    Where R is your orientation matrix and xo is the distance
    you want to move the object along it's X axis. Is there a
    reason you can't take this approach?
    Thats almost how i have the code.
    Every object draw method does this
    Code :
    glLoadIdentity();
    glTranslate(globalX, globalY, globalZ);
    glMultmatrix(rotationMatrix);
    //drawObject code
    the camera is calculated by doing the same but in inverse.
    so i've seperated the global coordinates and the rotation out of convenience.

    hope that clarifys a bit, my problem is that when the object is doing a local motion it must account its rotation, so that if viewed from the object it will look like its moving 1 step in x-axis, but when viewed by others it will look like its moved in the direction it was rotated to.

    Quote Originally Posted by Dark Photon
    If we presume operator-on-the-right convention (v1*M=v2), then you can see that the local X axis v1=(1,0,0,0) maps to v2=(r00,r04,r08,0) in the destination space. This may answer one of your other questions.
    no that looks more like multiplication of a vector with a matrix, it doesnt make sense im my case.

    my problem is to translate localmotion into globalX, globalY, and globalZ.

    everyobject has a globalX,globalY and globalZ

    i've almost made it work with, but it's slightly wrong when the object is rotated at certain angles.
    globalX += r00 + r04*r08; //i just guessed this code by
    globalY += r01 + r05*r09; //trying to reason what the
    globalZ += r02 + r06*r10; //rotationMatrix really means.

    reasoning for my guessing is that let's say the object is not rotated at the moment then it would have a rotationMatrix with the values:
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1
    and if we moved 1 step in x-axis
    globalX += 1 + 0*0 = 1
    globalY += 0 + 1*0 = 0
    globalZ += 0 + 0*1 = 0

    the result is that the globalX changed +1 and the other didnt change at all, which is the wanted result that fits for this rotationMatrix but not some of the others

    i want to create a 3D world where every object and the camera to have its own globalPosition and localRotation, and i want every object and the camera to be able to move according to their localRotation. Just like in reality.

    How do you guys do it?

    oh i just tried using just
    globalX += r00;
    globalY += r01;
    globalZ += r02;
    this works perfectly with any kind of rotation for the camera but doesn't work for the objects when they've been rotated over 2 axises or more. very odd that it works perfectly for the camera but not the objects. for the objects its completly wrong

Similar Threads

  1. How to rotate objects around global axis not local axis
    By silvermeteor in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-04-2017, 11:10 AM
  2. How to rotate a local oriented object by the global lookat axis?
    By RaenirSalazar in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-27-2016, 03:48 PM
  3. Orbiting object around local axis of another one with GLM.
    By Maelren in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-19-2015, 05:11 PM
  4. I want the camera to spin around its local axis
    By mohammad_aburrub in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 06-23-2006, 07:40 AM
  5. Local and global axis
    By Simon Hall in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-26-2000, 06:43 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
  •  
Proudly hosted by Digital Ocean