00001 #include "stdafx.h" 00002 #include "plane.h" 00003 00004 Plane::Plane() { 00005 normal = VECTOR(0,0,0); 00006 point = VECTOR(0,0,0); 00007 dist = 0.0; 00008 } 00009 00010 Plane::Plane(VECTOR n, VECTOR p) { 00011 normal = n; 00012 point = p; 00013 dist = -normal.dot(point); 00014 } 00015 00016 float 00017 Plane::Distance(VECTOR x) { 00018 VECTOR help = x - point; 00019 return fabsf(normal.dot(point)); 00020 } 00021 00022 bool 00023 Plane::Intersection(VECTOR ray_point, VECTOR ray_dir, VECTOR *res) { 00024 float dir_norm = ray_dir.dot(normal); 00025 if (fabsf(dir_norm) < 0.001) return false; // parallel 00026 float t = -(ray_point.dot(normal)+dist)/(dir_norm); 00027 *res = ray_point + t*ray_dir; 00028 return true; 00029 }