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!
Irrlicht NOT Using Quaternions?
-
- Posts: 602
- Joined: Sat Aug 23, 2003 2:03 am
- Location: Pottstown, PA
- Contact:
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
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
Crucible of Stars
-
- Posts: 158
- Joined: Wed Apr 28, 2004 11:03 am
- Location: Hungary
- Contact:
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"
"Seeing" in 4 dimensions is just not my style. :/
"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)
Are we controlled, or is our own will...?
(Edguy)
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:
good day good sirs
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;
}
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
Crucible of Stars