#### Archived

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

# ColDet and Lesson 23

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

## Recommended Posts

Just wondering if anybody have used ColDet (http://photoneffect.com/coldet/) collision detection library in lesson 23 or anything samekind FPS project. I''ve tried to make collision detection to my engine which is based on lesson 23, but with bad results. So if anyone can give some help or code snippet or anything, I would be thankful. -- YartZ

##### Share on other sites
i have tried this and have found for it not to work due to the code for calculating the normals not working properly. I still havent got it woking but have abandoned the project and started work on something else.

To draw the normals do

CVector center;

center = (vertex1 + vertex2 + vertex3) / 3;

glBegin(GL_LINES);
glVertex3f(center.x, center.y, center.z);
glVertex3f(center.x * 2, center.y * 2, center.z * 2);
glEnd();

##### Share on other sites
I would think something like, that player has a "model". In this case, quad or something and it walks with player. And when that quad hits the wall, player stops. I''m not sure about it, but this maybe could work if it''s done right.

-- YartZ

##### Share on other sites
The easiest way (and the way ive been performing collision detection) is by using ray -> plane intersections. All you need to do is project a ray from the player camera, and check it for intersections against the bounding boxes around the objects in your scene.

I won''t go into too much detail, but you could easily do something like this to see where the player _would_ intersect a defined plane, and 1) see if this point lies on your polygon and then 2) if the player is within a certain distance from the plane.

I define my rays as a parametric equation:
[Ray.x,Ray.y,Ray.z] = [CamPos.x,CamPos.y,CamPos.z] + t[DV.x,DV.y,DV.z]

thus:

Ray.x = CamPos.x + t(DV.x)
Ray.y = CamPos.y + t(DV.y)
Ray.z = CamPos.z + t(DV.z)

Where DV is representing a direction vector.
A plane, obviously, has the equation:
N.x(x) + N.y(y) + N.z(z) + D = 0

Where N is the normal, and (x,y,z) is any point lying on that plane, and D is a constant.
Firstly to find this constant, D, you will need to know a point lying on the plane (which is just a point lying on your polygon). Sub the point in for x,y & z to find the constant D.

Next you need to find where the ray intersects the plane:

N.x(Ray.x) + N.y(Ray.y) + N.z(Ray.z) + D = 0
N.x(CamPos.x+t(DV.x)) + N.y(CamPos.y+t(DV.y) + N.z(CamPos.z+t(DV.z)) = -D

t*[(N.x*DV.x)+(N.y*DV.y)+(N.z*DV.z)] = -D -(N.x*CamPos.x) -(N.y*CamPos.y) -(N.z*CamPos.z)

t = -(D +(N.x*CamPos.x) +(N.y*CamPos.y) +(N.z*CamPos.z)) / ((N.x*DV.x)+(N.y*DV.y)+(N.z*DV.z))

And finally by subing this found value for t into the ray equation, you can find the exact point at which the player will interect the plane, and from this point, you can find the distance between the player & that point to see if the game should stop the player from moving any further forward.

"You are just as irritating to me as an irrational term that accidentially creeps into your equation and cannot be factorized out."

##### Share on other sites
I''m sure that works, but i''m not quite sure did I understand it well. If you could implement that on lesson 10 or 23 and upload the code somewhere, it would be great.

-- YartZ

##### Share on other sites
Hi,

I''ve made a little example who use a detection collision function.

This function works with the lesson 23.

Tell me if it''s work.

Source code included.

========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/

##### Share on other sites
Thank you. I''ll try it out...

-- YartZ

##### Share on other sites
It works quite well. Just thinking how to get it work with strafing?

-- YartZ

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633298
• Total Posts
3011256
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!