Sign in to follow this  
oz02

I am a opengl beginner, I have a question about MATRIX.

Recommended Posts

Some of my friends with myself included are trying to code a air combat game. Some problems pop up. One of such is how to rotate a object along its own axis. Our current code is as folllowed: float MaTemp[16] = {1.0, 0.0, 0.0,0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}; void Draw (void) { ..................//movecode glMultMatrixf(MaTemp); .................//Drawland ................. glGetFloatv(GL_MODELVIEW_MATRIX,MaTemp); } While this method solves above mentioned problem, another arises. How to get coordinates of certain scene from the viewpoint? We really have a hard time on this. This is my code : http://www.mediafire.com/?dxrgditufbx

Share this post


Link to post
Share on other sites
Well at first I would suggest you split up your code to more codefiles, like putting the Mesh class in its own file.

But what exactly is your problem with rotation? Usually you can just use glRotatef(angle, x,y,z) to rotate the object around the axis specified through (x,y,z) and the given angle.

Remember the order of calls to glRotate and glTranslate is important. The last operation in your code will be the first performed on the Object you draw.


Your call to glMultMatrixf with the identity matrix just does nothing, did you want to have a rotation matrix in MaTemp? Thats exactly the same as using glRotatef.

You project looks great already!

Share this post


Link to post
Share on other sites
Quote:
Original post by Caste
Well at first I would suggest you split up your code to more codefiles, like putting the Mesh class in its own file.

But what exactly is your problem with rotation? Usually you can just use glRotatef(angle, x,y,z) to rotate the object around the axis specified through (x,y,z) and the given angle.

Remember the order of calls to glRotate and glTranslate is important. The last operation in your code will be the first performed on the Object you draw.


Your call to glMultMatrixf with the identity matrix just does nothing, did you want to have a rotation matrix in MaTemp? Thats exactly the same as using glRotatef.

You project looks great already!



Thank you for your reply.
Probably you have noticed, in our little project, there is no map, no indicator of directions, and it lacks a sense of gravity. All could be due to my inability to decide where the players should be, or simply I dont know how to calculate the relative positions of player's viewpoint to the ground surface model. That's too one of my questions I wish to find an answer with your help.

Share this post


Link to post
Share on other sites
My suggestion is to stay away from glGetFloatv(GL_MODELVIEW_MATRIX,...) and to implement (or fetch) a matrix/vector library for 3D graphics.

Then associate a position and an orientation with the aircraft, both related to the world space. Use incremental rotation and position updates, as is described in the post referred to by Gage64. Compose position and orientation to the local-to-global transformation matrix, treat the matrix as 3rd person camera frame, and invert it to yield in the view matrix (in this special case there are some tricks possible, making the inversion simple).

The map and direction issue is then simple, too, because position and orientation are available. Extract the world-related forward vector, if necessary by multiplication of the cardinal forward vector, and use its (perhaps) x,z co-ordinates. Normalize that 2D vector and use the result like a "compass-needle"; but be aware to catch the case of 0 length before normalization, namely if your aircraft is speeding straight the earth.

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