Sign in to follow this  
Olentzero

Transformations for Spacecruiser - Navigation

Recommended Posts

Hola amigos, I have to realise a OpenGL-Project for my Computergrafics Course here in San Sebastian by programming a space cruiser who flies throw space. The navigation therefore should work as follows: Increasing and decreasing of speed, and changing of directions by three rotations (pitch, heading, roll). The issue of navigation is now to realise the transformations in the correct way. I want the rotations (changes of directions) always be interpreted from the current state of orientation of the cruiser. E.g.: First, the cruiser is in coordinate space origin. Second, user presses the pitch-rotation button that the cruiser is turned about 90°. Simulated by y-rotation (e.g. glRotatef(pitchval,0,-1,0)) Third, user presses the heading-rotation button. What i want the cruiser to do now, is that it should head up and down with this nose. But what my program does to now is, that actually it led the cruiser roll for that it doesn't "think" in the new coordinate system of the cruiser but in the old. Here an the representing excerpt of code: ---------------------------------------------------- glPushMatrix(); glTranslated(koord[12],koord[13],koord[14]); glRotatef(rollval/4,0,0,-1); glRotatef(headingval/4,-1,0,0); glRotatef(pitchval/4,0,-1,0); glTranslatef(0,0,-speed); glRotatef(180,0,0,1); glRotatef(90,1,0,0); drawWireShip(); glGetDoublev(GL_MODELVIEW_MATRIX, koord); glPopMatrix(); ---------------------------------------------------- The first glTranslated moves the cruiser to the former position. There it is rotated for the given arguments of heading,rolling and pitching. Then its moved in this direction of the given speed argument an rotated at last once again for that the object is loaded with this bad orientation (correction rotations). Finally the cruiser is drawn by drawWireShip and the final transformationmatrix is stored in the array koord. Conclusively: What i want is a cruiser that is always heading/pitching/rolling when the user hit the heading/pitching/rolling button, with consideration of the current orientation. Using my code the cruiser is always heading/pitching/rolling according to the initial coordinate system. Gracias para ayudarme!

Share this post


Link to post
Share on other sites
You won't be able to do this (at least not straightforwardly) using OpenGL function calls. Rather, you'll need to store the orientation from frame to frame and update it incrementally.

For this you'll need some basic math classes (a vector class, and possibly a matrix or quaternion class).

I don't know what the focus of the homework assignment is, or whether you're allowed to use third-party code. If you can use other code, I can provide some links or suggest math libraries you could use that would take care of some of the work for you. If however the purpose of the assignment is the develop your 3D math and coding skills, the best we can probably do is offer some pointers on how to proceed.

In this latter case, you'll need a 3D vector class, so that'd be a good place to start. (Unless you want to hack it together with OpenGL function calls and state queries, which I wouldn't recommend.)

Share this post


Link to post
Share on other sites
Vale,

I would fit with a link to a guide that shows how to solve his problem by using the 3rd-hand math or quaternion class. I think i have enough theoretical background to understand the class. What i am most interested in is where and when to combine c++ and opengl-commands to get the wished new coordinate system.

Gracias para todo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this