actually, what i mean by IMPLEMENTATION is a good QUATERNION CLASS. all the ones i've found either did not have an associated header file, or had linker problems.
if i attempt to create a quat class myself, that'd take up a year i think.
oh, but TC, that was undoubtedly cool.
a2k
Edited by - a2k on 5/3/00 12:14:05 AM
Edited by - a2k on 5/3/00 12:15:37 AM
quaternions
------------------General Equation, this is Private Function reporting for duty, sir!a2k
i''m trying to compile that one from darwin3d.com, and i get this linking error:
LNK1104: cannot open file "nafxcwd.lib"
what''s the deal?
a2k
LNK1104: cannot open file "nafxcwd.lib"
what''s the deal?
a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Which one? Mine compiles fine.. and I don''t see any ref to that lib u are referring to..
the first one, the march one. the dagger. okay, maybe it's just my settings. i feel so lame. i've tried it under win32 app, and console app, and included all headers, and the resource, too. and compiled all files.
a2k
Edited by - a2k on 5/3/00 1:15:25 AM
a2k
Edited by - a2k on 5/3/00 1:15:25 AM
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Most probably the settings..
but there is a workspace included already.. why create your own??
Maybe I will write a tutorial on quaternion when I feel bored and if there is enough interest..
but there is a workspace included already.. why create your own??
Maybe I will write a tutorial on quaternion when I feel bored and if there is enough interest..
May 03, 2000 07:25 AM
Hay!
I am currently working on a 3D star wars game like X-Wing vs Tie fighter or XWA Alliance (yes, I am a star wars geek )
I have a similar problem. I already made a really good 3d-model of a Tie-Interceptor and now I want to fly around in it, I cant get the rotations correctly. I need it to move up/down, left/right and roll. I tried it using standard 3d rotation matrices but those are just plain evil and I can''t seem to get it right with those. So I decided to try quaternions. I saw this post and followed the links to get some more insight into quaternions. So I moved to using quaternions but I still cant get the way I want it. I want my ship to able to do the same movements like the ship in TC''s homepage. So how do I do that with quaternions? Any hints? or does have somebody have some source code that shows how to do it? Any help would be appreciated
WickedMystic
I am currently working on a 3D star wars game like X-Wing vs Tie fighter or XWA Alliance (yes, I am a star wars geek )
I have a similar problem. I already made a really good 3d-model of a Tie-Interceptor and now I want to fly around in it, I cant get the rotations correctly. I need it to move up/down, left/right and roll. I tried it using standard 3d rotation matrices but those are just plain evil and I can''t seem to get it right with those. So I decided to try quaternions. I saw this post and followed the links to get some more insight into quaternions. So I moved to using quaternions but I still cant get the way I want it. I want my ship to able to do the same movements like the ship in TC''s homepage. So how do I do that with quaternions? Any hints? or does have somebody have some source code that shows how to do it? Any help would be appreciated
WickedMystic
WickedMystic, Lucas is paranoid about his copyrights, so im not sure that your project could go commercial.
However, if its just a private game, go right ahead.
===============================================
"Tell brave deeds of war."
Then they recounted tales, -- "There were stern stands And bitter runs for glory."
Ah, I think there were braver deeds.
However, if its just a private game, go right ahead.
===============================================
"Tell brave deeds of war."
Then they recounted tales, -- "There were stern stands And bitter runs for glory."
Ah, I think there were braver deeds.
This is my signature. There are many like it, but this one is mine. My signature is my best friend. It is my life. I must master it as I must master my life. My signature, without me, is useless. Without my signature, I am useless.
Just to be sure...
Is the order in which you multiply the quaternions important? Like: Q_yaw * Q_pitch * Q_roll or: Q_pitch * Qyaw * Q_roll?
If so, how do I determine that order based on keyboard or joystick input? I am trying to control the view using keys/joystick.
WIcked
Is the order in which you multiply the quaternions important? Like: Q_yaw * Q_pitch * Q_roll or: Q_pitch * Qyaw * Q_roll?
If so, how do I determine that order based on keyboard or joystick input? I am trying to control the view using keys/joystick.
WIcked
hey, wickedmystic, i think it does matter of order, just like matrices. i don''t think they''re commutative. but i wouldn''t know, cuz i don''t have a working QUATERNION CLASS! do you have a working quaternion class? and where do you get it?
the darwin3d demo was done in vc++5. i''m using 6, would that make a difference?
a2k
the darwin3d demo was done in vc++5. i''m using 6, would that make a difference?
a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
May 03, 2000 10:35 AM
ak2, here it goes:
struct Matrix {
float pos[16];
};
class quaternion {
private:
float x,y,z,w;
public:
void normalize()
{
float length;
length = (float)sqrt(x*x + y*y + z*z + w*w);
x/= length;
y/= length;
z/= length;
w/= length;
}
void make(vector axis, GLfloat angle)
{
float pi = 3.141592f;
float sin_a = (float)sin(angle*pi/360);
float cos_a = (float)cos(angle*pi/360);
x = axis.x * sin_a;
y = axis.y * sin_a;
z = axis.z * sin_a;
w = cos_a;
normalize();
}
Matrix CreateRotationMatrix()
{
GLfloat xx, xy, xz, xw, yy, yz, yw, zz, zw;
Matrix M;
xx = x*x;
xy = x*y;
xz = x*z;
xw = x*w;
yy = y*y;
yz = y*z;
yw = y*w;
zz = z*z;
zw = z*w;
M.pos[0] = 1 - 2 * (yy + zz);
M.pos[1] = 2 * (xy - zw);
M.pos[2] = 2 * (xz + yw);
M.pos[3] = 0;
M.pos[4] = 2 * (xy + zw);
M.pos[5] = 1 - 2 * (xx + zz);
M.pos[6] = 2 * (yz - xw);
M.pos[7] = 0;
M.pos[8] = 2 * (xz - yw);
M.pos[9] = 2 * (yz + xw);
M.pos[10]= 1 - 2 * (xx + yy);
M.pos[11]= 0;
M.pos[12]= 0;
M.pos[13]= 0;
M.pos[14]= 0;
M.pos[15]= 1;
return M;
}
};
This is the class I made. It doesnt have many member functions. I just coded what I needed so far.
with:
M[] = 0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15
It works fine now. I setup 3 axis for the camera.
for example:
camera = { 0, 0, -1); (is also the axis to "roll" around)
top = { 0, 1, 0); (is also the axis to "yaw" around)
right = { 1, 0, 0); (is also the axis to "pitch" around)
then in my code:
quaternion Q;
Q.make(right, pitchangle); // change pitch
Matrix M;
M = Q.CreateRotationMatrix();
top = v_yaw * M;
camera = camema * M;
Q.make(pitch, yawangle); // yaw camera
M = Q.CreateRotationMatrix();
right = right * M;
camera = camera * M;
glLoadIdentity();
gluLookAt(0,0,0, cam.x, cam.y, cam.z, top.x, top.y, top.z);
This works fine finally, but there are still some things that worry me:
- pitchangle, yawangle are actually the change in pitch and angle rather than the actual(absolute) angles.
- the camera, top and right vectors will get additive numerical errors over a period of time.
I dont know how to solve this yet. Anyone know a way to set up the camera correctly using the actual(absolute) pitch, yaw and roll angles?
WickedMystic
struct Matrix {
float pos[16];
};
class quaternion {
private:
float x,y,z,w;
public:
void normalize()
{
float length;
length = (float)sqrt(x*x + y*y + z*z + w*w);
x/= length;
y/= length;
z/= length;
w/= length;
}
void make(vector axis, GLfloat angle)
{
float pi = 3.141592f;
float sin_a = (float)sin(angle*pi/360);
float cos_a = (float)cos(angle*pi/360);
x = axis.x * sin_a;
y = axis.y * sin_a;
z = axis.z * sin_a;
w = cos_a;
normalize();
}
Matrix CreateRotationMatrix()
{
GLfloat xx, xy, xz, xw, yy, yz, yw, zz, zw;
Matrix M;
xx = x*x;
xy = x*y;
xz = x*z;
xw = x*w;
yy = y*y;
yz = y*z;
yw = y*w;
zz = z*z;
zw = z*w;
M.pos[0] = 1 - 2 * (yy + zz);
M.pos[1] = 2 * (xy - zw);
M.pos[2] = 2 * (xz + yw);
M.pos[3] = 0;
M.pos[4] = 2 * (xy + zw);
M.pos[5] = 1 - 2 * (xx + zz);
M.pos[6] = 2 * (yz - xw);
M.pos[7] = 0;
M.pos[8] = 2 * (xz - yw);
M.pos[9] = 2 * (yz + xw);
M.pos[10]= 1 - 2 * (xx + yy);
M.pos[11]= 0;
M.pos[12]= 0;
M.pos[13]= 0;
M.pos[14]= 0;
M.pos[15]= 1;
return M;
}
};
This is the class I made. It doesnt have many member functions. I just coded what I needed so far.
with:
M[] = 0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15
It works fine now. I setup 3 axis for the camera.
for example:
camera = { 0, 0, -1); (is also the axis to "roll" around)
top = { 0, 1, 0); (is also the axis to "yaw" around)
right = { 1, 0, 0); (is also the axis to "pitch" around)
then in my code:
quaternion Q;
Q.make(right, pitchangle); // change pitch
Matrix M;
M = Q.CreateRotationMatrix();
top = v_yaw * M;
camera = camema * M;
Q.make(pitch, yawangle); // yaw camera
M = Q.CreateRotationMatrix();
right = right * M;
camera = camera * M;
glLoadIdentity();
gluLookAt(0,0,0, cam.x, cam.y, cam.z, top.x, top.y, top.z);
This works fine finally, but there are still some things that worry me:
- pitchangle, yawangle are actually the change in pitch and angle rather than the actual(absolute) angles.
- the camera, top and right vectors will get additive numerical errors over a period of time.
I dont know how to solve this yet. Anyone know a way to set up the camera correctly using the actual(absolute) pitch, yaw and roll angles?
WickedMystic
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement