www.pudn.com > Ray_Tracing_Materials.rar > Plane.cpp, change:2005-03-02,size:1133b


/* 
   File Name: 
 
      Plane.cpp 
 
   Created by: 
 
      Allen Sherrod (Programming Ace of www.UltimateGameProgramming.com). 
 
   Description: 
 
      This file has the source for the Plane class functions. 
*/ 
 
 
#include"Plane.h" 
#include<math.h> 


TraceResult Plane::Intersect(Ray &ray)
{ 
   // result will hold the result of the test if the ray hits this triangle. 
   TraceResult result;
   result.hit = false;

   float rayD = normal.DotProduct3(ray.direction);
   
   // If true then ray is parallel to the plane.  No intersection.
   if(fabs(rayD) < 0.00001f) return result;

   float originD = -(normal.DotProduct3(ray.origin) + d);
   
   float intersectDist = originD / rayD;
   
   // If less then 0, no intersection.  Behind ray origin.
   if(intersectDist < 0.001f) return result;
   
   // Else we have a hit.
   result.hit = true;
   result.distance = intersectDist;
   
   return result;
} 
 
 
CVector4 Plane::GetNormal()
{
   return normal;
} 
 
 
// Copyright February 2005 
// All Rights Reserved! 
// Allen Sherrod 
// ProgrammingAce@UltimateGameProgramming.com 
// www.UltimateGameProgramming.com