Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How To Use Quaternions

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Location
    California
    Posts
    2

    How To Use Quaternions

    I am having an issue figuring out how to implement quaternions. I was reading an article that suggested to use euler angles for the gameplay, but convert the euler angles to a quaternion only when you need to interpolate between two rotations. The article was written back in 1998 though so I am skeptical since this tech changes so often (http://www.gamasutra.com/view/featur...uaternions.php).

    Is that the correct approach to using quaternions or is there a better way? And if there is a better way, are there any articles you can point me to so I can start heading in the right direction?

    Lastly, and possibly the most helpful thing, could anyone post a link to some opensource OpenGL project that uses quaternions properly so I can just learn by reading the code?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    Quote Originally Posted by derydoca View Post
    I am having an issue figuring out how to implement quaternions. ... Is that the correct approach to using quaternions or is there a better way? And if there is a better way, are there any articles you can point me to so I can start heading in the right direction?
    It would help us to advise you if you'd describe the issue you're trying to solve. Otherwise this is just a technique in search of a problem. For instance, are you trying to interpolate rotations only? Or full rigid transformations? Do you want super-high quality/correctness, or are you more after speed? Is something that interpolates between adjacent pairs sufficient, or do you really need something that interpolates across 3 or more samples? ...and what's the problem domain? Camera transform interpolation? Skeletal animation? etc.

    For some possible issues, quaternions might be best. For others, they might be insufficient and would point you to something else like dual quats. Could provide you points to write-ups and code for both (and others).

    Among other places, there's Quat code in David Eberly's WildMagic engine: download link
    Last edited by Dark Photon; 06-03-2012 at 01:13 PM. Reason: rogue text

  3. #3
    Junior Member Newbie
    Join Date
    May 2012
    Location
    California
    Posts
    2
    What I am looking to achieve is to code a rudimentary game engine. I am not looking to make a game with it. I just want to be familiar with the inner workings of the game engine I use (Unity) and perhaps some day using the engine to make a game. Unity uses quaternions to express all of the rotations in the game, however you can get and set rotations in euler anglers.

    This is an idea that I mused that might work properly. Store the rotations as quaternions all the time but expose methods that will rotate it by another quaternion (or a set of euler angles converted into a quaternion). And if I remember correctly, multiplying the rotation quaternion with the new quaternion will rotate it by the second quaternion. And if I need to get the euler angles of a rotation I can just convert it back out into euler angles.

    I hope that makes sense. Also, I took a quick skim through the WildMagic engine. That looks like an excellent source of reference code. Thanks for sharing.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    Ok. I guess given you don't have a specific aim for quats yet, Eberly's code is probably a reasonable answer to your question.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •