/* * 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. */ /* Ray++ demo program This is a simple scene containing a white sphere and coloured lightsources. The image is written to a Targa file */ // first, include all the headers of the classes we need #include "kernel/globals.h" #include "kernel/handle.h" #include "worlds/scene.h" #include "renderers/raytracer.h" #include "outputs/tga_output.h" #include "shapes/sphere.h" #include "surfaces/matte.h" #include "objects/simple_object.h" #include "lights/pointlight.h" #include "cameras/std_camera.h" int main () { using namespace RAYPP; // define an output handle HANDLE Output; // create an output object. This one produces a 640x480 Targafile // with the name "first.tga" Output = Cnew TGA_OUTPUT (640, 480, "first.tga"); Output->Init(); // create a raytracer object. This is a child of the class RENDERER RAYTRACER *Raytracer = Cnew RAYTRACER; // create a scene object. This is a child of the class WORLD SCENE *Scn = Cnew SCENE; // create a camera, which sits at <0,0.75,-3.75> and looks at <0,0,0>. // By default, the sky vector is <0,1,0> and the field of view is // 45x34 degrees. // When created, add the camera to the scene. Raytracer->Add (Cnew STD_CAMERA (VECTOR (0,0.75,-3.75), VECTOR (0,0,0))); SIMPLE_OBJECT *obj; uint4 Priority = 1; // create an object to put into the scene obj = Cnew SIMPLE_OBJECT; // tell the object that its shape is a sphere (center at <0,0,0>, radius is 1) obj->Set_Shape (Cnew SPHERE); // tell the object that its surface is a matte surface with Ka=0.2, Kd=1.0 // and a colour of <1,1,1> (white) obj->Set_Surface (Cnew MATTE (0.2, 1.0, COLOUR(1,1,1))); // set the object's priority. You don't need to worry about that now. obj->Set_Priority (Priority); // Add the object to the scene Scn->Add (obj); // add some lightsources to the scene // the first lightsource sits at <10,30,-20> and has a colour of <800,0,0>. // the large values for the colour are needed because the light intensity // drops with the square of the distance. Scn->Add (Cnew POINTLIGHT (VECTOR (10,30,-20), COLOUR (800,0,0))); Scn->Add (Cnew POINTLIGHT (VECTOR (0,30,0), COLOUR (0,800,0))); Scn->Add (Cnew POINTLIGHT (VECTOR (-10,-20,-40), COLOUR (0,0,800))); // initialize the world handle with our new scene World = Scn; // initialize the world; this also initializes all subobjects // (that means everything we added to the scene) World->Init(); Renderer = Raytracer; Renderer->Init(); // tell the output to make an image Output->Render(); // no need to deallocate anything, the destructors take care of all // dynamically allocated memory. }