Thread: rotate an object in Opengl

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    5

    rotate an object in Opengl

    Hi, i'm learning opengl through a little app and now ive bumped into the 3d rotational problem.

    I store data for my object both the Rotation matrix and the quaternion. I want to visualize it and i tried to use glrotatef() with a quaternion_toAxisAngle() function but it doesnt quite work since glrotatef() accepts angles from 0 to 360 degrees and my quaternion_toAxisAngle() delivers an angle between -180 and 180 so when it starts to rotate around the x axis it does well between 0 and 180 degrees but then it stops rotating and gets stuck at 180 degrees. This happens when i apply a torque in the x axis.

    I think i cannot modify my quaternion_toAxisAngle() function to match the angle requirements so what are the alternatives?
    How can i do in order to have the object rotating 360 degrees?


    thanks in advance from Spain!!

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    -180 to 180 is 360 degrees. The function is using values relative to PI instead of 2 * PI. I don't see the problem.

  3. #3
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    You um don't actually rotate objects in OpenGL you rotate your projection matrix...

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    5
    -180 to 180 is 360 degrees. The function is using values relative to PI instead of 2 * PI. I don't see the problem.
    the rotation must be 360 degrees clockwise o counterclockwise, not just only 180

  5. #5
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    You um don't actually rotate objects in OpenGL you rotate your projection matrix...
    I thought the vertex data was modified by the model view matrix?

    To the question: Why not write a converter which maps 0..180 to the corresponding value and -180..-1 to 180..359? But I think this is unneccessary.

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    5
    Ok, solved!!, the strange rotation i was having made me think there was somthing with the angles range but there wasn't.

    The error was i was rotating a vector by a quaternion when what i really wanted was to perform a multiplication between a quaternion and another quaternion from a vector:

    v2 = Q *v*Q'

    instead of

    Q2 = Q * Qv where Qv is (0, vx, vy, vz)

    (this happens when we use math libraries we arent familiar with!!)


    thanks for your responses

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Object destroy itself?
    By cminusminus in forum C++ Programming
    Replies: 28
    Last Post: 03-27-2008, 01:08 AM
  2. Clicking an Object in OpenGL.
    By gpr1me in forum Game Programming
    Replies: 5
    Last Post: 03-26-2006, 10:12 PM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  4. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM