Archived

This topic is now archived and is closed to further replies.

spaceleader

a game

Recommended Posts

hi im a newbie trying to make my first graphic game using OpenGL, i have a couple of question i would like to ask. when i draw two model, and try to move one of them using the keyboard BOTH of them move.......how do you make only one model move and the other stay still? my second question is when the model touch each other, they just PASS through each other, how can u make them react when one touches another?

Share this post


Link to post
Share on other sites
Excellent questions.

I''m sort of new at OpenGL, but I''ve been doing Direct3D for three years. With that, you had to specify your own transformation matrices.

Anyway. I think in your case, you''re not loading an identity matrix for the ''GL_MODELVIEW'' transformation matrix. Try this before you render each object:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Check out a math book about matrices and how they are used for translation, rotation, and scaling.

About collision detection (that''s the term for it), there are several options. Depending on the shape of the objects, you could use bounding spheres. That is, assume each of the objects is sphere-shaped and give them an appropriate radius. During each test for collisions, determine the distance from the centers and assume a collision happened when the sum of the radii of the two objects is greater than the distance between the two centers (you could be slick and square the sum of the radii and compare that to square of the distance so you don''t have to call sqrt() but that may be trivial at this point in time).

Hope that works for you.

Share this post


Link to post
Share on other sites
I remember back in the day, when I was where you are. By model, I assume you mean primative. So call glLoadIdentity() after the MOVED one and before the one you want to stay still. I assume you''re talking about glTranslatef(...) commands for movement. Also, collision detection, that is a BIG topic. Check it out by searching for it or looking at nehe''s tut on the topic. If I have misunderstood your requests, please restate in more detail.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites
Funny, by the time I had finished typing, someone else had posted. Heh... Yea, his collision detection meathod works for basic objects of similar distance from all points around their center. For more complex objects however, I suggest you do some research on it.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites