Irrlicht NOT Using Quaternions?

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Irrlicht NOT Using Quaternions?

Post by Robomaniac »

I just noticed something. Even though niko added Quaternions to the engine, from what i've seen, he's not using them for rotation. At least not for nodes and stuff. If he used them for orientation, things like moving a node relative to its curent position is a breeze :)

Just a thought!
The Robomaniac
Project Head / Lead Programmer
Centaur Force
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Yeah, I probably agree. I find matrices easier to understand then quaternions, but quaternions are definitely better then matrices for rotation (no nasty gimbal lock, which is definitely a downside of working with matrices)
One point though, OpenGL has got internal support for matrices but I believe not quaternions (dunno about dx) thoguh I haven't looked in the innards of the engine enough to know if niko's even using OGL for any transforms, so that migh not be an issue
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
AssiDragon
Posts: 158
Joined: Wed Apr 28, 2004 11:03 am
Location: Hungary
Contact:

Post by AssiDragon »

Depends. While there is gimbal lock in matrices, quaternations is something that I don't think I will ever understand deeper than "they are something that avoids gimbal lock and uses 4x4 matrix" :D
"Seeing" in 4 dimensions is just not my style. :/
Staring through eyes of hate we kill
Are we controlled, or is our own will...?
(Edguy)
zola
Posts: 52
Joined: Thu Jul 15, 2004 2:31 pm
Location: switzerland
Contact:

Post by zola »

You don't have to understand the quaternions. All You have to know is the methods the quaternion class provides and what they are used for, and some basic stuff:

1) normalised Quaternions can be used for rotations around an arbitrary axis

2) Quaternions can be converted to and from rotation matrices

3) Quaternions can be converted to and from euler angles

4) rotating a vector with a Quaternion : vec' = Quat * vec

5) concatenating 2 rotations: Quat = Quat2 * Quat1
Quat is the result of applying first the rotation Quat1 and then the rotation Quat2!

Now comes the fun part
:) the quaternion class in irrlicht is nearly useless because it doesn't provide the needed functions to use quaternions in a meaningful way.

I miss these functions the most:

void Quaternion.FromAngleAxis(float angle, Vector3 axis)

Vector3 Quaternion.toEuler()

Vector3 operator*(const Vector3& v)

But here comes the remedy:

Code: Select all

void quaternion::FromAngleAxis (const f32& angle, const vector3df& axis)
	{
		// assert:  axis is unit length
		//
		// The quaternion representing the rotation is
		//   q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k)

		f32 fHalfAngle = 0.5*angle;
		f32 fSin = sin(fHalfAngle);
		w = cos(fHalfAngle);
		x = fSin*axis.X;
		y = fSin*axis.Y;
		z = fSin*axis.Z;
	}

Code: Select all

void quaternion::ToEuler(vector3df& euler){
		double sqw = W*W;    
		double sqx = X*X;    
		double sqy = Y*Y;    
		double sqz = Z*Z; 
		// heading == rotaton about z-axis
		euler.Z = (f32) (atan2(2.0 * (X*Y +Z*W),(sqx - sqy - sqz + sqw)));
		// bank == rotation about x-axis
		euler.X = (f32) (atan2(2.0 * (Y*Z +X*W),(-sqx - sqy + sqz + sqw)));  
		// attitude == rotation about y-axis
		euler.Y = (f32) (asin(-2.0 * (X*Z - Y*W)));
	}

Code: Select all

vector3df quaternion::operator* (const vector3df& v) const
	{
		// nVidia SDK implementation
		vector3df uv, uuv; 
		vector3df qvec(X, Y, Z);
		uv = qvec.crossProduct(v); 
		uuv = qvec.crossProduct(uv); 
		uv *= (2.0f * W); 
		uuv *= 2.0f; 

		return v + uv + uuv;

	}
good day good sirs
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

thanks for those functions
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Thanks for the methods, maybe I'll add them if its ok for you.
If anybody wants a scene node which uses quaternions for rotation instead of matrices, just override ISceneNode and implement it. :)
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Looks like I may be adding it myself soon enough.

Been a boid demo and want to update each boid based on its rotation and speed and everything out there says "use the orientation quaternion"
Crud, how do I do this again?
Not Oz

Post by Not Oz »

euler angles = gimbal lock

Yes we want this please niko! Were too stupid to do it ourselves. :)
Post Reply