Jump to content
  • Advertisement
Sign in to follow this  
ajm113

Why is it hard to find the a very basic collison tutorial for 3D games?

This topic is 3991 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, all that I am looking for is a very good tutorial on a very basic collision tutorial in OpenGL. The only thing I want to do is create a room that a player can jump around in. I have the player crouching and jumping, but I just want to do is not allow the user to go on after a amount of a distance. Like the player was in a squared room. Like the NeHe World demo. Yes and I do know OpenGL is ONLY a graphics API. So spare your hands from carpal tunnel. Can someone write me something of my description to do this and be detailed about how it works? I am not that well with algebra. :(

Share this post


Link to post
Share on other sites
Advertisement
The absolutely simplest way to put the player in a square box of a room, would be to simply have the walls align with the x and y directions of the world.
Which means all you'd have to do is a simple check of the player's coordinates:
if(player.x>200)player.x=200
if(player.x<-200)player.x=-200
and so on for y coordinate
This kind of thing is suitable for say, a game of pong or pinball, where you need to keep the object inside a limited playing field.

Getting more generalized though, if you wanted the walls of the room to be more varied than just along the x and y directions, you'd probably represent them mathematically as Planes, and calculate the line intersection of the player's motion path with the plane of each wall to decide where/if he hits any of them.
Lookup 'Line to Plane Intersection' the formulas are common.
But this overlooks the fact that a plane is infinite, while the walls of your room probably are limited in size. For a simple cube of a room this wont matter, but once you say... add a doorway and hall to one of the walls, where the walls are no longer convex, this is an issue.

At that stage, you'll want to graduate from line/plane intersection, to line/polygon intersection -look this up after you've figured out basic planes.

Much farther down along the line you'll need to learn about collision culling -needing a system to not just check collisions, but one to decide when to avoid checking in the first place.

I'll also mention, that rather than line/plane, line/polygon, you might simply collide the player as a sphere each loop, ignoring the path he took between steps. This is simpler, but has real problems... but if youre really having trouble with math this might be a start...

What else?
well, you seem to mention OpenGL as your current...context...; assuming you render the walls as quads or something, a collision plane can be calculated using 3 of the verticies... 3 points define a plane



I like this column: http://www.flipcode.com/archives/Building_a_3D_Portal_Engine-Issue_01_Introduction.shtml


Share this post


Link to post
Share on other sites
Quote:

Why is it hard to find the a very basic collison tutorial for 3D games?

Because collision detection in 3d is anything but simple. You have a third dimension to increase the complexity of the maths, you have a larger variety of shapes to be tested, and the rest of the application will be more complicated as well, making it hard to write a "simple" tutorial.

I often get asked how to write a simple application in 3d. I always recommend your first game be a flight simulator, where the only primitives you use are trimeshes and spheres. Would you like an explanation of how this collision system will work?


Share this post


Link to post
Share on other sites
Actually I was going to go for a flight game, and thought that would be easy, but I also am still kinda jumping around what to make. But a fight game mite not be bad to try out.

I can't really say how it would work since I never worked with collision detection for a game before. So I thought something like a camera radius and what not would be easy to try out.

Share this post


Link to post
Share on other sites
The easiest (though not by any means the best) 3d collision detection scheme (for something like a flight sim) is to use collision spheres. Each object basically has its position, and an invisible sphere around it representing the edge of its collision zone (the data for that is simply a radius value). To check for collisions between two objects, determine the distance between their coordinate locations (the distance formula comes in handy). If this distance is less than or equal to the sum of their collision radii, they have collided.

This is a very easily implemented and very cheap scheme. There are drawbacks, though. Among the worst is that most objects will not be even nearly spherical. This means that there will be a lot of unoccupied space within the collision sphere, so collisions will often be detected even when the models aren't quite touching eachother. A solution to this (again, using the collision sphere method) is to break up each object into a series of smaller collision zones, each represented by its own collision sphere (and associated location and radius). This will yield a somewhat more accurate detection, at the expense of somewhat increased complexity and increased calculation time.

Good Luck!

Share this post


Link to post
Share on other sites
this is as simple as I can put it...

It's using the point-distance-to-triangle function (from D. Eberly) to check if there are triangles withing a given distance from the centre of a 'character'. If there is, the charcter is pushed back to an amount so that the triangle is then at the distance threshold from the centre of the character.

There are 4 main.cpp file. They go up in difficulty. I've also added crude collision response. You need to understand basic vector maths. The distance function itself is rather difficult to explain, but It's easy to provide a similar, but less efficeint alternative.

If you want an article, you can look at this. It's a bit more advanced, and imo, it's not really reliable. I have a couple of other algorithms, but they would require an article of some kind.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!