00001 #include "raypp.h"
00002
00007 #ifdef GLUTM_RAYPP
00008
00009 #include <raypp/kernel/handle.h>
00010 #include <raypp/worlds/scene.h>
00011 #include <raypp/worlds/hmakers/pov_hmaker.h>
00012 #include <raypp/renderers/raytracer.h>
00013 #include <raypp/outputs/tga_output.h>
00014 #include <raypp/cameras/ortho_camera.h>
00015 #include <raypp/lights/pointlight.h>
00016 #include <raypp/lights/ambient_light.h>
00017
00018 #include <math/matrix4.h>
00019
00020 #include <cassert>
00021
00022 namespace RAYPP {
00023
00024 extern HANDLE<WORLD> World;
00025 extern HANDLE<RENDERER> Renderer;
00026
00027 }
00028
00029 using namespace RAYPP;
00030 using namespace std;
00031
00032 SCENE *scene = NULL;
00033
00034 bool
00035 initScene()
00036 {
00037 World = scene = new (countable) SCENE;
00038
00039 scene->Add(new (countable) POINTLIGHT(VECTOR (-20,30,20), COLOUR (600,600,600)));
00040 scene->Add(new (countable) POINTLIGHT(VECTOR (20,20,40), COLOUR (600,600,600)));
00041 scene->Add(new (countable) AMBIENT_LIGHT(COLOUR (1,1,1)));
00042
00043 scene->Set_HMaker (new (countable) POV_HMAKER());
00044
00045 return true;
00046 }
00047
00048 bool
00049 raytraceScene(const std::string &filename,const int width,const int height,const Matrix &modelview)
00050 {
00051 assert(width>0 && height>0);
00052
00053 RAYTRACER *raytracer = new (countable) RAYTRACER;
00054 raytracer->Set_Shadow_Rays(false);
00055 raytracer->Set_Super_Samples(2);
00056 Renderer = raytracer;
00057
00058 ORTHO_CAMERA *camera = new (countable) ORTHO_CAMERA;
00059 camera->Set_Infinite(true);
00060
00061 TRANSFORM transform;
00062 {
00063 TRANSMAT matrix;
00064 for (int i=0;i<4;i++)
00065 for (int j=0;j<3;j++)
00066 matrix.entry[i][j] = modelview[i*4+j];
00067
00068 matrix.Invert();
00069 transform.Make_General_Transform(matrix);
00070 camera->Transform(transform);
00071 }
00072
00073 raytracer->Add(camera);
00074 camera->Set_Aspect_Ratio(double(width)/double(height));
00075
00076 HANDLE<OUTPUT> output;
00077 output = new (countable) TGA_OUTPUT(width,height,filename.c_str());
00078 output->Init();
00079
00080 scene->Init();
00081 Renderer->Init();
00082 output->Render();
00083
00084 return true;
00085 }
00086
00087 #endif