Solved

Camera rotation using quaternions

Posted on 2003-11-10
3
2,250 Views
Last Modified: 2012-08-13
How do I specify the rotation of a camera using quaternions about an axis at a specified angle. I know how to rotate about individual axis, but what if I wanted the camera to rotate about all three i:e: u,v and n axis about the eye.
I am programming in C++ using OpenGL.

Thanks.
0
Comment
Question by:deol_bhaji
3 Comments
 
LVL 1

Accepted Solution

by:
jadecc earned 500 total points
ID: 9720089
Hi,

I wish I could claim that I completely understood quaternions. What I had to do was keep up with the values (in degrees) of the heading (u), pitch (v), and roll (n) of the camera.  Then I created a quaternion from each of these angles and used them to figure out the view and driection of the camera:


      //quaternions that represent rotation
      m_qHeading.CreateFromAxisAngle(0.0f, 1.0f, 0.0f, m_HeadingDegrees);
      m_qPitch.CreateFromAxisAngle(1.0f, 0.0f, 0.0f, m_PitchDegrees);
      m_qRoll.CreateFromAxisAngle(0.0f, 0.0f, 1.0f, m_RollDegrees);
      
      //combine pitch and heading and roll and put into quaternion q
      q = m_qPitch * m_qHeading * m_qRoll;
      q.CreateMatrix(Matrix);
      
      // set our new perspective
      glMultMatrixf(Matrix);
      
      //get the y coord for our direction from the pitch quaternion
      m_qPitch.CreateMatrix(Matrix);
      m_qDirection.y = Matrix[9];
      ypitch = Matrix[9];
            
      //combine heading and pitch rotations to get the x and z coords for our direction
      q = m_qHeading * m_qPitch;
      q.CreateMatrix(Matrix);
      m_qDirection.x = Matrix[8];
      m_qDirection.z = Matrix[10];      


For a better explanation than I can offer check this link: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Quaternion_Camera_Class

I hope that helps you more than hinders you:-)
jadecc
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9731945
deol_bhaji - Did jadecc answer your question? Do you need more or different information?

-bcl
0
 

Author Comment

by:deol_bhaji
ID: 9735994
Thank you Jadecc. The link you sent was quite helpful. I guess I need to study a bit more on quaternions first.
deol_bhaji.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now