Advertisement

Newbie: How to detect polygon positions

Started by February 18, 2001 03:54 PM
4 comments, last by JohnElectron 23 years, 9 months ago
I''m a newbie, and I''ve started building my first 3D engine (see my web page). Currently I can still walk through walls. What is the best way to detect walls and block walking through them? I started out very basically by making a small world-editor that creates 3D cubes based on quads. The 3D engine allows you to walk through it. Best regards John Electron
I''m sorry my web-page is still in Dutch. I really have to start working on an international page....
Advertisement
That might not be as easy as you think, it involves collision detection and response, which is a very elaborate topic, you should check out www.flipcode.com where they have an excellent tutorial on collision detection, but if you really are a newbie, I would''nt recommend starting with something that hard...
I will however tell you that it is based on sphere-plane intersection routines, a lot of math is involved.
Of, om het in het nederlands te zeggen, collision detection is niet direkt iets gemakkelijk om zomaar mee te beginnen, maar als je het aandurft, veel succes

Een helpende Belg
Ok, collision detection might be quite hard....
But I cannot imagine it would be too hard to detect me bumping into a wall?!?! I only want to stay inside the space I created.

greetings
JonhE
What you need to do is cast a ray from your viewpoint along your velocity vector, then check if this ray intersects with any of the planes made up by the polygons in your world. Then, if you crossed a plane, you need to find the ray-plane intersection point and check wether or not this is locate within the polygon belonging to the plane. If this is so, you have collided with a poly in your world.
Now, how do you know a point is inside a polygon? Wel, you construct a plane for each side of your poly and the viewpoint, and then check wether the intersection point is on the inside of each of these planes.
BTW, if you are using triangles, there are other ways of checking if a point is inside a poly

Have fun m8

Edited by - Flous on February 19, 2001 7:49:10 AM
If you are just trying to stay inside a square or rectangular space then it is easy. Let''s say x is your x-coordinate and z is your z-coordinate, and the size of the box is 10*10. Just say that if(x>5) z=5;
if(x<-5) z=-5;
if(z>5) z=5;
if(z>-5) z=-5;

This topic is closed to new replies.

Advertisement