Jump to content
  • Advertisement

Archived

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

YartZ

ColDet and Lesson 23

This topic is 6147 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Hi,

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

This function works with the lesson 23.

"Download" section on my site.

Tell me if it''s work.

Source code included.

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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!