Quaternions for rotations

  • Follow


I've googled for info and implemented my own quaternion code but I'll be 
damned if I can get the darned things to work :)

Does anyone have links to code showing how to use Quaternions to manage 
rotations in an OpenGL context?

TIA

Peter.

0
Reply Peter 2/24/2004 1:05:37 AM

Peter Ashford <me@here.there.com> wrote in news:Frx_b.214$SZ.37232
@news.xtra.co.nz:

> Does anyone have links to code showing how to use Quaternions to manage 
> rotations in an OpenGL context?

try www.gamedev.net
0
Reply Theo 2/24/2004 1:55:16 AM


Peter Ashford wrote:
> I've googled for info and implemented my own quaternion code but I'll be 
> damned if I can get the darned things to work :)
> 
> Does anyone have links to code showing how to use Quaternions to manage 
> rotations in an OpenGL context?
> 
> TIA
> 
> Peter.
> 

Look for "trackball" in google and you'll find more.
(assuming you want to move your camera with quaternions)


Here'a a code example:
http://cvs.sourceforge.net/viewcvs.py/bzflag/bzflag/src/bzgview/Attic/Trackball.cxx?rev=1.6

Cheers,

	Toni

-- 
for mail, mirror: ed.lausivksa@elielb
0
Reply Antonio 2/24/2004 9:27:20 AM

> Look for "trackball" in google and you'll find more.
> (assuming you want to move your camera with quaternions)

It's orienting object that I'm after (my camera is just afixed to an 
object, so that's where the issue lies for me :) )

> 
> Here'a a code example:
> http://cvs.sourceforge.net/viewcvs.py/bzflag/bzflag/src/bzgview/Attic/Trackball.cxx?rev=1.6 
> 
> 
> Cheers,
> 
>     Toni
> 

Thank you :)

0
Reply Peter 2/25/2004 12:02:21 AM

Peter Ashford <me@here.there.com> wrote in message news:<Frx_b.214$SZ.37232@news.xtra.co.nz>...
> I've googled for info and implemented my own quaternion code but I'll be 
> damned if I can get the darned things to work :)

Double-check the docs you're using.  I know some of them have the
conversion from quaternion to matrix WRONG. I'll include my code down
below for reference.

Also, careful on the order of your operations when doing successive
rotations.  If you get it backwards (like I did at first-- grr), then
your objects will not rotate smoothly.  Again, read the quaternion
references carefully.


Anyway, here's the code.  Please don't be too mean in your criticism,
please.  :-)



Note that the quaternion has members m_a, m_x, m_y, m_z (no surprise
there).  The Matrix4x4 is pretty obvious too.


void Quaternion::toRotationMatrix(Matrix4x4 &m) const
{
	R3DReal twoXSquared = 2.0 * m_x * m_x;
	R3DReal twoYSquared = 2.0 * m_y * m_y;
	R3DReal twoZSquared = 2.0 * m_z * m_z;
	R3DReal twoXY = 2.0 * m_x * m_y;
	R3DReal twoXZ = 2.0 * m_x * m_z;
	R3DReal twoYZ = 2.0 * m_y * m_z;
	R3DReal twoAX = 2.0 * m_a * m_x;
	R3DReal twoAY = 2.0 * m_a * m_y;
	R3DReal twoAZ = 2.0 * m_a * m_z;
	
	m.m_matrix[m.R1C1] = 1.0 - twoYSquared - twoZSquared;
	m.m_matrix[m.R1C2] = twoXY - twoAZ;
	m.m_matrix[m.R1C3] = twoXZ + twoAY;
	
	m.m_matrix[m.R2C1] = twoXY + twoAZ;
	m.m_matrix[m.R2C2] = 1.0 - twoXSquared - twoZSquared;
	m.m_matrix[m.R2C3] = twoYZ - twoAX;
	
	m.m_matrix[m.R3C1] = twoXZ - twoAY;
	m.m_matrix[m.R3C2] = twoYZ + twoAX;
	m.m_matrix[m.R3C3] = 1.0 - twoXSquared - twoYSquared;
}
0
Reply roy 2/25/2004 4:31:25 PM

4 Replies
147 Views

(page loaded in 0.082 seconds)

Similiar Articles:













7/15/2012 9:46:16 AM


Reply: