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

Started by
4 comments, last by haegarr 15 years, 8 months ago
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
Advertisement
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!
I suggest you look into Quaternions - there are alot of good tutorials out there

Good luck
I recommend that you read the discussion here. It helped me with a similar issue.
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.
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.

This topic is closed to new replies.

Advertisement