#include "Draw2D.h" #include <math.h> #define PI 3.14 Point3D Draw2D::camera = Point3D(225.000000, 225.000000, 1200.000000); //Point3D Draw2D::camera = Point3D(0.000000, 0.000000, 0.000000); Point2D Draw2D::center(640/2,480/2); float Draw2D::xangle = 0; float Draw2D::yangle = 0; float Draw2D::zangle = 0; float Draw2D::far = -300; float Draw2D::near = -10.0; float Draw2D::f = 320; float Draw2D::dx = 1; float Draw2D::dy = 1; float Draw2D::miniLine = 0.9; void Draw2D::drawSegment(SDL_Surface *screen,int x0, int y0, int x1, int y1, Uint8 r, Uint8 g, Uint8 b) { int dx = abs(x1-x0); int dy = abs(y1-y0); int sx,sy; if (x0 < x1) { sx = 1 ; }else{ sx = -1;
inline Point3D operator -(const Point3D& a, const Vector3D& b) { return Point3D(a[0]-b[0], a[1]-b[1], a[2]-b[2]); }
CFlightVisualiser::CFlightVisualiser(QWidget *parent) : CFlightVisualiser(parent, Point3D(100, 100, 100), Point2D(100, 250), Point3D(500, 500, 500), Vector3D(Grad(0), Grad(0))) { }
void World::build(void) { int num_samples = 16; vp.set_hres(600); vp.set_vres(600); vp.set_pixel_size(0.5); vp.set_samples(num_samples); // vp.set_gamut_display(true); // for Figure 14.23(b) tracer_ptr = new RayCast(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(0, 0, 10000); pinhole_ptr->set_lookat(0.0); pinhole_ptr->set_view_distance(15000); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* light_ptr = new Directional; light_ptr->set_direction(100, 100, 200); light_ptr->set_color(1.0, 1.0, 1.0); light_ptr->scale_radiance(4.5); add_light(light_ptr); // colors RGBColor yellow(1, 1, 0); // yellow RGBColor brown(0.71, 0.40, 0.16); // brown RGBColor dark_green(0.0, 0.41, 0.41); // dark_green RGBColor orange(1, 0.75, 0); // orange RGBColor green(0, 0.6, 0.3); // green RGBColor light_green(0.65, 1, 0.30); // light green RGBColor dark_yellow(0.61, 0.61, 0); // dark yellow RGBColor light_purple(0.65, 0.3, 1); // light purple RGBColor dark_purple(0.5, 0, 1); // dark purple // Matt material reflection coefficients float ka = 0.25; float kd = 0.75; // spheres Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(ka); matte_ptr1->set_kd(kd); matte_ptr1->set_cd(yellow); Sphere* sphere_ptr1 = new Sphere(Point3D(5, 3, 0), 30); sphere_ptr1->set_material(matte_ptr1); // yellow add_object(sphere_ptr1); Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(ka); matte_ptr2->set_kd(kd); matte_ptr2->set_cd(brown); Sphere* sphere_ptr2 = new Sphere(Point3D(45, -7, -60), 20); sphere_ptr2->set_material(matte_ptr2); // brown add_object(sphere_ptr2); Matte* matte_ptr3 = new Matte; matte_ptr3->set_ka(ka); matte_ptr3->set_kd(kd); matte_ptr3->set_cd(dark_green); Sphere* sphere_ptr3 = new Sphere(Point3D(40, 43, -100), 17); sphere_ptr3->set_material(matte_ptr3); // dark green add_object(sphere_ptr3); Matte* matte_ptr4 = new Matte; matte_ptr4->set_ka(ka); matte_ptr4->set_kd(kd); matte_ptr4->set_cd(orange); Sphere* sphere_ptr4 = new Sphere(Point3D(-20, 28, -15), 20); sphere_ptr4->set_material(matte_ptr4); // orange add_object(sphere_ptr4); Matte* matte_ptr5 = new Matte; matte_ptr5->set_ka(ka); matte_ptr5->set_kd(kd); matte_ptr5->set_cd(green); Sphere* sphere_ptr5 = new Sphere(Point3D(-25, -7, -35), 27); sphere_ptr5->set_material(matte_ptr5); // green add_object(sphere_ptr5); Matte* matte_ptr6 = new Matte; matte_ptr6->set_ka(ka); matte_ptr6->set_kd(kd); matte_ptr6->set_cd(light_green); Sphere* sphere_ptr6 = new Sphere(Point3D(20, -27, -35), 25); sphere_ptr6->set_material(matte_ptr6); // light green add_object(sphere_ptr6); Matte* matte_ptr7 = new Matte; matte_ptr7->set_ka(ka); matte_ptr7->set_kd(kd); matte_ptr7->set_cd(green); Sphere* sphere_ptr7 = new Sphere(Point3D(35, 18, -35), 22); sphere_ptr7->set_material(matte_ptr7); // green add_object(sphere_ptr7); Matte* matte_ptr8 = new Matte; matte_ptr8->set_ka(ka); matte_ptr8->set_kd(kd); matte_ptr8->set_cd(brown); Sphere* sphere_ptr8 = new Sphere(Point3D(-57, -17, -50), 15); sphere_ptr8->set_material(matte_ptr8); // brown add_object(sphere_ptr8); Matte* matte_ptr9 = new Matte; matte_ptr9->set_ka(ka); matte_ptr9->set_kd(kd); matte_ptr9->set_cd(light_green); Sphere* sphere_ptr9 = new Sphere(Point3D(-47, 16, -80), 23); sphere_ptr9->set_material(matte_ptr9); // light green add_object(sphere_ptr9); Matte* matte_ptr10 = new Matte; matte_ptr10->set_ka(ka); matte_ptr10->set_kd(kd); matte_ptr10->set_cd(dark_green); Sphere* sphere_ptr10 = new Sphere(Point3D(-15, -32, -60), 22); sphere_ptr10->set_material(matte_ptr10); // dark green add_object(sphere_ptr10); Matte* matte_ptr11 = new Matte; matte_ptr11->set_ka(ka); matte_ptr11->set_kd(kd); matte_ptr11->set_cd(dark_yellow); Sphere* sphere_ptr11 = new Sphere(Point3D(-35, -37, -80), 22); sphere_ptr11->set_material(matte_ptr11); // dark yellow add_object(sphere_ptr11); Matte* matte_ptr12 = new Matte; matte_ptr12->set_ka(ka); matte_ptr12->set_kd(kd); matte_ptr12->set_cd(dark_yellow); Sphere* sphere_ptr12 = new Sphere(Point3D(10, 43, -80), 22); sphere_ptr12->set_material(matte_ptr12); // dark yellow add_object(sphere_ptr12); Matte* matte_ptr13 = new Matte; matte_ptr13->set_ka(ka); matte_ptr13->set_kd(kd); matte_ptr13->set_cd(dark_yellow); Sphere* sphere_ptr13 = new Sphere(Point3D(30, -7, -80), 10); sphere_ptr13->set_material(matte_ptr13); add_object(sphere_ptr13); // dark yellow (hidden) Matte* matte_ptr14 = new Matte; matte_ptr14->set_ka(ka); matte_ptr14->set_kd(kd); matte_ptr14->set_cd(dark_green); Sphere* sphere_ptr14 = new Sphere(Point3D(-40, 48, -110), 18); sphere_ptr14->set_material(matte_ptr14); // dark green add_object(sphere_ptr14); Matte* matte_ptr15 = new Matte; matte_ptr15->set_ka(ka); matte_ptr15->set_kd(kd); matte_ptr15->set_cd(brown); Sphere* sphere_ptr15 = new Sphere(Point3D(-10, 53, -120), 18); sphere_ptr15->set_material(matte_ptr15); // brown add_object(sphere_ptr15); Matte* matte_ptr16 = new Matte; matte_ptr16->set_ka(ka); matte_ptr16->set_kd(kd); matte_ptr16->set_cd(light_purple); Sphere* sphere_ptr16 = new Sphere(Point3D(-55, -52, -100), 10); sphere_ptr16->set_material(matte_ptr16); // light purple add_object(sphere_ptr16); Matte* matte_ptr17 = new Matte; matte_ptr17->set_ka(ka); matte_ptr17->set_kd(kd); matte_ptr17->set_cd(brown); Sphere* sphere_ptr17 = new Sphere(Point3D(5, -52, -100), 15); sphere_ptr17->set_material(matte_ptr17); // browm add_object(sphere_ptr17); Matte* matte_ptr18 = new Matte; matte_ptr18->set_ka(ka); matte_ptr18->set_kd(kd); matte_ptr18->set_cd(dark_purple); Sphere* sphere_ptr18 = new Sphere(Point3D(-20, -57, -120), 15); sphere_ptr18->set_material(matte_ptr18); // dark purple add_object(sphere_ptr18); Matte* matte_ptr19 = new Matte; matte_ptr19->set_ka(ka); matte_ptr19->set_kd(kd); matte_ptr19->set_cd(dark_green); Sphere* sphere_ptr19 = new Sphere(Point3D(55, -27, -100), 17); sphere_ptr19->set_material(matte_ptr19); // dark green add_object(sphere_ptr19); Matte* matte_ptr20 = new Matte; matte_ptr20->set_ka(ka); matte_ptr20->set_kd(kd); matte_ptr20->set_cd(brown); Sphere* sphere_ptr20 = new Sphere(Point3D(50, -47, -120), 15); sphere_ptr20->set_material(matte_ptr20); // browm add_object(sphere_ptr20); Matte* matte_ptr21 = new Matte; matte_ptr21->set_ka(ka); matte_ptr21->set_kd(kd); matte_ptr21->set_cd(light_purple); Sphere* sphere_ptr21 = new Sphere(Point3D(70, -42, -150), 10); sphere_ptr21->set_material(matte_ptr21); // light purple add_object(sphere_ptr21); Matte* matte_ptr22 = new Matte; matte_ptr22->set_ka(ka); matte_ptr22->set_kd(kd); matte_ptr22->set_cd(light_purple); Sphere* sphere_ptr22 = new Sphere(Point3D(5, 73, -130), 12); sphere_ptr22->set_material(matte_ptr22); // light purple add_object(sphere_ptr22); Matte* matte_ptr23 = new Matte; matte_ptr23->set_ka(ka); matte_ptr23->set_kd(kd); matte_ptr23->set_cd(dark_purple); Sphere* sphere_ptr23 = new Sphere(Point3D(66, 21, -130), 13); sphere_ptr23->set_material(matte_ptr23); // dark purple add_object(sphere_ptr23); Matte* matte_ptr24 = new Matte; matte_ptr24->set_ka(ka); matte_ptr24->set_kd(kd); matte_ptr24->set_cd(light_purple); Sphere* sphere_ptr24 = new Sphere(Point3D(72, -12, -140), 12); sphere_ptr24->set_material(matte_ptr24); // light purple add_object(sphere_ptr24); Matte* matte_ptr25 = new Matte; matte_ptr25->set_ka(ka); matte_ptr25->set_kd(kd); matte_ptr25->set_cd(green); Sphere* sphere_ptr25 = new Sphere(Point3D(64, 5, -160), 11); sphere_ptr25->set_material(matte_ptr25); // green add_object(sphere_ptr25); Matte* matte_ptr26 = new Matte; matte_ptr26->set_ka(ka); matte_ptr26->set_kd(kd); matte_ptr26->set_cd(light_purple); Sphere* sphere_ptr26 = new Sphere(Point3D(55, 38, -160), 12); sphere_ptr26->set_material(matte_ptr26); // light purple add_object(sphere_ptr26); Matte* matte_ptr27 = new Matte; matte_ptr27->set_ka(ka); matte_ptr27->set_kd(kd); matte_ptr27->set_cd(light_purple); Sphere* sphere_ptr27 = new Sphere(Point3D(-73, -2, -160), 12); sphere_ptr27->set_material(matte_ptr27); // light purple add_object(sphere_ptr27); Matte* matte_ptr28 = new Matte; matte_ptr28->set_ka(ka); matte_ptr28->set_kd(kd); matte_ptr28->set_cd(dark_purple); Sphere* sphere_ptr28 = new Sphere(Point3D(30, -62, -140), 15); sphere_ptr28->set_material(matte_ptr28); // dark purple add_object(sphere_ptr28); Matte* matte_ptr29 = new Matte; matte_ptr29->set_ka(ka); matte_ptr29->set_kd(kd); matte_ptr29->set_cd(dark_purple); Sphere* sphere_ptr29 = new Sphere(Point3D(25, 63, -140), 15); sphere_ptr29->set_material(matte_ptr29); // dark purple add_object(sphere_ptr29); Matte* matte_ptr30 = new Matte; matte_ptr30->set_ka(ka); matte_ptr30->set_kd(kd); matte_ptr30->set_cd(dark_purple); Sphere* sphere_ptr30 = new Sphere(Point3D(-60, 46, -140), 15); sphere_ptr30->set_material(matte_ptr30); // dark purple add_object(sphere_ptr30); Matte* matte_ptr31 = new Matte; matte_ptr31->set_ka(ka); matte_ptr31->set_kd(kd); matte_ptr31->set_cd(light_purple); Sphere* sphere_ptr31 = new Sphere(Point3D(-30, 68, -130), 12); sphere_ptr31->set_material(matte_ptr31); // light purple add_object(sphere_ptr31); Matte* matte_ptr32 = new Matte; matte_ptr32->set_ka(ka); matte_ptr32->set_kd(kd); matte_ptr32->set_cd(green); Sphere* sphere_ptr32 = new Sphere(Point3D(58, 56, -180), 11); sphere_ptr32->set_material(matte_ptr32); // green add_object(sphere_ptr32); Matte* matte_ptr33 = new Matte; matte_ptr33->set_ka(ka); matte_ptr33->set_kd(kd); matte_ptr33->set_cd(green); Sphere* sphere_ptr33 = new Sphere(Point3D(-63, -39, -180), 11); sphere_ptr33->set_material(matte_ptr33); // green add_object(sphere_ptr33); Matte* matte_ptr34 = new Matte; matte_ptr34->set_ka(ka); matte_ptr34->set_kd(kd); matte_ptr34->set_cd(light_purple); Sphere* sphere_ptr34 = new Sphere(Point3D(46, 68, -200), 10); sphere_ptr34->set_material(matte_ptr34); // light purple add_object(sphere_ptr34); Matte* matte_ptr35 = new Matte; matte_ptr35->set_ka(ka); matte_ptr35->set_kd(kd); matte_ptr35->set_cd(light_purple); Sphere* sphere_ptr35 = new Sphere(Point3D(-3, -72, -130), 12); sphere_ptr35->set_material(matte_ptr35); // light purple add_object(sphere_ptr35); }
Point3D RaySpotLight::transparency(RayIntersectionInfo& iInfo,RayShape* shape,Point3D cLimit){ return Point3D(1,1,1); }
ParticleSystem::ParticleSystem() : mNumParticles( 0.0 ), mOrigin( Point3D() ), mBaseVelocity( Vector3D() ), mBaseSize( 1.0 ) {}
Point3D operator +(const Point3D& u, const Vector3D& v){ return Point3D(u[0]+v[0], u[1]+v[1], u[2]+v[2]); }
Point3D AllDirections() { int a = rand() % 100-50, b = (rand() % 100 - 50) / 200.0, c = rand() % 100-50; return Point3D(a*1.0, b*1.0, c*1.0).Normalize(); }
Point3D DefaultTranslation() { return Point3D(0.0, 0.0, 0.0); }
Point3D Translation() { return Point3D(rand() % 5, rand() % 5, 0.0); }
Point3D BoxPosition() { int a = rand() % 100-50, b = rand() % 100-50, c = rand() % 100 - 50; return Point3D(a*1.0, b*1.0, c*1.0).Normalize(); }
Point3D NoDirection() { return Point3D(0.0, 0.0, 0.0).Normalize(); }
Point3D Planar() { int a = rand() % 100-50, b = rand() % 100-50; return Point3D(0.0, 0.0, 0.0).Normalize(); }
int main(int argc, char* argv[]) { // Build your scene and setup your camera here, by calling // functions from Raytracer. The code here sets up an example // scene and renders it from two different view points, DO NOT // change this if you're just implementing part one of the // assignment. Raytracer raytracer; int width = 320; int height = 240; if (argc == 3) { width = atoi(argv[1]); height = atoi(argv[2]); } /***********************************************************Testing ******************************** // Camera parameters. Point3D eye(0, 0, 1); Vector3D view(0, 0, -1); Vector3D up(0, 1, 0); double fov = 60; // Defines a material for shading. Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2,0.3,0,NULL ); Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), Colour(0.316228, 0.316228, 0.316228), 12.8,0.3,0,NULL); // Defines a point light source. raytracer.addLightSource( new PointLight(Point3D(0.0, 0, 5), Colour(0.9, 0.9, 0.9) ) ); // Add a unit square into the scene with material mat. SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold ); SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade ); // Apply some transformations to the unit square. double factor1[3] = { 1.0, 2.0, 1.0 }; double factor2[3] = { 6.0, 6.0, 6.0 }; raytracer.translate(sphere, Vector3D(0, 0, -5)); raytracer.rotate(sphere, 'x', -45); raytracer.rotate(sphere, 'z', 45); raytracer.scale(sphere, Point3D(0, 0, 0), factor1); raytracer.translate(plane, Vector3D(0, 0, -7)); raytracer.rotate(plane, 'z', 45); raytracer.scale(plane, Point3D(0, 0, 0), factor2); // Render the scene, feel free to make the image smaller for // testing purposes. raytracer.render(width, height, eye, view, up, fov, "view4.bmp"); // Render it from a different point of view. Point3D eye2(4, 2, 1); Vector3D view2(-4, -2, -6); raytracer.render(width, height, eye2, view2, up, fov, "view5.bmp"); ***********************************************************Testing ********************************/ /***********************************************************Final Scene********************************/ // Camera parameters. // Point3D eye(0, 8, -3); // Vector3D view(0, -1,0); Point3D eye(0, 0, 1); Vector3D view(0, 0, -1); Vector3D up(0, 1, 0); double fov = 60; // Defines a material for shading. Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2,0.2,NULL); // Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63), // Colour(0.316228, 0.316228, 0.316228), // 12.8,0.5,NULL); Material jade( Colour(0, 0, 0), Colour(0.47, 0.576, 0.859), Colour(0.316228, 0.316228, 0.316228), 12.8,0.5,NULL); Material red( Colour(0.3, 0.3, 0.3), Colour(1, 0, 0), Colour(0.628281, 0.555802, 0.366065), 51.2,0.2,NULL); Material white( Colour(0.3, 0.3, 0.3), Colour(1, 0.8549, 0.7255), Colour(0.628281, 0.555802, 0.366065), 51.2,0.2,NULL); Material pink( Colour(0.3, 0.3, 0.3), Colour(0.9412, 0.502, 0.502), Colour(0.628281, 0.555802, 0.366065), 51.2,0.2,NULL); Material mirror( Colour(0.0, 0.0, 0.0), Colour(0.0, 0.0, 0.0), Colour(0.0, 0.0, 0.0), 51.2,1,NULL); Material glass( Colour(0.3, 0.3, 0.3), Colour(1, 1, 1), Colour(0.628281, 0.555802, 0.366065), 51.2,0,1,NULL); glass.R_index = 1.3; glass.transparency_coef=1; // Defines a point light source. raytracer.addLightSource( new PointLight(Point3D(0, 0, 5), Colour(0.9, 0.9, 0.9) ) ); raytracer.addLightSource( new PointLight(Point3D(0, 6, -1), Colour(0.9, 0.3, 0.1) ) ); Material test( Colour(0.3, 0.3, 0.3), Colour(0.3, 0.60648, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2 ,0.1,NULL); Material test3( Colour(0.3, 0.3, 0.3), Colour(0.3, 0.5, 0.22648), Colour(0.628281, 0.555802, 0.366065), 51.2,1,NULL ); Material test2( Colour(0, 0, 0), Colour(0.3, 0.3, 0.3), Colour(1.0, 1.0, 1.0), 51.2,0,NULL ); Texture sky("/Users/bingxu/Documents/graphics/COMP3271_assignment_4_template/raytracerMacOS/sky.bmp"); Texture board("/Users/bingxu/Documents/graphics/COMP3271_assignment_4_template/raytracerMacOS/board.bmp"); Material starrysky(Colour(0, 0, 0),Colour(0, 0, 0), Colour(0.1, 0.1, 0.1), 11.264, 0, &sky); Material board_mat(Colour(0, 0, 0),Colour(0, 0, 0), Colour(0.1, 0.1, 0.1), 11.264, 1, &board); SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade ); SceneDagNode* plane1 = raytracer.addObject( new UnitSquare(), &jade ); SceneDagNode* plane2 = raytracer.addObject( new UnitSquare(), &board_mat );//the bottom SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &mirror); SceneDagNode* sphere1 = raytracer.addObject( new UnitSphere(), &white ); SceneDagNode* mars = raytracer.addObject( new UnitSphere(), &glass ); SceneDagNode* earth = raytracer.addObject( new UnitSphere(), &pink ); SceneDagNode* cylinder1 = raytracer.addObject( new UnitFiniteCylinder(), &gold ); SceneDagNode* cylinder2 = raytracer.addObject( new UnitFiniteCylinder(), &gold ); SceneDagNode* cylinder3 = raytracer.addObject( new UnitFiniteCylinder(), &gold ); SceneDagNode* cone = raytracer.addObject( new UnitFiniteCone(), &red ); double factor1[3] = { 2.0, 2.0, 2.0 }; double factor2[3] = {50,50,50}; double factor3[3] = { 1.0, 1.0, 1.0}; double factor4[3] = { 1.0, 2, 1.0}; double factor5[3] = {0.5,0.5,0.5}; double factor6[3] = {0.5,1.5,0.5}; double factor7[3] = {1.0,4.0,1.0}; //3 squares raytracer.translate(plane, Vector3D(0, 0, -15)); raytracer.scale(plane, Point3D(0, 0, 0), factor2); raytracer.translate(plane1, Vector3D(-15, 0, 0)); raytracer.rotate(plane1, 'y', 90); raytracer.scale(plane1, Point3D(0, 0, 0), factor2); raytracer.translate(plane2, Vector3D(0, -8, 0)); raytracer.rotate(plane2, 'x', -90); raytracer.scale(plane2, Point3D(0, 0, 0), factor2); //four balls raytracer.translate(sphere, Vector3D(-1, -6, -2)); raytracer.scale(sphere, Point3D(0, 0, 0), factor3); raytracer.translate(sphere1,Vector3D(-4.5, -6, 1)); raytracer.scale(sphere1, Point3D(0, 0, 0), factor3); raytracer.translate(mars, Vector3D(3, -3, -1)); raytracer.scale(mars, Point3D(0, 0, 0), factor3); raytracer.translate(earth, Vector3D(-8, -6, -2)); raytracer.scale(earth, Point3D(0, 0, 0), factor3); raytracer.rotate(cylinder1, 'z', -30); //raytracer.rotate(cylinder1, 'x', -15); raytracer.translate(cylinder1, Vector3D(0, -4, -2)); raytracer.scale(cylinder1, Point3D(0, 0, 0), factor7); raytracer.rotate(cylinder2, 'z', -30); raytracer.translate(cylinder2, Vector3D(1.5, -3, -2)); raytracer.scale(cylinder2, Point3D(0, 0, 0), factor6); raytracer.rotate(cylinder3, 'z', -30); raytracer.translate(cylinder3, Vector3D(-1.5, -3, -2)); raytracer.scale(cylinder3, Point3D(0, 0, 0), factor6); raytracer.rotate(cone, 'z', -30); raytracer.translate(cone, Vector3D(0, 2, -2)); raytracer.scale(cone, Point3D(0, 0, 0), factor4); std::clock_t start; double duration; start = std::clock(); // raytracer.render(width, height, eye, view, up, fov, "view4.bmp"); duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; //std::cout<<"The rendering duration 1 is .......: "<< duration <<'\n'; // Render it from a different point of view. Point3D eye2(3, 1, 5); Vector3D view2(-10, -8, -15); std::clock_t start1; double duration1; start1 = std::clock(); raytracer.render(width, height, eye2, view2, up, fov, "view5.bmp"); duration1 = ( std::clock() - start1 ) / (double) CLOCKS_PER_SEC; // std::cout<<"The rendering duration 2 is .......: "<< duration1 <<'\n'; /***********************************************************Final Scene********************************/ return 0; }
void World::build(void) { int num_samples = 9; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); vp.set_max_depth(10); tracer_ptr = new Whitted(this); background_color = RGBColor(0.75); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(4.5, 6, 4); pinhole_ptr->set_lookat(0.0); pinhole_ptr->set_view_distance(1800.0); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); PointLight* light_ptr1 = new PointLight; light_ptr1->set_location(40, 25, -10); light_ptr1->scale_radiance(5.0); light_ptr1->set_shadows(true); add_light(light_ptr1); // fishbowl // glass-air interface float c = 2; RGBColor glass_color(0.27*c, 0.49*c, 0.42*c); RGBColor water_color(0.75, 1, 0.75); Dielectric* glass_ptr = new Dielectric; glass_ptr->set_ks(0.5); glass_ptr->set_exp(8000.0); glass_ptr->set_eta_in(1.50); // glass glass_ptr->set_eta_out(1.0); // air glass_ptr->set_cf_in(glass_color); glass_ptr->set_cf_out(white); // water-air interface Dielectric* water_ptr = new Dielectric; water_ptr->set_ks(0.5); water_ptr->set_exp(8000); water_ptr->set_eta_in(1.33); // water water_ptr->set_eta_out(1.0); // air water_ptr->set_cf_in(water_color); water_ptr->set_cf_out(white); // water-glass interface Dielectric* dielectric_ptr = new Dielectric; dielectric_ptr->set_ks(0.5); dielectric_ptr->set_exp(8000); dielectric_ptr->set_eta_in(1.33); // water dielectric_ptr->set_eta_out(1.5); // glass dielectric_ptr->set_cf_in(water_color); dielectric_ptr->set_cf_out(glass_color); // physical bowl parameters (also the defaults) double inner_radius = 1.0; double glass_thickness = 0.1; double water_depth = 1.25; double meniscus_radius = 0.05; double opening_angle = 90.0; FishBowl* fishbowl_ptr = new FishBowl( inner_radius, glass_thickness, water_depth, meniscus_radius, opening_angle); fishbowl_ptr->set_glass_air_material(glass_ptr); fishbowl_ptr->set_water_air_material(water_ptr); fishbowl_ptr->set_water_glass_material(dielectric_ptr); add_object(fishbowl_ptr); // goldfish Phong* phong_ptr = new Phong; phong_ptr->set_ka(0.4); phong_ptr->set_kd(0.8); phong_ptr->set_cd(1.0, 0.15, 0.0); // orange phong_ptr->set_ks(0.5); phong_ptr->set_cs(1.0, 0.35, 0.0); // orange phong_ptr->set_exp(50.0); // phong_ptr->set_shadows(false); // const char* file_name = "goldfish_low_res.ply"; // for scene design char* file_name = "goldfish_high_res.ply"; // for production Grid* grid_ptr = new Grid(new Mesh); // grid_ptr->read_flat_triangles(file_name); grid_ptr->read_smooth_triangles(file_name); grid_ptr->set_material(phong_ptr); grid_ptr->setup_cells(); Instance* gold_fish_ptr = new Instance(grid_ptr); gold_fish_ptr->scale(0.03); gold_fish_ptr->translate(0.5, 0.0, 0.0); add_object(gold_fish_ptr); // plane PlaneChecker* checker_ptr = new PlaneChecker; checker_ptr->set_size(0.5); checker_ptr->set_outline_width(0.05); checker_ptr->set_color1(0.75); checker_ptr->set_color2(0.75); checker_ptr->set_outline_color(0.45); SV_Matte* sv_matte_ptr = new SV_Matte; sv_matte_ptr->set_ka(0.5); sv_matte_ptr->set_kd(0.65); sv_matte_ptr->set_cd(checker_ptr); Plane* plane_ptr = new Plane(Point3D(0, -1.51, 0), Normal(0, 1, 0)); plane_ptr->set_material(sv_matte_ptr); add_object(plane_ptr); }
Point3D GeometricObject::sample(void) { return (Point3D(0.0)); }
void World::build(void) { int num_samples = 100; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); vp.set_max_depth(19); tracer_ptr = new AreaLighting(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(7.5, 3, 9.5); pinhole_ptr->set_lookat(5, 2.5, 0); pinhole_ptr->set_view_distance(800); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); // four point lights near the ceiling // these don't use distance attenuation PointLight* light_ptr1 = new PointLight; light_ptr1->set_location(10, 10, 0); light_ptr1->scale_radiance(2.0); light_ptr1->set_shadows(true); add_light(light_ptr1); PointLight* light_ptr2 = new PointLight; light_ptr2->set_location(0, 10, 10); light_ptr2->scale_radiance(2.0); light_ptr2->set_shadows(true); add_light(light_ptr2); PointLight* light_ptr3 = new PointLight; light_ptr3->set_location(-10, 10, 0); light_ptr3->scale_radiance(2.0); light_ptr3->set_shadows(true); add_light(light_ptr3); PointLight* light_ptr4 = new PointLight; light_ptr4->set_location(0, 10, -10); light_ptr4->scale_radiance(2.0); light_ptr4->set_shadows(true); add_light(light_ptr4); // sphere // this is the only reflective object with a direct illumination shading component Reflective* reflective_ptr1 = new Reflective; reflective_ptr1->set_ka(0.1); reflective_ptr1->set_kd(0.4); reflective_ptr1->set_cd(0, 0, 1); // blue reflective_ptr1->set_ks(0.25); reflective_ptr1->set_exp(100.0); reflective_ptr1->set_kr(0.85); reflective_ptr1->set_cr(0.75, 0.75, 1); // blue Sphere* sphere_ptr1 = new Sphere(Point3D(0, 0.5, 0), 4); sphere_ptr1->set_material(reflective_ptr1); add_object(sphere_ptr1); // the walls, the ceiling, and the floor of the room are defined as planes // the shape is a cube double room_size = 11.0; // floor (-ve yw) Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(0.1); matte_ptr1->set_kd(0.50); matte_ptr1->set_cd(0.25); // medium grey Plane* floor_ptr = new Plane(Point3D(0, -room_size, 0), Normal(0, 1, 0)); floor_ptr->set_material(matte_ptr1); add_object(floor_ptr); // ceiling (+ve yw) Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(0.35); matte_ptr2->set_kd(0.50); matte_ptr2->set_cd(white); Plane* ceiling_ptr = new Plane(Point3D(0, room_size, 0), Normal(0, -1, 0)); ceiling_ptr->set_material(matte_ptr2); add_object(ceiling_ptr); // back wall (-ve zw) Matte* matte_ptr3 = new Matte; matte_ptr3->set_ka(0.15); matte_ptr3->set_kd(0.60); matte_ptr3->set_cd(0.5, 0.75, 0.75); // cyan Plane* backWall_ptr = new Plane(Point3D(0, 0, -room_size), Normal(0, 0, 1)); backWall_ptr->set_material(matte_ptr3); add_object(backWall_ptr); // front wall (+ve zw) Plane* frontWall_ptr = new Plane(Point3D(0, 0, room_size), Normal(0, 0, -1)); frontWall_ptr->set_material(matte_ptr3); add_object(frontWall_ptr); // left wall (-ve xw) Matte* matte_ptr4 = new Matte; matte_ptr4->set_ka(0.15); matte_ptr4->set_kd(0.60); matte_ptr4->set_cd(0.71, 0.40, 0.20); // orange Plane* leftWall_ptr = new Plane(Point3D(-room_size, 0, 0), Normal(1, 0, 0)); leftWall_ptr->set_material(matte_ptr4); add_object(leftWall_ptr); // right wall (+ve xw) Plane* rightWall_ptr = new Plane(Point3D(room_size, 0, 0), Normal(-1, 0, 0)); rightWall_ptr->set_material(matte_ptr4); add_object(rightWall_ptr); // mirrors on the walls // the right wall has no mirror double mirror_size = 8; // the mirror size double offset = 1.0; // the mirror offset from the walls // mirror reflection material for the left wall mirror Reflective* reflective_ptr2 = new Reflective; reflective_ptr2->set_ka(0); reflective_ptr2->set_kd(0); reflective_ptr2->set_cd(black); reflective_ptr2->set_ks(0); reflective_ptr2->set_kr(0.9); reflective_ptr2->set_cr(0.9, 1.0, 0.9); // light green // glossy reflector material for the back and front mirrors float exp = 25000.0; GlossyReflector* glossy_reflector_ptr = new GlossyReflector; glossy_reflector_ptr->set_samples(num_samples, exp); glossy_reflector_ptr->set_ka(0.0); glossy_reflector_ptr->set_kd(0.0); glossy_reflector_ptr->set_ks(0.0); glossy_reflector_ptr->set_exp(exp); glossy_reflector_ptr->set_cd(black); glossy_reflector_ptr->set_kr(0.9); glossy_reflector_ptr->set_exponent(exp); glossy_reflector_ptr->set_cr(0.9, 1.0, 0.9); // light green // back wall mirror (-ve zw) Point3D p0; Vector3D a, b; p0 = Point3D(-mirror_size, -mirror_size, -(room_size - offset)); a = Vector3D(2.0 * mirror_size, 0, 0); b = Vector3D(0, 2.0 * mirror_size, 0); Normal n(0, 0, 1); Rectangle* rectangle_ptr1 = new Rectangle(p0, a, b, n); // rectangle_ptr1->set_material(reflective_ptr2); rectangle_ptr1->set_material(glossy_reflector_ptr); add_object(rectangle_ptr1); // front wall mirror (+ve zw) p0 = Point3D(-mirror_size, -mirror_size, +(room_size - offset)); n = Normal(0, 0, -1); Rectangle* rectangle_ptr2 = new Rectangle(p0, a, b, n); // rectangle_ptr2->set_material(reflective_ptr2); rectangle_ptr2->set_material(glossy_reflector_ptr); add_object(rectangle_ptr2); // left wall mirror (-ve xw) p0 = Point3D(-(room_size - offset), -mirror_size, +mirror_size); a = Point3D(0, 0, -2.0 * mirror_size); n = Normal(1, 0, 0); Rectangle* rectangle_ptr3 = new Rectangle(p0, a, b, n); rectangle_ptr3->set_material(reflective_ptr2); add_object(rectangle_ptr3); // horizontal mirror underneath the sphere // this has no direct illumination and a lemon color Reflective* reflective_ptr3 = new Reflective; reflective_ptr3->set_ka(0); reflective_ptr3->set_kd(0); reflective_ptr3->set_cd(black); reflective_ptr3->set_ks(0); reflective_ptr3->set_kr(1); reflective_ptr3->set_cr(1, 1, 0.5); // lemon double yw = -4.0; // the yw location of the mirror p0 = Point3D(-mirror_size, yw, -mirror_size); a = Vector3D(0, 0, 2.0 * mirror_size); b = Vector3D(2.0 * mirror_size, 0, 0); n = Normal(0, 1, 0); Rectangle* rectangle_ptr4 = new Rectangle(p0, a, b, n); rectangle_ptr4->set_material(reflective_ptr3); add_object(rectangle_ptr4); }
/* * Fun flux analysis */ void FluxAnalysis::RunFluxAnalysis( QString nodeURL, QString surfaceSide, unsigned long nOfRays, bool increasePhotonMap, int heightDivisions, int widthDivisions ) { m_surfaceURL = nodeURL; m_surfaceSide = surfaceSide; //Delete a photonCounts if( m_photonCounts && m_photonCounts != 0 ) { for( int h = 0; h < m_heightDivisions; h++ ) { delete[] m_photonCounts[h]; } delete[] m_photonCounts; } m_photonCounts = 0; m_heightDivisions = heightDivisions; m_widthDivisions = widthDivisions; //Check if there is a scene if ( !m_pCurrentScene ) return; //Check if there is a transmissivity defined TTransmissivity* transmissivity = 0; if ( !m_pCurrentScene->getPart( "transmissivity", false ) ) transmissivity = 0; else transmissivity = static_cast< TTransmissivity* > ( m_pCurrentScene->getPart( "transmissivity", false ) ); //Check if there is a rootSeparator InstanceNode if( !m_pRootSeparatorInstance ) return; InstanceNode* sceneInstance = m_pRootSeparatorInstance->GetParent(); if ( !sceneInstance ) return; //Check if there is a light and is properly configured if ( !m_pCurrentScene->getPart( "lightList[0]", false ) )return; TLightKit* lightKit = static_cast< TLightKit* >( m_pCurrentScene->getPart( "lightList[0]", false ) ); InstanceNode* lightInstance = sceneInstance->children[0]; if ( !lightInstance ) return; if( !lightKit->getPart( "tsunshape", false ) ) return; TSunShape* sunShape = static_cast< TSunShape * >( lightKit->getPart( "tsunshape", false ) ); if( !lightKit->getPart( "icon", false ) ) return; TLightShape* raycastingSurface = static_cast< TLightShape * >( lightKit->getPart( "icon", false ) ); if( !lightKit->getPart( "transform" ,false ) ) return; SoTransform* lightTransform = static_cast< SoTransform * >( lightKit->getPart( "transform" ,false ) ); //Check if there is a random generator is defined. if( !m_pRandomDeviate || m_pRandomDeviate== 0 ) return; //Check if the surface and the surface side defined is suitable if( CheckSurface() == false || CheckSurfaceSide() == false ) return; //Create the photon map where photons are going to be stored if( !m_pPhotonMap || !increasePhotonMap ) { if( m_pPhotonMap ) m_pPhotonMap->EndStore( -1 ); delete m_pPhotonMap; m_pPhotonMap = new TPhotonMap(); m_pPhotonMap->SetBufferSize( HUGE_VAL ); m_tracedRays = 0; m_wPhoton = 0; m_totalPower = 0; } QVector< InstanceNode* > exportSuraceList; QModelIndex nodeIndex = m_pCurrentSceneModel->IndexFromNodeUrl( m_surfaceURL ); if( !nodeIndex.isValid() ) return; InstanceNode* surfaceNode = m_pCurrentSceneModel->NodeFromIndex( nodeIndex ); if( !surfaceNode || surfaceNode == 0 ) return; exportSuraceList.push_back( surfaceNode ); //UpdateLightSize(); TSeparatorKit* concentratorRoot = static_cast< TSeparatorKit* >( m_pCurrentScene->getPart( "childList[0]", false ) ); if ( !concentratorRoot ) return; SoGetBoundingBoxAction* bbAction = new SoGetBoundingBoxAction( SbViewportRegion() ) ; concentratorRoot->getBoundingBox( bbAction ); SbBox3f box = bbAction->getXfBoundingBox().project(); delete bbAction; bbAction = 0; BBox sceneBox; if( !box.isEmpty() ) { sceneBox.pMin = Point3D( box.getMin()[0], box.getMin()[1], box.getMin()[2] ); sceneBox.pMax = Point3D( box.getMax()[0], box.getMax()[1], box.getMax()[2] ); if( lightKit ) lightKit->Update( sceneBox ); } m_pCurrentSceneModel->UpdateSceneModel(); //Compute bounding boxes and world to object transforms trf::ComputeSceneTreeMap( m_pRootSeparatorInstance, Transform( new Matrix4x4 ), true ); m_pPhotonMap->SetConcentratorToWorld( m_pRootSeparatorInstance->GetIntersectionTransform() ); QStringList disabledNodes = QString( lightKit->disabledNodes.getValue().getString() ).split( ";", QString::SkipEmptyParts ); QVector< QPair< TShapeKit*, Transform > > surfacesList; trf::ComputeFistStageSurfaceList( m_pRootSeparatorInstance, disabledNodes, &surfacesList ); lightKit->ComputeLightSourceArea( m_sunWidthDivisions, m_sunHeightDivisions, surfacesList ); if( surfacesList.count() < 1 ) return; QVector< long > raysPerThread; int maximumValueProgressScale = 100; unsigned long t1 = nOfRays/ maximumValueProgressScale; for( int progressCount = 0; progressCount < maximumValueProgressScale; ++ progressCount ) raysPerThread<< t1; if( ( t1 * maximumValueProgressScale ) < nOfRays ) raysPerThread<< ( nOfRays - ( t1* maximumValueProgressScale) ); Transform lightToWorld = tgf::TransformFromSoTransform( lightTransform ); lightInstance->SetIntersectionTransform( lightToWorld.GetInverse() ); // Create a progress dialog. QProgressDialog dialog; dialog.setLabelText( QString("Progressing using %1 thread(s)..." ).arg( QThread::idealThreadCount() ) ); // Create a QFutureWatcher and conncect signals and slots. QFutureWatcher< void > futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int, int)), &dialog, SLOT(setRange(int, int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); QMutex mutex; QMutex mutexPhotonMap; QFuture< void > photonMap; if( transmissivity ) photonMap = QtConcurrent::map( raysPerThread, RayTracer( m_pRootSeparatorInstance, lightInstance, raycastingSurface, sunShape, lightToWorld, transmissivity, *m_pRandomDeviate, &mutex, m_pPhotonMap, &mutexPhotonMap, exportSuraceList ) ); else photonMap = QtConcurrent::map( raysPerThread, RayTracerNoTr( m_pRootSeparatorInstance, lightInstance, raycastingSurface, sunShape, lightToWorld, *m_pRandomDeviate, &mutex, m_pPhotonMap, &mutexPhotonMap, exportSuraceList ) ); futureWatcher.setFuture( photonMap ); // Display the dialog and start the event loop. dialog.exec(); futureWatcher.waitForFinished(); m_tracedRays += nOfRays; double irradiance = sunShape->GetIrradiance(); double inputAperture = raycastingSurface->GetValidArea(); m_wPhoton = double ( inputAperture * irradiance ) / m_tracedRays; UpdatePhotonCounts(); }
void World::build(void) { int num_samples = 64; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); tracer_ptr = new AreaLighting(this); background_color = RGBColor(0.5,0.5,0.5); AmbientOccluder* ambient_occluder_ptr = new AmbientOccluder; ambient_occluder_ptr->set_sampler(new MultiJittered(num_samples)); ambient_occluder_ptr->set_min_amount(0.5); set_ambient_light(ambient_occluder_ptr); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(100, 45, 100); pinhole_ptr->set_lookat(-10, 40, 0); pinhole_ptr->set_view_distance(400); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* light_ptr3 = new Directional; light_ptr3->set_direction(150, 50, -50); light_ptr3->scale_radiance(4.0); light_ptr3->set_color(1.0, 0.25, 0.0); // orange light_ptr3->set_shadows(true); add_light(light_ptr3); Emissive* emissive_ptr = new Emissive; emissive_ptr->scale_radiance(0.90); emissive_ptr->set_ce(1.0, 1.0, 0.5); // yellow //ConcaveSphere* sphere_ptr = new ConcaveSphere; //sphere_ptr->set_radius(1000000.0); //sphere_ptr->set_material(emissive_ptr); //sphere_ptr->set_shadows(false); //add_object(sphere_ptr); EnvironmentLight* environment_light_ptr = new EnvironmentLight; environment_light_ptr->set_material(emissive_ptr); environment_light_ptr->set_sampler(new MultiJittered(num_samples)); environment_light_ptr->set_shadows(true); add_light(environment_light_ptr); float ka = 0.2; // commom ambient reflection coefficient // large sphere Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(ka); matte_ptr1->set_kd(0.60); matte_ptr1->set_cd(0.75); Sphere* sphere_ptr1 = new Sphere(Point3D(38, 20, -24), 20); sphere_ptr1->set_material(matte_ptr1); add_object(sphere_ptr1); // small sphere Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(ka); matte_ptr2->set_kd(0.5); matte_ptr2->set_cd(0.85); Sphere* sphere_ptr2 = new Sphere(Point3D(34, 12, 13), 12); sphere_ptr2->set_material(matte_ptr2); add_object(sphere_ptr2); // medium sphere Matte* matte_ptr3 = new Matte; matte_ptr3->set_ka(ka); matte_ptr3->set_kd(0.5); matte_ptr3->set_cd(0.75); Sphere* sphere_ptr3 = new Sphere(Point3D(-7, 15, 42), 16); sphere_ptr3->set_material(matte_ptr3); add_object(sphere_ptr3); // cylinder // //Matte* matte_ptr4 = new Matte; //matte_ptr4->set_ka(ka); //matte_ptr4->set_kd(0.5); //matte_ptr4->set_cd(0.60); // //float bottom = 0.0; //float top = 85; //float radius = 22; //SolidCylinder* cylinder_ptr = new SolidCylinder(bottom, top, radius); //cylinder_ptr->set_material(matte_ptr4); //add_object(cylinder_ptr); // cylinder Matte* matte_ptr4 = new Matte; matte_ptr4->set_ka(ka); matte_ptr4->set_kd(0.5); matte_ptr4->set_cd(0.60); float bottom = 0.0; float top = 85; float radius = 22; SolidCylinder* cylinder_ptr = new SolidCylinder(bottom, top, radius); cylinder_ptr->set_material(matte_ptr4); add_object(cylinder_ptr); // box Matte* matte_ptr5 = new Matte; matte_ptr5->set_ka(ka); matte_ptr5->set_kd(0.5); matte_ptr5->set_cd(0.95); Box* box_ptr = new Box(Point3D(-35, 0, -110), Point3D(-25, 60, 65)); box_ptr->set_material(matte_ptr5); add_object(box_ptr); // ground plane Matte* matte_ptr6 = new Matte; matte_ptr6->set_ka(0.15); matte_ptr6->set_kd(0.5); matte_ptr6->set_cd(0.7); Plane* plane_ptr = new Plane(Point3D(0, 0.01, 0), Normal(0, 1, 0)); plane_ptr->set_material(matte_ptr6); add_object(plane_ptr); }
int step_trace_ray::execute ( const pair & frame_fragment, ray_tracer & rt ) const { int current_frame = frame_fragment.first; int current_fragment = frame_fragment.second; // Consume std::vector<Primitive*> scene; std::vector<Primitive*> static_scene = rt.static_scene; std::vector<Luminaire*> luminaires = rt.luminaires; std::vector<Primitive*> dynamic_scene; rt.dynamic_scene.get(current_frame, dynamic_scene); scene.insert(scene.end(), static_scene.begin(), static_scene.end()); scene.insert(scene.end(), dynamic_scene.begin(), dynamic_scene.end()); std::vector<Point2D*> points; rt.pixel_locations.get(pair(current_frame, current_fragment), points); // Execute double duration; std::clock_t start = std::clock(); std::vector<Pixel*> pixels; double invWidth = 1/((double)rt.image_width); double invHeight = 1/((double)rt.image_height); int smaller = std::min(rt.image_width, rt.image_height); double fov = 30; double aspectratio = rt.image_width/((double)rt.image_height); double angle = tan(3.141592653589793 * 0.5 * fov / 180.0); for(int ij = 0; ij < points.size(); ij++) { double x = (double)points[ij]->i; double y = (double)points[ij]->j; double nSamp1D = sqrt(rt.number_pixel_samples); double duvSamp = 1.0/nSamp1D; Multispectral3D superSample = Multispectral3D(); for(int i = 0; i < nSamp1D; ++i) { for(int j = 0; j < nSamp1D; ++j) { double u = x + (i + 0.5 * duvSamp)/smaller; double v = y + (j + 0.5 * duvSamp)/smaller; double xx = (2 * (u * invWidth) - 1) * angle * aspectratio; double yy = (1 - 2 * (v * invHeight)) * angle; Vector3D raydir = Vector3D(xx, yy, -1).normalize(); Ray3D ray = Ray3D(Point3D(), raydir, NULL, 0); superSample = superSample + trace(ray, scene, luminaires); } } Multispectral3D rgb = superSample / rt.number_pixel_samples; pixels.push_back(new Pixel(points[ij]->i,points[ij]->j,rgb.r,rgb.g,rgb.b)); } duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; // Produce rt.pixels.put(pair(current_frame, current_fragment), pixels); rt.execution_time.put(pair(current_frame, current_fragment), duration); return CnC::CNC_Success; };
Point3D operator -(const Point3D& u, const Vector3D& v){ return Point3D(u[0]-v[0], u[1]-v[1], u[2]-v[2]); }
BeveledWedge::BeveledWedge(const double _y0, // minimum y value const double _y1, // minimum y value const double _r0, // inner radius const double _r1, // outer radius const double _rb, // bevel radius const double _phi0, // minimum azimuth angle in degrees const double _phi1): // maximum azimuth angle in degrees y0(_y0), y1(_y1), r0(_r0), r1(_r1), rb(_rb), phi0(_phi0), phi1(_phi1) { double sin_phi0 = sin(phi0 * PI_ON_180); // in radians double cos_phi0 = cos(phi0 * PI_ON_180); // in radians double sin_phi1 = sin(phi1 * PI_ON_180); // in radians double cos_phi1 = cos(phi1 * PI_ON_180); // in radians double sin_alpha = rb / (r0 + rb); double cos_alpha = sqrt(r0 * r0 + 2.0 * r0 * rb) / (r0 + rb); double sin_beta = rb / (r1 - rb); double cos_beta = sqrt(r1 * r1 - 2.0 * r1 * rb) / (r1 - rb); double xc1 = (r0 + rb) * (sin_phi0 * cos_alpha + cos_phi0 * sin_alpha); double zc1 = (r0 + rb) * (cos_phi0 * cos_alpha - sin_phi0 * sin_alpha); double xc2 = (r1 - rb) * (sin_phi0 * cos_beta + cos_phi0 * sin_beta); double zc2 = (r1 - rb) * (cos_phi0 * cos_beta - sin_phi0 * sin_beta); double xc3 = (r0 + rb) * (sin_phi1 * cos_alpha - cos_phi1 * sin_alpha); double zc3 = (r0 + rb) * (cos_phi1 * cos_alpha + sin_phi1 * sin_alpha); double xc4 = (r1 - rb) * (sin_phi1 * cos_beta - cos_phi1 * sin_beta); double zc4 = (r1 - rb) * (cos_phi1 * cos_beta + sin_phi1 * sin_beta); // corner spheres ------------------------------------------------------------------------------- // bottom spheres Sphere* bottom_c1 = new Sphere(Point3D(xc1, y0 + rb, zc1), rb); objects.push_back(bottom_c1); Sphere* bottom_c2 = new Sphere(Point3D(xc2, y0 + rb, zc2), rb); objects.push_back(bottom_c2); Sphere* bottom_c3 = new Sphere(Point3D(xc3, y0 + rb, zc3), rb); objects.push_back(bottom_c3); Sphere* bottom_c4 = new Sphere(Point3D(xc4, y0 + rb, zc4), rb); objects.push_back(bottom_c4); // top spheres Sphere* top_c1 = new Sphere(Point3D(xc1, y1 - rb, zc1), rb); objects.push_back(top_c1); Sphere* top_c2 = new Sphere(Point3D(xc2, y1 - rb, zc2), rb); objects.push_back(top_c2); Sphere* top_c3 = new Sphere(Point3D(xc3, y1 - rb, zc3), rb); objects.push_back(top_c3); Sphere* top_c4 = new Sphere(Point3D(xc4, y1 - rb, zc4), rb); objects.push_back(top_c4); // vertical cylinders ------------------------------------------------------------------------------ Instance* bottom_c1_cylinder = new Instance(new OpenCylinder(y0 + rb, y1 - rb, rb)); bottom_c1_cylinder->translate(xc1, 0.0, zc1); bottom_c1_cylinder->transform_texture(false); objects.push_back(bottom_c1_cylinder); Instance* bottom_c2_cylinder = new Instance(new OpenCylinder(y0 + rb, y1 - rb, rb)); bottom_c2_cylinder->translate(xc2, 0.0, zc2); bottom_c2_cylinder->transform_texture(false); objects.push_back(bottom_c2_cylinder); Instance* bottom_c3_cylinder = new Instance(new OpenCylinder(y0 + rb, y1 - rb, rb)); bottom_c3_cylinder->translate(xc3, 0.0, zc3); bottom_c3_cylinder->transform_texture(false); objects.push_back(bottom_c3_cylinder); Instance* bottom_c4_cylinder = new Instance(new OpenCylinder(y0 + rb, y1 - rb, rb)); bottom_c4_cylinder->translate(xc4, 0.0, zc4); bottom_c4_cylinder->transform_texture(false); objects.push_back(bottom_c4_cylinder); // inner curved surface --------------------------------------------------------------------------------- // the azimuth angle range has to be specified in degrees double alpha = acos(cos_alpha); // radians double phi_min = phi0 + alpha * 180.0 / PI; double phi_max = phi1 - alpha * 180.0 / PI; ConcavePartCylinder* inner_cylinder_ptr = new ConcavePartCylinder(y0 + rb, y1 - rb, r0, phi_min, phi_max); objects.push_back(inner_cylinder_ptr); // outer curved surface ----------------------------------------------------------------------------------- // the azimuth angle range has to be specified in degrees double beta = acos(cos_beta); // radians phi_min = phi0 + beta * 180.0 / PI; phi_max = phi1 - beta * 180.0 / PI; ConvexPartCylinder* outer_cylinder_ptr = new ConvexPartCylinder(y0 + rb, y1 - rb, r1, phi_min, phi_max); objects.push_back(outer_cylinder_ptr); // phi0 vertical rectangle double s1 = sqrt(r0 * r0 + 2.0 * r0 * rb); double s2 = sqrt(r1 * r1 - 2.0 * r1 * rb); Point3D p1(s1 * sin_phi0, y0 + rb, s1 * cos_phi0); Point3D p2(s2 * sin_phi0, y0 + rb, s2 * cos_phi0); Vector3D a = p2 - p1; Vector3D b(0, y1 - y0 - 2.0 * rb, 0); Rectangle* phi0_rectangle_ptr = new Rectangle(p1, a, b); objects.push_back(phi0_rectangle_ptr); // phi1 vertical rectangle Point3D p3(s1 * sin_phi1, y0 + rb, s1 * cos_phi1); Point3D p4(s2 * sin_phi1, y0 + rb, s2 * cos_phi1); a = p3 - p4; Rectangle* phi1_rectangle_ptr = new Rectangle(p4, a, b); objects.push_back(phi1_rectangle_ptr); // the tori -------------------------------------------------------------------------------------------- // inner bottom phi_min = phi0 + alpha * 180.0 / PI; phi_max = phi1 - alpha * 180.0 / PI; Instance* inner_bottom_torus = new Instance(new ConvexPartTorus(r0 + rb, rb, phi_min, phi_max, 0, 360)); inner_bottom_torus->translate(0.0, y0 + rb, 0.0); inner_bottom_torus->transform_texture(false); objects.push_back(inner_bottom_torus); // inner top Instance* inner_top_torus = new Instance(new ConvexPartTorus(r0 + rb, rb, phi_min, phi_max, 0, 360)); inner_top_torus->translate(0.0, y1 - rb, 0.0); inner_top_torus->transform_texture(false); objects.push_back(inner_top_torus); // outer bottom phi_min = phi0 + beta * 180.0 / PI; phi_max = phi1 - beta * 180.0 / PI; Instance* outer_bottom_torus = new Instance(new ConvexPartTorus(r1 - rb, rb, phi_min, phi_max, 0, 360)); outer_bottom_torus->translate(0.0, y0 + rb, 0.0); outer_bottom_torus->transform_texture(false); objects.push_back(outer_bottom_torus); // outer top Instance* outer_top_torus = new Instance(new ConvexPartTorus(r1 - rb, rb, phi_min, phi_max, 0, 360)); outer_top_torus->translate(0.0, y1 - rb, 0.0); outer_top_torus->transform_texture(false); objects.push_back(outer_top_torus); // horizontal cylinders ---------------------------------------------------------------------------------- // phi0 bottom cylinder Instance* phi0_bottom_cylinder_ptr = new Instance(new OpenCylinder(0, s2 - s1, rb)); phi0_bottom_cylinder_ptr->rotate_x(90); phi0_bottom_cylinder_ptr->rotate_y(phi0); phi0_bottom_cylinder_ptr->translate(xc1, y0 + rb, zc1); phi0_bottom_cylinder_ptr->transform_texture(false); objects.push_back(phi0_bottom_cylinder_ptr); // phi0 top cylinder Instance* phi0_top_cylinder_ptr = new Instance(new OpenCylinder(0, s2 - s1, rb)); phi0_top_cylinder_ptr->rotate_x(90); phi0_top_cylinder_ptr->rotate_y(phi0); phi0_top_cylinder_ptr->translate(xc1, y1 - rb, zc1); phi0_top_cylinder_ptr->transform_texture(false); objects.push_back(phi0_top_cylinder_ptr); // phi1 bottom cylinder Instance* phi1_bottom_cylinder_ptr = new Instance(new OpenCylinder(0, s2 - s1, rb)); phi1_bottom_cylinder_ptr->rotate_x(90); phi1_bottom_cylinder_ptr->rotate_y(phi1); phi1_bottom_cylinder_ptr->translate(xc3, y0 + rb, zc3); phi1_bottom_cylinder_ptr->transform_texture(false); objects.push_back(phi1_bottom_cylinder_ptr); // phi1 top cylinder Instance* phi1_top_cylinder_ptr = new Instance(new OpenCylinder(0, s2 - s1, rb)); phi1_top_cylinder_ptr->rotate_x(90); phi1_top_cylinder_ptr->rotate_y(phi1); phi1_top_cylinder_ptr->translate(xc3, y1 - rb, zc3); phi1_top_cylinder_ptr->transform_texture(false); objects.push_back(phi1_top_cylinder_ptr); // top flat surface ----------------------------------------------------------------------------------- // main part Point3D center(0, y1, 0); Normal normal(0, 1, 0); double r_min = r0 + rb; double r_max = r1 - rb; phi_min = phi0 + alpha * 180.0 / PI; phi_max = phi1 - alpha * 180.0 / PI; PartAnnulus* top_main_part_ptr = new PartAnnulus(y1, r_min, r_max, phi_min, phi_max); objects.push_back(top_main_part_ptr); // small phi0 side patch r_min = 0.0; r_max = s2 - s1; phi_min = 0.0; phi_max = alpha * 180.0 / PI; Instance* top_phi0_patch_ptr = new Instance(new PartAnnulus(y1, r_min, r_max, phi_min, phi_max)); top_phi0_patch_ptr->rotate_y(phi0); top_phi0_patch_ptr->translate(xc1, 0.0, zc1); top_phi0_patch_ptr->transform_texture(false); objects.push_back(top_phi0_patch_ptr); // small phi1 side patch phi_min = 360.0 - alpha * 180.0 / PI; phi_max = 360.0; Instance* top_phi1_patch_ptr = new Instance(new PartAnnulus(y1, r_min, r_max, phi_min, phi_max)); top_phi1_patch_ptr->rotate_y(phi1); top_phi1_patch_ptr->translate(xc3, 0.0, zc3); top_phi1_patch_ptr->transform_texture(false); objects.push_back(top_phi1_patch_ptr); // bottom flat surface --------------------------------------------------------------------------------- // main part center = Point3D(0, y0, 0); normal = Normal(0, -1, 0); r_min = r0 + rb; r_max = r1 - rb; phi_min = phi0 + alpha * 180.0 / PI; phi_max = phi1 - alpha * 180.0 / PI; PartAnnulus* bottom_main_part_ptr = new PartAnnulus(y0, r_min, r_max, phi_min, phi_max); objects.push_back(bottom_main_part_ptr); // small phi0 side patch r_min = 0.0; r_max = s2 - s1; phi_min = 0.0; phi_max = alpha * 180.0 / PI; Instance* bottom_phi0_patch_ptr = new Instance(new PartAnnulus(y0, r_min, r_max, phi_min, phi_max)); bottom_phi0_patch_ptr->rotate_y(phi0); bottom_phi0_patch_ptr->translate(xc1, 0.0, zc1); bottom_phi0_patch_ptr->transform_texture(false); objects.push_back(bottom_phi0_patch_ptr); // small phi1 side patch phi_min = 360.0 - alpha * 180.0 / PI; phi_max = 360.0; Instance* bottom_phi1_patch_ptr = new Instance(new PartAnnulus(y0, r_min, r_max, phi_min, phi_max)); bottom_phi1_patch_ptr->rotate_y(phi1); bottom_phi1_patch_ptr->translate(xc3, 0.0, zc3); bottom_phi1_patch_ptr->transform_texture(false); objects.push_back(bottom_phi1_patch_ptr); // compute the bounding box double x[4] = {xc1, xc2, xc3, xc4}; double z[4] = {zc1, zc2, zc3, zc4}; // first, assume that the wedge is completely inside a quadrant, which will be true for most wedges // work out the maximum and minimum values double x0 = kHugeValue; double z0 = kHugeValue; for (int j = 0; j <= 3; j++) { if (x[j] < x0) x0 = x[j]; } for (int j = 0; j <= 3; j++) { if (z[j] < z0) z0 = z[j]; } double x1 = -kHugeValue; double z1 = -kHugeValue; for (int j = 0; j <= 3; j++) { if (x[j] > x1) x1 = x[j]; } for (int j = 0; j <= 3; j++) { if (z[j] > z1) z1 = z[j]; } // assign values to the bounding box bbox.x0 = x0 - rb; bbox.y0 = y0; bbox.z0 = z0 - rb; bbox.x1 = x1 + rb; bbox.y1 = y1; bbox.z1 = z1 + rb; bool spans90 = phi0 < 90 && phi1 > 90; bool spans180 = phi0 < 180 && phi1 > 180; bool spans270 = phi0 < 270 && phi1 > 270; if (spans90 && spans180 && spans270) { bbox.x0 = -r1; bbox.z0 = -r1; bbox.x1 = r1; bbox.z1 = max(zc2, zc4); } else if (spans90 && spans180) { bbox.x0 = xc4 - rb; bbox.z0 = -r1; bbox.x1 = r1; bbox.z1 = zc2 + rb; } else if (spans180 && spans270) { bbox.x0 = -r1; bbox.z0 = -r1; bbox.x1 = xc2 + rb; bbox.z1 = zc4 + rb; } else if (spans90) { bbox.x0 = min(xc1, xc3); bbox.z0 = zc4 - rb; bbox.x1 = r1; bbox.z1 = zc2 + rb; } else if (spans180) { bbox.x0 = xc4 - rb; bbox.z0 = -r1; bbox.x1 = xc2 + rb; bbox.z1 = max(zc1, zc3); } else if (spans270) { bbox.x0 = -r1; bbox.z0 = zc2 - rb; bbox.x1 = max(xc1, xc3); bbox.z1 = zc4 + rb; } }
void World::build(void) { int num_samples = 16; vp.set_hres(600); vp.set_vres(600); vp.set_samples(num_samples); vp.set_max_depth(4); background_color = RGBColor(0.5, 0.5, 1.0); // light blue tracer_ptr = new Whitted(this); Pinhole* pinhole_ptr = new Pinhole; pinhole_ptr->set_eye(0, 0, 2); pinhole_ptr->set_lookat(0, 0, 10); pinhole_ptr->set_view_distance(200.0); pinhole_ptr->set_exposure_time(0.17); pinhole_ptr->compute_uvw(); set_camera(pinhole_ptr); Directional* light_ptr1 = new Directional; light_ptr1->set_direction(0, 1, 0); // straight down light_ptr1->scale_radiance(3.0); light_ptr1->set_shadows(true); add_light(light_ptr1); Directional* light_ptr2 = new Directional; light_ptr2->set_direction(0, -1, 0); // straight up light_ptr2->scale_radiance(2.5); light_ptr2->set_shadows(false); add_light(light_ptr2); // transparent sphere Dielectric* dielectric_ptr = new Dielectric; dielectric_ptr->set_eta_in(2.42); // diamond dielectric_ptr->set_eta_out(1.0); // air dielectric_ptr->set_cf_in(white); dielectric_ptr->set_cf_out(white); Sphere* sphere_ptr1 = new Sphere(Point3D(0.0), 4.0); sphere_ptr1->set_material(dielectric_ptr); add_object(sphere_ptr1); // a ring of spheres around the transparent sphere double scaling_factor = 2.0; // used to scale the radii of the ring and spheres double sphere_radius = 1.75 * scaling_factor; double ring_radius = 10.0 * scaling_factor; int num_spheres = 20; int delta_theta = 20; RGBColor color1(1, 0.5, 0); // orange RGBColor color2(0.0, 0.5, 0.25); // cyan // Phong material for top half of each sphere Phong* phong_ptr1 = new Phong; phong_ptr1->set_ka(0.2); phong_ptr1->set_kd(1.0); phong_ptr1->set_cd(color1); phong_ptr1->set_exp(100.0); phong_ptr1->set_ks(0.5); phong_ptr1->set_cs(1, 1, 0); // reflective material for bottom half of each sphere Reflective* reflective_ptr2 = new Reflective; reflective_ptr2->set_ka(0.2); reflective_ptr2->set_kd(1.0); reflective_ptr2->set_cd(color2); reflective_ptr2->set_exp(100.0); reflective_ptr2->set_ks(0.5); reflective_ptr2->set_cs(1, 1, 0); reflective_ptr2->set_kr(0.2); for (int j = 0; j < num_spheres; j++) { double xc = ring_radius * sin (j * delta_theta * PI / 180.0); double zc = ring_radius * cos (j * delta_theta * PI / 180.0); Point3D center(xc, 0, zc); ConvexPartSphere* top_half_ptr = new ConvexPartSphere(center, sphere_radius, 0, 360, 0, 90); top_half_ptr->set_material(phong_ptr1); add_object(top_half_ptr); ConvexPartSphere* bottom_half_ptr = new ConvexPartSphere(center, sphere_radius, 0, 360, 90, 180); bottom_half_ptr->set_material(reflective_ptr2); add_object(bottom_half_ptr); } // ground plane with checker Checker3D* checker3D_ptr = new Checker3D; checker3D_ptr->set_size(4.2); checker3D_ptr->set_color1(white); checker3D_ptr->set_color2(0.5); SV_Matte* sv_matte_ptr = new SV_Matte; sv_matte_ptr->set_ka(0.4); sv_matte_ptr->set_kd(0.6); sv_matte_ptr->set_cd(checker3D_ptr); Plane* plane_ptr = new Plane(Point3D(0, -4.5, 0), Normal(0, 1, 0)); plane_ptr->set_material(sv_matte_ptr); add_object(plane_ptr); }
void World::build(void) { int num_samples = 64; vp.set_hres(600); vp.set_vres(400); vp.set_samples(num_samples); tracer_ptr = new RayCast(this); AmbientOccluder* ambient_occluder_ptr = new AmbientOccluder; ambient_occluder_ptr->set_sampler(new MultiJittered(num_samples)); ambient_occluder_ptr->set_min_amount(1.0); // for Figure 17.13(a) // ambient_occluder_ptr->set_min_amount(0.25); // for Figure 17.13(b) set_ambient_light(ambient_occluder_ptr); Orthographic* orthographic_ptr = new Orthographic; vp.set_pixel_size(0.31); orthographic_ptr->set_eye(100, 100, 50); orthographic_ptr->set_lookat(0, 10, 0); orthographic_ptr->compute_uvw(); set_camera(orthographic_ptr); PointLight* light_ptr = new PointLight; light_ptr->set_location(150, 500, 300); light_ptr->scale_radiance(3.75); light_ptr->set_shadows(true); add_light(light_ptr); // city parameters float a = 10; // city block width: xw extent float b = 12; // city block length: yw extent int num_rows = 10; // number of blocks in the xw direction int num_columns = 12; // number of blocks in the zw direction float width = 7; // building width: xw extent in range [min, a - offset] float length = 7; // building length: zw extent in range [min, b - offset] float min_size = 6; // mininum building extent in xw and yw directions float offset = 1.0; // half the minimum distance between buildings float min_height = 0.0; // minimum building height float max_height = 30; // maximum bulding height float height; // the building height in range [min_height, max_height] int num_park_rows = 4; // number of blocks of park in xw direction int num_park_columns = 6; // number of blocks of park in xw direction int row_test; // there are no buildings in the park int column_test; // there are no buildings in the park float min_color = 0.1; // prevents black buildings float max_color = 0.9; // prevents white buildings set_rand_seed(15); // as the buildings' dimensions and colors are random, it's necessary to // seed rand to keep these quantities the same at each run // if you leave this out, and change the number of samples per pixel, // these will change // the buildings are stored in a grid Grid* grid_ptr = new Grid; for (int r = 0; r < num_rows; r++) // xw direction for (int c = 0; c < num_columns; c++) { // zw direction // determine if the block is in the park if ((r - num_rows / 2) >= 0) row_test = r - num_rows / 2; else row_test = r - num_rows / 2 + 1; if ((c - num_columns / 2) >= 0) column_test = c - num_columns / 2; else column_test = c - num_columns / 2 + 1; if (abs(row_test) >= (num_park_rows / 2) || abs(column_test) >= (num_park_columns / 2)) { Matte* matte_ptr = new Matte; matte_ptr->set_ka(0.4); matte_ptr->set_kd(0.6); matte_ptr->set_cd( min_color + rand_float() * (max_color - min_color), min_color + rand_float() * (max_color - min_color), min_color + rand_float() * (max_color - min_color)); // block center coordinates float xc = a * (r - num_rows / 2.0 + 0.5); float zc = b * (c - num_columns / 2.0 + 0.5); width = min_size + rand_float() * (a - 2 * offset - min_size); length = min_size + rand_float() * (b - 2 * offset - min_size); // minimum building coordinates float xmin = xc - width / 2.0; float ymin = 0.0; float zmin = zc - length / 2.0; // maximum building coordinates height = min_height + rand_float() * (max_height - min_height); // The following is a hack to make the middle row and column of buildings higher // on average than the other buildings. // This only works properly when there are three rows and columns of buildings if (r == 1 || r == num_rows - 2 || c == 1 || c == num_columns - 2) height *= 1.5; float xmax = xc + width / 2.0; float ymax = height; float zmax = zc + length / 2.0; Box* building_ptr = new Box(Point3D(xmin, ymin, zmin), Point3D(xmax, ymax, zmax)); building_ptr->set_material(matte_ptr); grid_ptr->add_object(building_ptr); } } grid_ptr->setup_cells(); add_object(grid_ptr); // render the park green Matte* matte_ptr1 = new Matte; matte_ptr1->set_ka(0.4); matte_ptr1->set_kd(0.5); matte_ptr1->set_cd(0.3, 0.5, 0.3); // green Box* park_ptr = new Box( Point3D(-a * num_park_rows / 2, 0.0, -b * num_park_columns / 2), Point3D(a * num_park_rows / 2, 0.1, b * num_park_columns / 2) ); park_ptr->set_material(matte_ptr1); add_object(park_ptr); // ground plane Matte* matte_ptr2 = new Matte; matte_ptr2->set_ka(0.3); matte_ptr2->set_kd(0.5); matte_ptr2->set_cd(0.85); Plane* plane_ptr = new Plane(Point3D(0, 0.01, 0), Normal(0, 1, 0)); plane_ptr->set_material(matte_ptr2); add_object(plane_ptr); }
Point3D ShapeBezierSurface::Sample( double /*u*/, double /*v*/ ) const { return Point3D(); }
void sreBoundingVolume::CompleteParameters() { if (is_complete) return; if (type == SRE_BOUNDING_VOLUME_PYRAMID) { // pyramid->nu_planes = pyramid->nu_vertices; if (pyramid->nu_vertices == 0) { type = SRE_BOUNDING_VOLUME_EMPTY; is_complete = true; return; } #if 0 // For a pyramid, we can't just take the mean value of the vertex positions, // because the center would be shifted into the direction of the base. // We have to give the same weight to the apex as all base vertices combined. pyramid->center = pyramid->vertex[0] * (pyramid->nu_vertices - 1); for (int i = 0; i < pyramid->nu_vertices - 1; i++) pyramid->center += pyramid->vertex[i + 1]; pyramid->center /= (pyramid->nu_vertices - 1) * 2; pyramid->nu_planes = pyramid->nu_vertices; // Add the side planes. The normals should point inwards. for (int i = 0; i < pyramid->nu_vertices - 1; i++) { pyramid->plane[i] = dstPlaneFromPoints(pyramid->vertex[0], pyramid->vertex[i + 1], pyramid->vertex[((i + 1) % (pyramid->nu_vertices - 1)) + 1]); pyramid->plane[i].OrientPlaneTowardsPoint(pyramid->center); } #endif // Add the base plane. We can any use three of the base vertices, the result should be // the same, although the accuracy would suffer if the angle between the first three // side planes is small. When a pyramid is derived from a projected bounding // box, the number of base vertices will usually be four, six or seven. We can try to // avoid this issue by spreading out the used vertices. int v0 = 1; // Always use the first base vertex. int v1, v2; if (pyramid->nu_vertices == 5) { // Four base vertices. v1 = 2; v2 = 4; } else if (pyramid->nu_vertices == 7) { // Six base vertices. v1 = 3; v2 = 6; } else if (pyramid->nu_vertices == 8) { // Seven base vertices. v1 = 4; v2 = 7; } else { v1 = 2; v2 = 3; } Vector4D base_plane = dstPlaneFromPoints(pyramid->vertex[v0], pyramid->vertex[v1], pyramid->vertex[v2]); // The normal should point inwards (which is towards the apex). base_plane.OrientPlaneTowardsPoint(pyramid->vertex[0]); pyramid->base_normal = base_plane.GetVector3D(); } else if (type == SRE_BOUNDING_VOLUME_CONVEX_HULL) { // This is not yet used. A sreBoundingVolumeConvexHullConfigurable type is assumed. // Determine the center using the mean position of the vertices. convex_hull_configurable->center = Point3D(0, 0, 0); for (int i = 0; i < convex_hull_configurable->hull.nu_vertices; i++) convex_hull_configurable->center += convex_hull_configurable->hull.vertex[i]; convex_hull_configurable->center /= convex_hull_configurable->hull.nu_vertices; // For each plane, create the plane vector using the information in the // plane definitions array. int j = 0; for (int i = 0; i < convex_hull_configurable->nu_planes; i++) { int *vertex_indices = &convex_hull_configurable->plane_definitions[j + 1]; // Just use the first three vertices defined for the plane. For planes defined with // three or four vertices, this should be OK. convex_hull_configurable->plane[i] = dstPlaneFromPoints( convex_hull_configurable->hull.vertex[vertex_indices[0]], convex_hull_configurable->hull.vertex[vertex_indices[1]], convex_hull_configurable->hull.vertex[vertex_indices[2]]); convex_hull_configurable->plane[i].OrientPlaneTowardsPoint( convex_hull_configurable->center); // To the next plane in the plane definitions array. j += 1 + convex_hull_configurable->plane_definitions[j]; } } else return; // For convex hull derived types (including configurable convex hulls), // calculate the radius of each plane with respect to the center, and store minimum // and maximum values found. convex_hull_full->min_radius = POSITIVE_INFINITY_FLOAT; convex_hull_full->max_radius = 0; for (int i = 0; i < convex_hull_full->nu_planes; i++) { convex_hull_full->plane_radius[i] = fabsf(Dot(convex_hull_full->plane[i], convex_hull_full->center)); convex_hull_full->min_radius = minf(convex_hull_full->min_radius, convex_hull_full->plane_radius[i]); convex_hull_full->max_radius = maxf(convex_hull_full->max_radius, convex_hull_full->plane_radius[i]); } is_complete = true; return; }
void CFlightVisualiser::drawCords(QPainter& painter, const QRect& fieldLimit) { Point3D zero3D(0, 0, 0), x3D(100, 0, 0), y3D(0, 100, 0), z3D(0, 0, 100); Point2D zeroPoint = getScreenPoint(zero3D, fieldLimit); Point2D x = getScreenPoint(x3D, fieldLimit); Point2D y = getScreenPoint(y3D, fieldLimit); Point2D z = getScreenPoint(z3D, fieldLimit); painter.setPen(QPen(QColor(), 1)); painter.drawLine(QPointF(zeroPoint), QPointF(x)); painter.drawText(QRectF(QPointF(x), QPointF(x.X() + 20, x.Y() + 20)), "X"); painter.drawLine(QPointF(zeroPoint), QPointF(y)); painter.drawText(QRectF(QPointF(y), QPointF(y.X() + 20, y.Y() + 20)), "Y"); painter.drawLine(QPointF(zeroPoint), QPointF(z)); painter.drawText(QRectF(QPointF(z), QPointF(z.X() + 20, z.Y() + 20)), "Z"); painter.setPen(Qt::SolidLine); const int distance = 1; std::vector<QPoint> frameVec = {QPoint(distance, distance), QPoint(distance, this->height() - distance), QPoint(distance, this->height() - distance), QPoint(this->width() - distance, this->height() - distance), QPoint(this->width() - distance, this->height() - distance), QPoint(this->width() - distance, distance), QPoint(this->width() - distance, distance), QPoint(distance, distance)}; QVector<QPoint> frameCords; for(const auto& p: frameVec) { frameCords.push_back(p); } painter.drawLines(frameCords); Rectangle3D max3dRect = getMaximumRect(); float xPosStart = max3dRect.minX; float yPosStart = max3dRect.minY; float xPosEnd = max3dRect.maxX; float yPosEnd = max3dRect.maxY; float xPos = xPosStart; float yPos = yPosStart; for(int i = 0; i < 11; ++i) { Point2D curXMinYWebPoint = getScreenPoint(Point3D(xPos, yPosStart, 0), fieldLimit); Point2D curXMaxYWebPoint = getScreenPoint(Point3D(xPos, yPosEnd, 0), fieldLimit); Point2D minXCurYWebPoint = getScreenPoint(Point3D(xPosStart, yPos, 0), fieldLimit); Point2D maxXCurYWebPoint = getScreenPoint(Point3D(xPosEnd, yPos, 0), fieldLimit); painter.drawLine(QPointF(curXMinYWebPoint.X(), curXMinYWebPoint.Y()), QPointF(curXMaxYWebPoint.X(), curXMaxYWebPoint.Y())); //x painter.drawLine(QPointF(minXCurYWebPoint.X(), minXCurYWebPoint.Y()), QPointF(maxXCurYWebPoint.X(), maxXCurYWebPoint.Y())); xPos += (xPosEnd - xPosStart) / 10; yPos += (yPosEnd - yPosStart) / 10; } }
void TrackerLinearFresnel::Evaluate( Vector3D sunVectorW, Transform parentWT0 ) { Vector3D i = parentWT0( sunVectorW ); Vector3D localAxis; Point3D focusPoint; if( activeAxis.getValue() == 0 ) { localAxis = Vector3D( 1.0, 0.0, 0.0 ) ; focusPoint = Point3D( 0.0, axisOrigin.getValue()[0], axisOrigin.getValue()[1] ) ; } else if( activeAxis.getValue() == 1 ) { localAxis = Vector3D( 0.0, 1.0, 0.0 ); focusPoint = Point3D( axisOrigin.getValue()[0], 0.0, axisOrigin.getValue()[1] ) ; } else { localAxis = Vector3D( 0.0, 0.0, 1.0 ) ; focusPoint = Point3D( axisOrigin.getValue()[0], axisOrigin.getValue()[1], 0.0 ) ; } Vector3D focus = Vector3D( focusPoint ); if (typeOfAimingPoint.getValue() == 0 ) //Absolute { localAxis = parentWT0( localAxis ); focus = Vector3D( parentWT0( focusPoint ) ); } double angle = 0.0; //Dawann : in a Fresnel concentrator we use the project of the sun vector on the normal plan of the axis //it= the projection of the sun on the normal plan of the axis... if( localAxis == Vector3D( 1.0, 0.0, 0.0 ) ) { Vector3D r = Normalize( Vector3D( 0.0, focus.y, focus.z ) ); Vector3D it = Normalize( Vector3D( 0.0, i.y, i.z ) ); Vector3D n = Normalize( it + r ); if( fabs( n.z ) > 0.0 ) angle = atan2( n.z, n.y ); } else if( localAxis == Vector3D( 0.0, 1.0, 0.0 ) ) { Vector3D r = Normalize( Vector3D( focus.x, 0.0, focus.z ) ); Vector3D it = Normalize( Vector3D( i.x, 0.0, i.z ) ); Vector3D n = Normalize( it + r ); if( fabs( n.z ) > 0.0 ) angle = - atan2( n.z, n.x ); } else { Vector3D r = Normalize( Vector3D( focus.x, focus.y, 0.0 ) ); Vector3D it = Normalize( Vector3D( i.x, i.y, 0.0 ) ); Vector3D n = Normalize( it + r ); if( fabs( n.x ) > 0.0 ) angle = -atan2( n.x, n.y ); } SbVec3f axis = SbVec3f( localAxis.x, localAxis.y, localAxis.z ); SoTransform* newTransform = new SoTransform(); newTransform->rotation.setValue( axis, angle ); SetEngineOutput(newTransform); }
Point3D Matrix::operator*(const Point3D& p) const { return Point3D(m[0][0] * p.x + m[0][1] * p.y + m[0][2] * p.z + m[0][3], m[1][0] * p.x + m[1][1] * p.y + m[1][2] * p.z + m[1][3], m[2][0] * p.x + m[2][1] * p.y + m[2][2] * p.z + m[2][3]); }
Vector3D operator* (const Matrix& mat, const Vector3D& v) { return (Point3D(mat.m[0][0] * v.x + mat.m[0][1] * v.y + mat.m[0][2] * v.z, mat.m[1][0] * v.x + mat.m[1][1] * v.y + mat.m[1][2] * v.z, mat.m[2][0] * v.x + mat.m[2][1] * v.y + mat.m[2][2] * v.z)); }