How to move around in space ?
Hi there,
I want to write a small space sim ....
The ship should move around like a plane. Every ship has a position in space and three angles, representing the direction the ship is looking at. The position of my ship is always 0,0,0 at the moment to test the other routines.
display method:
...
camera->setMatrix(); // no translation, just rotating around
stars -> render ();
// render some objects
camera-> removeMatrix();
...
movement mehtod:
...
mouseX = mouseXPos - oldMouseXPos;
mouseY = mouseYPos - oldMouseYPos;
pitch = player -> getPitch();
roll = player -> getRoll();
heading = player -> getHeading();
player -> setRoll ( roll + mouseX );
player -> setPitch ( pitch + cos (roll) * mouseY ) ;
player -> setHeading( heading + sin (roll) * mouseY);
oldMouseXPos = mouseX;
oldMouseYPos = mouseY;
..
Heres my camera
setMatrix(): // From the red Book
{
glPushMatrix();
glRotatef( player->getRoll(), 0.0, 0.0, 1.0 );
glRotatef( player->getPitch(), 0.0, 1.0, 0.0 );
glRotatef( player->getHeading(), 1.0, 0.0, 0.0 );
// glTranslatef(...);
}
removeMatrix()
{
glPopMatrix();
}
Well the roll part works fine but, when i move the mouse up and down it doesn''t work at all. I can''t expain how .... it''s absolutely chaotic...
Any ideas ?
It seems you are mixing mouseX and mouseY which are deltas in screen space coordinates with angles roll, pitch probably in degrees (Rotatef uses degrees not radians). Also don''t forget to convert degrees to radians before you compute sine and cosine of an angle.
Ohh YES thanks a lot, especially QWERTY...
I changed it now and it works .......
but only for a short while ....... after a some movements with angles larger than .. lets say 90 deg it gets absolutely chaotic..... I dont know why .....
After realizing that I added some lines that keep the three angles between -180 and 180.... without any effect......
MMMMhm
Any ideas ?
Or should I stop here and follow the paths of Eoin ?
I changed it now and it works .......
but only for a short while ....... after a some movements with angles larger than .. lets say 90 deg it gets absolutely chaotic..... I dont know why .....
After realizing that I added some lines that keep the three angles between -180 and 180.... without any effect......
MMMMhm
Any ideas ?
Or should I stop here and follow the paths of Eoin ?
Might you be experiencing gimbal lock? The best way around it is to use quaternions instead of matrices. But there are ways around it.
Here''s some advice from another source:
Quaternions & Representing Object Orientation - 21 June 1999
and even better ...
Quaternion Powers
eriol
Here''s some advice from another source:
Quaternions & Representing Object Orientation - 21 June 1999
and even better ...
Quaternion Powers
eriol
Ok slow down !
What are quaternions ? -- Do you know the german expression for it ? And whats a gimbal lock ?
I will release a demo to show my problem soon ...... But my friend still needs some time to get page online...
What are quaternions ? -- Do you know the german expression for it ? And whats a gimbal lock ?
I will release a demo to show my problem soon ...... But my friend still needs some time to get page online...
Heh heh ...
Well ... I''ll do my best to explain Gibal Lock ...
Gimbal Lock occurs when you end up rotating an axis such that becomes parallel with another axis in whose dimension you have not yet rotated. Thus you lose a degree of freedom until the axis is no longer parallel to the other axis. I''m not 100% sure of why it happens either (I have trouble envisioning it). You can look at the sources below for better explainations:
What is Gimbal Lock and why does it occur?
Look under Euler Details here.
You can look up "gimbal lock" on any search engine in case these aren''t adequate.
As for quaternions ... I think the best thing to do is to consult the sources I cited above. Unfortunately, I don''t know how "quaternion" translates into German . Search engines or books would be your best bet - you can find a lot online.
To do a real bad job at describing them, quaternions are as follows. They are a 4 unit vector-like entity: {a (i j k)} - where (i j k) is a vector and a is a scalar. For our purposes (that is, rotation) (i j k) is an arbitrary axis, and a is the angle of rotation. You should write a library (or better yet find one) that takes care of quaternion multiplications. There are ways to convert between euler angles and quaternions, and matrices and quaternions, as well as some cool effects such as SLERP, where you can calculate another quaternion anywhere on a path of transformation between 2 given quaternions. Actually, there''s some pretty neat stuff you can do with them. They''re just not very intuitive, and the math takes a while to understand. But once you get the functions to take care of it for you, you tend not to think about them too much anymore.
But seriously ... consult other sources ... I do a poor job of describing them. I have worked with them in the past, but since I don''t do much with them I still rely on documentation.
Hope I''ve been some help. To others, please correct me if I''m wrong, or what I said needs clarification. It''s not my best understood subject.
eriol
Well ... I''ll do my best to explain Gibal Lock ...
Gimbal Lock occurs when you end up rotating an axis such that becomes parallel with another axis in whose dimension you have not yet rotated. Thus you lose a degree of freedom until the axis is no longer parallel to the other axis. I''m not 100% sure of why it happens either (I have trouble envisioning it). You can look at the sources below for better explainations:
What is Gimbal Lock and why does it occur?
Look under Euler Details here.
You can look up "gimbal lock" on any search engine in case these aren''t adequate.
As for quaternions ... I think the best thing to do is to consult the sources I cited above. Unfortunately, I don''t know how "quaternion" translates into German . Search engines or books would be your best bet - you can find a lot online.
To do a real bad job at describing them, quaternions are as follows. They are a 4 unit vector-like entity: {a (i j k)} - where (i j k) is a vector and a is a scalar. For our purposes (that is, rotation) (i j k) is an arbitrary axis, and a is the angle of rotation. You should write a library (or better yet find one) that takes care of quaternion multiplications. There are ways to convert between euler angles and quaternions, and matrices and quaternions, as well as some cool effects such as SLERP, where you can calculate another quaternion anywhere on a path of transformation between 2 given quaternions. Actually, there''s some pretty neat stuff you can do with them. They''re just not very intuitive, and the math takes a while to understand. But once you get the functions to take care of it for you, you tend not to think about them too much anymore.
But seriously ... consult other sources ... I do a poor job of describing them. I have worked with them in the past, but since I don''t do much with them I still rely on documentation.
Hope I''ve been some help. To others, please correct me if I''m wrong, or what I said needs clarification. It''s not my best understood subject.
eriol
Hello,
if you don''t want to dive into quaternions, you should really try Eoins link. His classes offers exactly what you''re searching for! You can also follow what he does if you want to (I mean understanding the math) To to this you have to take a some time, it''s a little bit tricky, and you will need at least vector math.
I''ve tried to understand quaternions, but until now I didn''t managed it. Hopefully studying will bring enlightment :-)
Man kann Quaternions nicht wirklich ins Deutsche uebersetzen, jedenfalls meiner Meinung nach. Babylon sagt dazu: "Viererspiel aus echten Zahlen die komplexe Nummern beinhalten", aber das ist eine rein mathematische Definition, und keine informatische. Aber mit komplexen Zahlen hat das was zu tun.
Gruss Ben
if you don''t want to dive into quaternions, you should really try Eoins link. His classes offers exactly what you''re searching for! You can also follow what he does if you want to (I mean understanding the math) To to this you have to take a some time, it''s a little bit tricky, and you will need at least vector math.
I''ve tried to understand quaternions, but until now I didn''t managed it. Hopefully studying will bring enlightment :-)
Man kann Quaternions nicht wirklich ins Deutsche uebersetzen, jedenfalls meiner Meinung nach. Babylon sagt dazu: "Viererspiel aus echten Zahlen die komplexe Nummern beinhalten", aber das ist eine rein mathematische Definition, und keine informatische. Aber mit komplexen Zahlen hat das was zu tun.
Gruss Ben
After reading the tutz I understand the gimbal lock.. And well I encounter it in my demo !
Now 2 hours after reading the stuff about quaternions .. Well I am confused ... and the complex numbers try to get out my head shouting FOR WORLD DOMINATION
ok lets come back to topic
I will try to understand Quats because they sound pretty interesting !! I never thought that sth like complex numbers will be important part in my work.
Well thanks to you all !
Now 2 hours after reading the stuff about quaternions .. Well I am confused ... and the complex numbers try to get out my head shouting FOR WORLD DOMINATION
ok lets come back to topic
I will try to understand Quats because they sound pretty interesting !! I never thought that sth like complex numbers will be important part in my work.
Well thanks to you all !
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement