/* * 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 #include "kernel/globals.h" #include "kernel/handle.h" #include "worlds/scene.h" #include "renderers/raytracer.h" #include "outputs/tga_output.h" #include "shapes/cylinder.h" #include "shapes/plane.h" #include "shapes/sphere.h" #include "shapes/csg_shape.h" #include "surfaces/matte.h" #include "surfaces/phong.h" #include "objects/simple_object.h" #include "lights/pointlight.h" #include "lights/ambient_light.h" #include "cameras/std_camera.h" #include "worlds/hmakers/pov_hmaker.h" #include "volumes/clear_glass.h" #include "kernel/bstream.h" namespace RAYPP { SIMPLE_OBJECT *make_yellow_cross() { CSG_SHAPE *cross = Cnew CSG_SHAPE (UNION); SOLID_SHAPE *cyl; cyl = Cnew CYLINDER; cyl->Translate(VECTOR(0, -0.5, 0)); cyl->Scale(VECTOR(3, 20, 3)); cross->Add (cyl); cyl = Cnew CYLINDER; cyl->Translate(VECTOR(0, -0.5, 0)); cyl->Scale(VECTOR(3, 20, 3)); cyl->Rotate(VECTOR(0, 0, 90)); cross->Add (cyl); cross->Add (Cnew SPHERE(VECTOR(0,10,0), 3)); cross->Add (Cnew SPHERE(VECTOR(0,-10,0), 3)); cross->Add (Cnew SPHERE(VECTOR(10,0,0), 3)); cross->Add (Cnew SPHERE(VECTOR(-10,0,0), 3)); HANDLE Surf2 = Cnew PHONG (0.5, 0.5, 0.8, 0.0, 0.0, 30, COLOUR(1.0,0.7,0.0)); SIMPLE_OBJECT *obj = Cnew SIMPLE_OBJECT; obj->Set_Shape (cross); obj->Scale(VECTOR(0.55,0.55,0.55)); obj->Set_Surface (Surf2); return obj; } } // namespace RAYPP int main () { using namespace RAYPP; HANDLE Output; Output = Cnew TGA_OUTPUT (640, 480, "logo.tga"); Output->Init(); SCENE *Scn = Cnew SCENE; RAYTRACER *Raytracer = Cnew RAYTRACER; Raytracer->Add (Cnew STD_CAMERA (VECTOR (0,0,-120), VECTOR (0,0,0))); SIMPLE_OBJECT *obj; uint4 Priority = 1; byte logo[100][60]; int x, y; float4 pixel; ifstream infile ("logo.raw", ios::in | ios::binary); if (!infile) error ("Could not open file 'logo.raw'."); bistream binfile (infile); for (y=0; y<60; y++) for (x=0; x<100; x++) binfile >> logo[x][y]; HANDLE Surf = Cnew PHONG (0.1, 0.5, 1.0, 0.0, 0.0, 30, COLOUR(0.1,0.2,1.0)); for (y=0; y<60; y+=3) for (x=(y/3)%3; x<99; x+=3) { if (logo[x][y] < 250.0) { pixel = logo[x][y]/255.0; obj = Cnew SIMPLE_OBJECT; obj->Set_Shape (Cnew SPHERE(VECTOR(0,0,0), 2.2 - 2.0*pixel)); obj->Translate(VECTOR(-50.0+x, 28.0-y, 0)); obj->Set_Surface (Surf); obj->Set_Priority (Priority); Scn->Add (obj); } } obj = Cnew SIMPLE_OBJECT; obj->Set_Shape (Cnew PLANE); obj->Translate(VECTOR(0, -2.0, 0)); obj->Rotate(VECTOR(-90, 0, 0)); obj->Set_Surface (Cnew MATTE (0.85, 1.0, COLOUR(1,1,1))); obj->Set_Priority (Priority); Scn->Add (obj); obj = make_yellow_cross(); obj->Translate(VECTOR(8.5, -4, -50)); obj->Set_Priority (Priority); Scn->Add (obj); obj = make_yellow_cross(); obj->Translate(VECTOR(-8.5, -4, -50)); obj->Set_Priority (Priority); Scn->Add (obj); int intensity = 500000; Scn->Add (Cnew POINTLIGHT (VECTOR (300,300,-300), COLOUR (intensity,intensity,intensity))); Scn->Add (Cnew AMBIENT_LIGHT (COLOUR (1,1,1))); Scn->Set_HMaker (Cnew POV_HMAKER); World = Scn; World->Init(); Renderer = Raytracer; Renderer->Init(); Output->Render(); }