As far as I know the following code:
struct CVector
{
float x,y,z;
}
CVector calculateNormal(CVector vec[])
{
CVector vector1; // create a new vector
CVector vector2; // and another
CVector vector3; // one more...
vector1 = subtract(vec[0],vec[1]); // v1-v2
vector2 = subtract(vec[1],vec[2]); // v2-v3
// now get the cross product (length)
vector3 = crossProduct(vector1, vector2);
// get the square root of the length
float length = sqrt( (vector3.x*vector3.x) +
(vector3.y*vector3.y) +
(vector3.z*vector3.z)
);
// now calculate the normal of this triangle!
vector3.x /= length;
vector3.y /= length;
vector3.z /= length;
// return the Normal!
return vector3;
}
float dotProduct(CVector vec1, CVector vec2)
{
// (V1.x * V2.x + V1.y * V2.y + V1.z * V2.z)
return ( (vec1.x * vec2.x) + (vec1.y * vec2.y) + (vec1.z * vec2.z) );
}
bool planeCollision(CVector vec[], CVector point)
{
// vec[] is an array of vertices defining our triangle, point is a random point we are
// checking to see if it lies on our plane.
// ooooh this is an evil equation, very evil, forget learning it as its TOO EVIL!
CVector vector; // for our "plane" normal
vector = calculateNormal(vec); // calculate our "planes" normal
// calculate D from the plane equation
// D = dot product of our planes normal and a point we know is on that plane...
float D = -dotProduct(vector, point);
// now we have 4 very EVIL values, now we check them in the equation with the vertices
// of our random point (CVector point)
// simply return the value, in the main function we check by asking -
// is there a collision? true or false? easy
if( ((vector.x*point.x) + (vector.y*point.y) + (vector.z*point.z) + D) <= 0)
return true;
return false;
}
should produce me an answer.
OK I am to believe:
* get a normal of a triangle
* ''-D'' = the dot product of this triangle AND a point we know exists on the triangle such as the first corner vertice.
* with that we just then perform the Ax+By+Cz+D = 0 function and we get an answer.....
Basically I have two triangles, one kinda sideways the other not. I check the plane of the sideways one and the corner point of the user moved one too see if I ''intersect'' that plane of the sideways one. If so, it will go red.
But no, its still pretty colours. >8(
I call the test with this:
if( (planeCollision(triangle2,triangle1[0])) )
the two vectors I am playing with are two triangles of CVector structures:
CVector triangle1[3] = { {-1, 0, 0}, {1, 0, 0}, {0, 1, 0} };
CVector triangle2[3] = { {-4, 0, -1},{-4, 0, 1}, {-4, 1, 0} };
man...im stuck....help from some of you lesser newbies would be extremely appreciated!
CHEERS...
PS: at least im thoroughly learning about vector maths

Im just a beginner!!!
http://www.actsofgord.com