Multiple moving objects

Started by
11 comments, last by JM33 12 years, 10 months ago
Are there other moving objects than the plane? Maybe it would be easier if you first created an enemy plane that is moving independently in a straight line, because to make a rocket that at first sits on your plane and is fired later sounds more difficult.

The discussion about matrices is very interesting. I haven't much thought about it as matrix mathematics, I've just thought about translations and rotations. If you are not comfortable with matrix mathematics it might be easier to not think about the matrices, even though using matrix mathematics might be the more professional approach.

At first I had some problems with making things move and rotate correctly in OpenGl, but after some experimenting I learned how to do it. I would grade this problem as a problem with a low difficulty. While developing your game you'll run into other problems that are much more difficult, like creating the AI for enemy planes. I'm sure that you can figure out how to do translations and rotations yourself without thinking about matrices or using other libraries. To use matrix libraries sounds like a much more difficult approach, because then you first need to learn how to use the libraries, thus making the problem more complex.

Advertisement
This is how you can do. You can imagine the origin (0,0,0) as a point in the world. Then give the airplane the coordinates (x,y,z) relative to the origin. If you are object oriented you can store them in the airplane object. The airplane will not be at the middle of the screen. Now write glTranslatef( -x, -y, -z ). This will move the coordinate system so that the airplane is at the middle of the screen.

You can move the plane by changing the position in accordance with the laws of mechanics, like x += v + t. Then when you render next time, the plane will still be at the middle of the screen,but the world seems to have moved.

Draw the other objects after the translation. If you have another plane you can give it the coordinates (x1, y1, z1) and you can move it according to the laws of physics. When you run the game loop, it will move relative to your airplane.

The problem with the rocket would be that it is first drawn before the translation (and rotations), so that it is always at the same position relative to the plane body, and then after it is fired it should be drawn after the translation (and rotations) . When your airplane fires the rocket, you might have to do some simple trick to make it first follow the plane and then leave the plane when it is fired. As a dirty trick maybe you can delete the rocket and then create a new rocket as an object that is treated the same way as the other objects, with its own coordinates and velocity vector, and draw it after the translation.

Thanks Artes, but as far as I have read the only way for me to achieve this is through the use of matrices. I am trying to get six degrees of freedom, rotation on 3 axis and movement on x,y,z. The main problem with using glRotate is the gimabal lock issue, where if I rotate on one axis the next rotation is no longer on the global axis used by glRotate. (Using glGetFloatv to return the values of the MODELVIEW matrix does not work in Android). Using matrices the result of the first rotation gives a new axis for the second rotation. The only other solution I have read about uses quaternions, but those are then converted to matrices.

Someone can correct me if I am wrong about this, but as far as I know one of those two methods have to be used. I would love to have a simpler way to do it. I understand matrices at a minimum level. However once I start getting two or three sets of matrices, and their inversions, I just have a hard time wrapping my head around what is actually going on.

This topic is closed to new replies.

Advertisement