/* * 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/clip.h" namespace RAYPP { //virtual void CLIP::Init () { if (initialized) return; if (!Clipping) error ("CLIP: no clipping shape"); if (!Clipped) error ("CLIP: no shape to clip"); Clipping->Init(); if (!Clipping->Has_Inside()) error ("CLIP: clipping shape must have an inside"); Clipped->Init(); if (Clipping->Inside_in_BBox()) Mybox = Intersection (Clipping->BBox(), Clipped->BBox()); else Mybox = Clipped->BBox(); initialized = true; } //virtual void CLIP::Deinit () { if (!initialized) return; Clipping->Deinit(); Clipped ->Deinit(); initialized = false; } //virtual void CLIP::Transform (const TRANSFORM &trans) { cni(); if (Clipping) Clipping->Transform (trans); if (Clipped) Clipped->Transform (trans); } //virtual AXISBOX CLIP::BBox () const { ci(); return Mybox; } //virtual bool CLIP::Test (const GEOM_RAY &Ray, float8 &dist, bool &realhit) const { ci(); GEOM_RAY Local_Ray = Ray; if (!Mybox.Clip_Ray (Local_Ray)) return false; realhit = false; bool dummy; return Clipped->Test (Local_Ray, dist, dummy); } //virtual bool CLIP::Intersect (const GEOM_RAY &Ray, float8 &dist, VECTOR &Normal) const { ci(); vector myInters; bool found = false; dist = Ray.maxdist; Clipped->All_Intersections (Ray, myInters); for (uint2 m=0; mInside (Ray.eval(myInters[m].first))) { found = true; Normal = myInters[m].second; dist = myInters[m].first; } } } return found; } //virtual void CLIP::All_Intersections (const GEOM_RAY &Ray, vector &Inter) const { ci(); vector myInters; Clipped->All_Intersections (Ray, myInters); for (uint2 m=0; mInside (Ray.eval(myInters[m].first))) Inter.push_back (myInters[m]); } } void CLIP::Set_Clipping (const HANDLE &Clpng) { cni(); Clipping = Clpng; } void CLIP::Set_Clipped (const HANDLE &Clpd) { cni(); Clipped = Clpd; } } // namespace RAYPP