00001 #include <windows.h>
00002 #include "plane.h"
00003 #include "locmath.h"
00004 #include "mmgr.h"
00005
00006 PLANE::PLANE()
00007 {
00008 }
00009
00010 PLANE::~PLANE()
00011 {
00012 }
00013
00014 VECTOR GetEdgeIntersection(VECTOR point0, VECTOR point1, PLANE plane, VECTOR pointOnPlane)
00015 {
00016 VECTOR planeNormal, intersection, temp;
00017 float numerator, denominator, t;
00018
00019
00020 planeNormal.x = plane.nx;
00021 planeNormal.y = plane.ny;
00022 planeNormal.z = plane.nz;
00023
00024
00025
00026
00027
00028
00029 temp.x = pointOnPlane.x - point0.x;
00030 temp.y = pointOnPlane.y - point0.y;
00031 temp.z = pointOnPlane.z - point0.z;
00032 numerator = DotProduct(planeNormal, temp);
00033
00034
00035 temp.x = point1.x - point0.x;
00036 temp.y = point1.y - point0.y;
00037 temp.z = point1.z - point0.z;
00038 denominator = DotProduct(planeNormal, temp);
00039
00040 if (denominator)
00041 t = numerator / denominator;
00042 else
00043 t = 0.0;
00044
00045 intersection.x = point0.x + temp.x * t;
00046 intersection.y = point0.y + temp.y * t;
00047 intersection.z = point0.z + temp.z * t;
00048
00049 return intersection;
00050 }
00051