/* * 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/box.h" namespace RAYPP { const AXISBOX BOX::abox (VECTOR(0,0,0), VECTOR(1,1,1)); inline VECTOR BOX::Get_Normal (const VECTOR &Loc) const { VECTOR tmp = Trans.TransNormal (abox.Normal(Loc)); tmp.Normalize(); if (Inverted) tmp.Flip(); return tmp; } BOX::BOX (const VECTOR &lower, const VECTOR &higher) { Trans = Scaling_Transform (higher-lower); Trans.Add_Transform (Translation_Transform (lower)); } //virtual void BOX::Init () { if (initialized) return; initialized = true; } //virtual void BOX::Transform (const TRANSFORM &trans) { cni(); Trans.Add_Transform (trans); } //virtual AXISBOX BOX::BBox () const { ci(); AXISBOX Mybox (abox); Mybox.Transform (Trans); return Mybox; } //virtual bool BOX::Test (const GEOM_RAY &Ray, float8 &dist, bool &realhit) const { ci(); float8 d1, d2; GEOM_RAY tmpray = Trans.InvTransRay (Ray); realhit = true; if (!abox.Ray_in_Bounds (tmpray, d1, d2)) return false; if (d1>Ray.mindist) { dist=d1; return true; } if (d2Ray.mindist) { dist = tmpray.mindist; Normal = Get_Normal (tmpray.eval(dist)); return true; } if (tmpray.maxdist &Inter) const { ci(); GEOM_RAY tmpray = Trans.InvTransRay (Ray); if (abox.Clip_Ray (tmpray)) { if (tmpray.mindist>Ray.mindist) Inter.push_back (INTER (tmpray.mindist, Get_Normal (tmpray.evalmin()))); if (tmpray.maxdist