Author Topic: Best way to use quaternions ?  (Read 2934 times)

0 Members and 1 Guest are viewing this topic.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Best way to use quaternions ?
« on: December 08, 2013, 08:33:23 am »
Hey guys,

I've recently got some interest for quaternions, since I couldn't take Gimbal Lock anymore. So what I did is write a small quaternion lib in Axe, but realized I could do at max 15 FPS, where with a classical 3*3 XY rotation matrix I could do more than 56 FPS. So I was asking myself, what's the best way (by that understand : the fastest, the one that uses the less calculations) to use quaternions ?

Right now I use this technique :
  • Start with an identity quaternion and its conjugate.
  • Game loop :
    • Multiply each vertex by the quaternion and its opposite : v' = q * v * q-1
    • If an arrow key is pressed, multiply the quaternion by another quaternion representing the correct rotation : if left arrow is pressed, multiply by a quaternion traducing -4° around the (0,1,0) axis, if it's the up arrow multiply it by a quaternion traducing 4° around the (1,0,0) axis etc. I build a quaternion out of an axis and an angle : q = sin(Θ/2) * axis + cos(Θ/2)
    • After that, get the conjugate of the resulting quaternion.
    • Get back to the beginning.
I'm not quite sure this is the best way to do it since multiplying two quaternions implies 16 multiplications, and rotating a vertex by a quaternion implies 2 quaternions multiplications. Any idea ?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Best way to use quaternions ?
« Reply #1 on: December 08, 2013, 10:00:27 am »
Checking out Wikipedia's article, the comparison shows that you can't really get much better than that with quaternions. I've been looking into them, too, but also, I don't see why you would only get 10FPS if you were getting so much more with rotation matrices.