/* * 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. */ /*! \file spotlight.cxx \brief Implementation of the SPOTLIGHT class */ /* THIS FILE is copyright (c) 1999 by Ugo Varetto - varetto@computer.org */ #include "lights/spotlight.h" namespace RAYPP { extern HANDLE World; // Constructors SPOTLIGHT::SPOTLIGHT () : Colour (1,1,1), Location (0,0,0), To (0,0,1), Dir(0,0,1), Exp(1), CutOff(0) { Attenuation[0]=0; Attenuation[1]=0; Attenuation[2]=1.0; } SPOTLIGHT::SPOTLIGHT (const VECTOR &Loc,const VECTOR &to, const COLOUR &Col, const float8 &e, const float8 &c) : Colour (Col), Location (Loc), To(to), Exp(e) { Attenuation[0]=0; Attenuation[1]=0; Attenuation[2]=1.0; CutOff= cos(radians(c)); Dir=(To - Location).Norm(); } //virtual void SPOTLIGHT::Init () { if (initialized) return; World->Get_Surrounding_Volume (Location, MyVolume); initialized = true; } //virtual void SPOTLIGHT::Transform (const TRANSFORM &trans) { cni(); Set_FromTo(trans.TransPoint (Location),trans.TransPoint (To)); } //virtual void SPOTLIGHT::Cast_Light (const VECTOR &Pos, LIGHT_ARRAY &Arr) const { ci(); VECTOR v = (Pos - Location); float8 d1 = v.Length(); float8 d2 = d1*d1; VECTOR L = v.Norm(); float8 cosangle = Dot(L,Dir); float8 maxval= max(cosangle-CutOff,0.0); float8 att = pow(maxval,Exp)/ (d2*Attenuation[2]+d1*Attenuation[1]+Attenuation[0]); COLOUR Col = Colour*att; if (!Col.TooSmall()) Arr.push_back (LIGHT_ENTRY (Col, Location, MyVolume)); } void SPOTLIGHT::Set_Colour (const COLOUR &new_col) { cni(); Colour = new_col; } //virtual void SPOTLIGHT::Set_Location (const VECTOR &new_loc) { cni(); Location = new_loc; Dir=(To-Location).Norm(); } //virtual void SPOTLIGHT::Set_To (const VECTOR &new_to) { cni(); To = new_to; Dir=(To-Location).Norm(); } void SPOTLIGHT::Set_Exp (const float8 new_exp) { cni(); Exp = new_exp; } //virtual void SPOTLIGHT::Set_FromTo (const VECTOR &new_loc,const VECTOR &new_to) { cni(); Location = new_loc; To = new_to; Dir=(To-Location).Norm(); } void SPOTLIGHT::Set_CutOff(const float8 c) { cni(); CutOff=cos(radians(c)); } void SPOTLIGHT::Set_Attenuation(const float8 a2,const float8 a1, const float8 a0) { Attenuation[0]=a0; Attenuation[1]=a1; Attenuation[2]=a2; } } // namespace RAYPP