Advertisement

Newbie Needs help :(3d collsion question

Started by April 07, 2002 05:10 AM
4 comments, last by macgeorge 22 years, 10 months ago
Hi everyone, I''ve been coding for a relatively short time and your sight has inspired me to learn more especially about opengl!!. I was wondering if you could help me out with a small problem I''m having. I''ve been working on writing a 3d game engine... I was inspired by tutorial 10 (3d world) on nehe''s site. And thought I''d add collision detection... sound music objects(static and dynamic) and the ability to clreate the world from a text file. with the text file symbolising an overhead view with diffrent textures represented by diffrent characters. ie. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA A A A A AAAAAAAAAA AAAAAAAAAAAAAAAAAA A A I''ve just started so far I''ve got the world loading from the file and I''ve implemented some crude collision detection. My problem lies with the collision detection . I''m using a bounding box technique. For each object read in I store a - Maximum X value - Minimum X value - Maximum Z value - Minimum Z value which is a Glfloat. Then each frame I check to see if the proposed posiotn to move to is within these values If so I don''t move else I move. Simple. . This works fine when walking straight up to a wall or object the problem is when I look around( rotate) . The world rotates around me(I think) and therefore if I walk backwards into a wall or turn around when close to a wall I end up in it... Do I need to rebuild my bounding boxes everyframe. Is there some simple logic I''m missing???? Any-help will be very much appreciated!!!!!. Once again thanks for the great site ------------------------ what about y20k?
------------------------what about y20k?
Hi,

If you have set up your bounding box correctly then changing the camera''s orientation shouldn''t affect things. Remember that your bounding box and camera coords are (should be) world co-ordinates - they will be the same regardless of the orientation of the camera.

I find a useful debugging technique for this sort of thing is to actually draw the bounding box as a wireframe, then you can ensure that it is set up correctly.


Cheers

Keef


-----------------------
glDisable(WORK);
glEnable(GL_CODING);
-----------------------Current Project: The Chromatic Game Engine
Advertisement
Thanks for the reply Keef, its appreciated.
I Don''t think the problem is with my bounding boxes. I Think the problem is with the way I''m moving around my world. I;m using gltranslate and glrotate. I haven''t set up a camera class as of yet. So when I rotate around My Xposition and Zposition variables aren''t changing which is fair enough and the bounding box positions aren''t changing either, so If I go right up to a wall,but don''t touch it,face it, then rotate, the wall will rotate infront of me..... Sorry I''m new to this thanks...
------------------------what about y20k?
Hmm Ok,

Sounds like the order of translations/rotations are wrong. You need to rotate before you translate

It seems you need to invest some time in a camera class/library. Believe me its worth sorting this our before you go any further.

I''d have a look at some matrix tutorials (matrices are the easiest way of getting true 3 degrees of freedom movement)

Cheers

Keef












-----------------------
glDisable(WORK);
glEnable(GL_CODING);
-----------------------Current Project: The Chromatic Game Engine
Thanks Again Keef,
I agree I think the first thing I should do is setup a camera class. That way I will be moving the camera( my virtual head ) instead of the world around me.. true????
regards,
Marc
PS - Nice to see a fellow Aussie onboard.



------------------------
what about y20k?
------------------------what about y20k?

No worries!

OpenGL display things from the camera''s point of view by applying the model view matrix to all vertices that you send it. The model view matrix is the transformation matrix that converts your model''s world coords to the camera''s view coords.

This means that under the hood all your model co-ordinates are getting moved by the modelview matrix - OpenGL is moving the world so that it aligns with the camera''s point of view. This is nice, as you don''t have to specifically move all the items in your scene, but it can be confusing if you don''t know what''s going on.

So although conceptually you are moving the camera around, in reality OpenGL translates this into moving the world to match the camera''s point of view. This can get confusing when you combine operations, as you may need to do them in the reverse order from what seems logical to get them to work.

There are quite a few ways to do a camera class btw. The method I prefer is for your camera class to maintain its own version of the model view matrix, which you load into OpenGL''s modelview matrix when you want to set the camera position.

I store all the component matrices (x rotation, y rotation, z rotation, translation) separately and combine them (by matrix multiplication) to get the model view matrix. This is not as expensive as it sounds because you only need to do it when the camera moves. When you move the camera you just need to update the appropriate component matrix and recombine them.

There are several advantages to this method, the main one being that you can easily extract the individual matrices so that you can billboard in one or more directions.
You can also easily implement relative camera rotation (where you rotate around the camera''s local x,y,z axes rather than the world axes.

Hope this helps

Keef

-----------------------
glDisable(WORK);
glEnable(GL_CODING);
-----------------------Current Project: The Chromatic Game Engine

This topic is closed to new replies.

Advertisement