/* * Ray++ - Object-oriented ray tracing library * Copyright (C) 1998-2001 Martin Reinecke and others. * See the AUTHORS file for more information. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * See the README file for more information. */ #include "shapes/plane.h" namespace RAYPP { inline bool PLANE::Find_Intersection (const GEOM_RAY &Ray, float8 &dist) const { float8 testval = Dot (Normal_Vector, Ray.dir); if (abs (testval) < Small_float8) return false; dist = (- Dot (Normal_Vector, Ray.start) + Distance) / testval; return ((dist > Ray.mindist) && (dist < Ray.maxdist)); } PLANE::PLANE (const VECTOR &Norm, float8 dist) : Normal_Vector (Norm), Distance (dist) {} //virtual void PLANE::Transform (const TRANSFORM &trans) { cni(); VECTOR v = Normal_Vector*Distance; Normal_Vector = (trans.TransDirection (Normal_Vector)).Norm(); Distance = Dot (trans.TransPoint (v), Normal_Vector); } //virtual AXISBOX PLANE::BBox () const { ci(); return AXISBOX (VECTOR (-Huge_float8, -Huge_float8, -Huge_float8), VECTOR (Huge_float8, Huge_float8, Huge_float8)); } //virtual bool PLANE::Test (const GEOM_RAY &Ray, float8 &dist, bool &realhit) const { ci(); realhit = true; return Find_Intersection (Ray, dist); } //virtual bool PLANE::Inside (const VECTOR &Loc) const { ci(); if (Dot (Normal_Vector, Loc) > Distance) return Inverted; return (!Inverted); } //virtual bool PLANE::Intersect (const GEOM_RAY &Ray, float8 &dist, VECTOR &Normal) const { ci(); Normal = Normal_Vector; if (Inverted) Normal.Flip(); return Find_Intersection (Ray, dist); } //virtual void PLANE::All_Intersections (const GEOM_RAY &Ray, vector &Inter) const { ci(); float8 depth; if (Find_Intersection (Ray, depth)) { VECTOR tmp = Normal_Vector; if (Inverted) tmp.Flip(); Inter.push_back (INTER (depth, tmp)); } } } // namespace RAYPP