Hi,

The equation of the plane passing through the three points Va, Vb and Vc is:

V=Va + s (Vb-Va) + t (Vc-Va)

Where s and t are scalar.

The equation of the line passing through V1 and V2 is

V=V1 + r (V2-V1)

where r is a scalar.

So, put the two values equal lead us to 3 equations (one for x, one for y and one for z) and 3

unknowns (r, s, and t):

V1.x-Va.x = r (V2.x-V1.x) + s (Vb.x - Va.x) + t (Vc.x - Va.x)

V1.y-Va.y = r (V2.y-V1.y) + s (Vb.y - Va.y) + t (Vc.y - Va.y)

V1.z-Va.z = r (V2.z-V1.z) + s (Vb.z - Va.z) + t (Vc.z - Va.z)

so, you get r, s and t with your favourite algorithm to solve such a linear system.

If r is negative, when V1 is at the observer and V2 in front of the observer, then the wall is

behind the observer. So, r must be positive if you are interested to the ray (the semi infinite

line from the observer toward the front). Same thing for s and t, but in addition, we must have s+t

<= 1 to be in the triangle. If s<0, or t<0, or s+t>1, then the intersection point is outside the

triangle delimited by Va, Vb and Vc.

If you are interested in the intersection with a quad, solve for one of the triangle, and, assuming

the quad is a plane (no warping, the four points are in the same plane), then, if the "membership"

test fails, test the second triangle. Sure, you can optimize the second test, if you are sure that

the four points are coplanar, since the value for the scalar r would be the same, in that case, for

the second triangle than it was for the first triangle, and so, let you only to solve 2 eq with 2

unk. (s and t), for the second triangle... but only if you are really sure the four points are

really in the same plane.

Hoping it may help,

Vanderghast, Access MVP

Quote:

> Hi,

> I have used this newsgroup before and it was very

> helpful. I was wondering if anyone could help me with

> collision detection in DX8. I have come up with a couple

> of methods of my own, but they are not really up to

> scratch (i.e. uses trig, and only work 50% of the time). I

> also have looked on the internet, but most stuff is not

> approprate for DX8, or bypasses the problem. What I am

> aiming to do is find out if a line (from the players

> current position to the players destination), intersects

> with a wall (made from four points, each being the corner

> of the wall). Please, if anyone knows of a method, your

> help would be greatly appreciated,

> Thanks in advance,

> Tom