With the dot product this is really simple...

The dot product of two vectors is positive, if they "point in the same direction" (i.e. the angle between them is less than 90 degrees), it is zero if they are perpendicular to each other and negative if the angle between them is greater than 90 degrees.

So, you want to know if Ent1 is in front of Ent2 or behind. Just calculate the "view" vector of Ent2, that is a vector (say of length 1) pointing in front of Ent2. This can be done by two lines:

Code:

vec_Set(temp, vector(1,0,0));
vec_rotate(temp, ent2.pan);



Then define a vector pointing from ent2 to ent1. One line of code:

Code:

vec_diff(temp2, ent1.x, ent2.x);



Of course temp2 has to be defined first. ;-) Last, just check the dot product:

Code:

if (vec_dot(temp,temp2) > 0)
{ // Ent1 is in front of Ent2
...
}
else
{ // Ent1 is behind Ent2
...
}



And that's it. Three lines and then a test.

Regards,
Gnometech

Last edited by Gnometech; 08/19/07 15:12.

Download our playable Movement & Interaction Tutorial for 3DGS here:
http://www.puppenheim.org/MITutorial.zip