/* * 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 spot.cxx Test file for the SPOTLIGHT class */ /* File written by Ugo Varetto - varetto@computer.org for testing the SPOTLIGHT class. */ #include "kernel/globals.h" #include "kernel/handle.h" #include "worlds/scene.h" #include "renderers/raytracer.h" #include "outputs/tga_output.h" #include "shapes/implicit.h" #include "shapes/plane.h" #include "surfaces/matte.h" #include "surfaces/phong.h" #include "objects/simple_object.h" #include "lights/pointlight.h" #include "cameras/std_camera.h" #include "lights/spotlight.h" namespace RAYPP { class Dens1: public IMPLICIT::DENSFUNC { public: float8 Density (const VECTOR &Loc) const { float8 length=Loc.Length(); float8 theta =acos(Loc.y/length); return (1-length-0.1*sin(15*theta)); } VECTOR Maxgrad () const { return VECTOR(4,4,4); } VECTOR Mingrad () const { return VECTOR(-4,-4,-4); } }; } // namespace RAYPP int main () { using namespace RAYPP; HANDLE Output; Output = Cnew TGA_OUTPUT (640, 480, "spot.tga"); Output->Init(); RAYTRACER *Raytracer = Cnew RAYTRACER; SCENE *Scn = Cnew SCENE; Raytracer->Add (Cnew STD_CAMERA (VECTOR (3,4,-12), VECTOR (0,0,0))); SIMPLE_OBJECT *obj; uint4 Priority = 1; IMPLICIT *imp=Cnew IMPLICIT; imp->Set_Minmax(AXISBOX(VECTOR(-1.11,-1.11,-1.11),VECTOR(1.11,1.11,1.11))); imp->Set_Densfunc(Cnew Dens1); obj = Cnew SIMPLE_OBJECT; obj->Set_Shape (imp); obj->Set_Surface (Cnew PHONG (0.2, 0.8, 0.6,0,0,50, COLOUR(1.0,0.5,0.8))); obj->Set_Priority (Priority); Scn->Add (obj); obj = Cnew SIMPLE_OBJECT; obj->Set_Shape (Cnew PLANE); obj->Translate(VECTOR(0,-2,0)); obj->Set_Surface (Cnew MATTE (0.2, 1.0, COLOUR(1,1,1))); obj->Set_Priority (Priority); Scn->Add (obj); Scn->Add (Cnew POINTLIGHT (VECTOR (0,6,-10), COLOUR (80,80,80))); //// // Create a SPOTLIGHT at position (0,5,0) looking at (0,0,0), // with a 0.5 radial attenuation exponent and a 25 degrees angle // SPOTLIGHT *spot=Cnew SPOTLIGHT( VECTOR (0,5,0),VECTOR(0,0,0),COLOUR (150,50,50),.5,25); // Add spot to scene Scn->Add (spot); //// World = Scn; World->Init(); Renderer = Raytracer; Renderer->Init(); Output->Render(); }