Solved

Camera rotation using quaternions

Posted on 2003-11-10
Medium Priority
2,259 Views
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
Question by:deol_bhaji
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 1

Accepted Solution

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_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.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:-)
0

LVL 11

Expert Comment

ID: 9731945

-bcl
0

Author Comment

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

Question has a verified solution.

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

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll