Collision det. in opengl help needed

Started by
2 comments, last by Quizzah 23 years, 4 months ago
I am stuck at one of those points where my brain hurts. It is not that I do not understand collision detection, it is cus I have hit a wall. I have written my own collision detection that uses bounding boxes based on the radius of the objects (the inner object and the world object (a box)). Basically, the inner ball knows that it has collided with the larger box outside when either the radius of the world minus the increments (x,y, or z) have crossed the radius of the larger "world" box. I''m using gltranslate(,,) to move them. When a collision is detected, I move the increment of the object in a new direction from which it just collided. This is the problem, my collision works fine for one object bouncing around within a box. It however, is not so simple for a more complex world. I am wanting to have collision detection in a world with many objects (not one). The reason that I am stumped is that I do not know how to get the x,y,z points of objects from opengl objects. I can say create this box with a radius of .5, but how can I know the x,y,z coordinates from the object at all times? I want to be able to go down a list of my objects in a world that are close to the "character" and check for collisions. Without the radius like I am doing. Can anyone out there help explain a solution using opengl(with glut) with c++. I''m lost and pulling my hair out. Code is easy when you know what it is doing.
---------------------------------------Code is easy when you know what it is doing.
Advertisement
Translate the box with coordinates the same way you do with your character. If your just drawing a box at the base matrix level, that just means that your object is at 0,0,0. If you want to check for collision of one object to another, all you have to do is subtract the character pos from the object pos, and now you have the characters local pos relative to the object pos. Now check and see if the character lies withing the object.
For a start, I recommend putting your objects into a class if you haven''t already. Make a glBall class or whatever, and have the class contain three float variables: Xpos, Ypos, and Zpos to track the object''s coordinates. To keep things simple have these represent the actual screen coordinates that you will render the object at. (When you expand your world you will probably want some sort of world coordinate system and a function to convert from world coordinates to screen coordinates) Keep a list of objects that a collision can occur with, then test each of them with the method WhatEver described.

This is about the simplest solution possible, and definitely isn''t the optimal way to go, but you have to start somewhere :-)
Thanks for the info.. I guess I am on my way to start making my own 3d engine.. ; )

---------------------------------------
Code is easy when you know what it is doing.
---------------------------------------Code is easy when you know what it is doing.

This topic is closed to new replies.

Advertisement