Quake 3 BSP and Collision Detection

Started by
14 comments, last by MigPosada 21 years, 7 months ago
Excuse me, I didn''t write well.

What I wanted to say was:

distance = DotProduct(-->SPHERECENTER<--,PlaneNormal) - PlaneDistance
If distance < -radius, the sphere is beyond the plane.
If -radius <= distance <= radius, the sphere is touching the plane.

That''s what I am using in my code, and it seems to be working.

But why???, if you said I need to use a vector from a point in the plane to the sphere, not the sphere''s center directly.

In the other way, I can''t test all the vertices of the sphere against the brush''s planes, just because I don''t have any sphere vertex, just its center and radius.
Advertisement
Excuse me, I didn''t write well.

What I wanted to say was:

distance = DotProduct(-->SPHERECENTER<--,PlaneNormal) - PlaneDistance
If distance < -radius, the sphere is beyond the plane.
If -radius <= distance <= radius, the sphere is touching the plane.

That''s what I am using in my code, and it seems to be working.

But why???, if you said I need to use a vector from a point in the plane to the sphere, not the sphere''s center directly.

In the other way, I can''t test all the vertices of the sphere against the brush''s planes, just because I don''t have any sphere vertex, just its center and radius.
Computer Programming is Magic! Hold the Power!
hey, it''s the french anonymous poster...thanx for the advice but can you write your code to find the brushes to test, because i''ve some trouble with it...
Do you already know how BSP trees works?
If you do, then just use the bounding boxes of each node and leaf to get the brushes you need to test against.
Computer Programming is Magic! Hold the Power!
quote:Original post by MigPosada
Excuse me, I didn''t write well.

What I wanted to say was:

distance = DotProduct(-->SPHERECENTER<--,PlaneNormal) - PlaneDistance
If distance < -radius, the sphere is beyond the plane.
If -radius <= distance <= radius, the sphere is touching the plane.


That makes sence, sorry, I wasn''t trying to be uptight, I just didn''t understand why you were using the radius.

quote:Original post by MigPosada
That''s what I am using in my code, and it seems to be working.

But why???, if you said I need to use a vector from a point in the plane to the sphere, not the sphere''s center directly.


Here''s why it works and here''s why you need to correct it. The Plane''s normal can be used on any point on the plane. However, the Normal itself is relative to the plane as local units. What I''m trying to say is that the Vector measures direction. This direction can be measured from any point, but is represented as extending from the (0,0,0) origin. It is represented as extending from this point, any point on the plane is translated to the origin to do this calculation and all we are concerned about is the direction. You can move vectors to any point in space, as long as you keep them pointing in the same direction and same length. The normal is relative to the plane.

Your radius is also measured from the origin, but it is not relative to the plane like the normal vector is. It is relative to the origin. If you drew a vector from the origin to the sphere''s center, then moved it''s vector to be with repect to the plane, it would actually shift the sphere closer or farther to the plane, depending on the plane''s distance from the origin. You have to measure the sphere from plane to get the distance with respect to the plane. After you get this relationship correct, you can move the vector anywhere, and it would represent the direction and displacement the sphere is from the plane.

Your test is passing because your plane runs through or close to the origin. Try using a plane whose equation is y = 20 and then try the calculation. You should see some erradict behavior.
Oh!!, I know understand everything

Thank you very much, I''ll fix my code right now.
Computer Programming is Magic! Hold the Power!

This topic is closed to new replies.

Advertisement