コード例 #1
0
void
makeBunny1Scene()
{
	g_camera = new Camera;
	g_scene = new Scene;
	g_image = new Image;

	g_image->resize(512, 512);

	// set up the camera
	g_camera->setBGColor(Vector3(0.0f, 0.0f, 0.2f));
	g_camera->setEye(Vector3(0, 5, 15));
	g_camera->setLookAt(Vector3(0, 0, 0));
	g_camera->setUp(Vector3(0, 1, 0));
	g_camera->setFOV(45);

	// create and place a point light source
	PointLight * light = new PointLight;
	light->setPosition(Vector3(10, 20, 10));
	light->setColor(Vector3(1, 1, 1));
	light->setWattage(4.0 * PI * 1000);
	g_scene->addLight(light);

	Material* lambert = new Lambert(Vector3(1.0f));
	Material* mirror = new Mirror(Vector3(0.5f));
	TriangleMesh * bunny = new TriangleMesh;
	bunny->load("bunny.obj");
	addMeshTrianglesToScene(bunny, lambert);
    
	// create the floor triangle
	TriangleMesh * floor = new TriangleMesh;
	floor->createSingleTriangle();
	floor->setV1(Vector3(-100, 0, -100));
	floor->setV2(Vector3(   0, 0,  100));
	floor->setV3(Vector3( 100, 0, -100));
	floor->setN1(Vector3(0, 1, 0));
	floor->setN2(Vector3(0, 1, 0));
	floor->setN3(Vector3(0, 1, 0));
    
	Triangle* t = new Triangle;
	t->setIndex(0);
	t->setMesh(floor);
	t->setMaterial(lambert); 
	g_scene->addObject(t);
    
	// let objects do pre-calculations if needed
	g_scene->preCalc();
}
コード例 #2
0
void
makeBallScene()
{
	g_camera = new Camera;
	g_scene = new Scene;
	g_image = new Image;


	g_image->resize(512, 512);

	Material* lambert = new Lambert(Vector3(1.0f,0.5f,0.0f));
	Material* lambert_ground = new Lambert(Vector3(0.9f,0.9f,0.9f));
	Material* mirror = new Mirror(Vector3(0.6f));
	Material* glass = new Glass(Vector3(0.95f),1.5f);
	Material* brdf = new BPhong(Vector3(0.4f),Vector3(0.6f),200);

	// set up the camera
	g_camera->setBGColor(Vector3(0.0f, 0.0f, 0.0f));
	g_camera->setEye(Vector3( 10, 3, 10));
	g_camera->setLookAt(Vector3(0, 0, 0));
	g_camera->setUp(Vector3(0, 1, 0));
	g_camera->setFOV(45);

	// create and place a point light source
	PointLight * light = new PointLight;
	light->setPosition(Vector3(5, 15, 5));
	light->setColor(Vector3(1, 1, 1));
	light->setWattage(4.0 * PI * 700);

	g_scene->addLight(light);

	// create the floor triangle
	TriangleMesh * floor = new TriangleMesh;
	floor->createSingleTriangle();
	floor->setV1(Vector3(-100, 0, -100));
	floor->setV2(Vector3(0, 0, 100));
	floor->setV3(Vector3(100, 0, 0));
	floor->setN1(Vector3(0, 1, 0));
	floor->setN2(Vector3(0, 1, 0));
	floor->setN3(Vector3(0, 1, 0));


	TriangleMesh * right = new TriangleMesh;
	right->createSingleTriangle();
	right->setV1(Vector3(10, 0, -10));
	right->setV2(Vector3(0, 100, 0));
	right->setV3(Vector3(-10, 0, 10));
	right->setN1(Vector3(1, 0, 1));
	right->setN2(Vector3(1, 0, 1));
	right->setN3(Vector3(1, 0, 1));

	TriangleMesh * left = new TriangleMesh;
	left->createSingleTriangle();
	left->setV1(Vector3(0, 0, 0));
	left->setV2(Vector3(100, 0, 0));
	left->setV3(Vector3(0, 100, 0));
	left->setN1(Vector3(0, 0, 1));
	left->setN2(Vector3(0, 0, 1));
	left->setN3(Vector3(0, 0, 1));

	Triangle* t = new Triangle;
	t->setIndex(0);
	t->setMesh(floor);
	t->setMaterial(lambert_ground);

	Triangle* t2 = new Triangle;
	t2->setIndex(0);
	t2->setMesh(right);
	t2->setMaterial(lambert_ground);

	Triangle* t3 = new Triangle;
	t3->setIndex(0);
	t3->setMesh(left);
	t3->setMaterial(lambert_ground);
	

	g_scene->addObject(t);
	g_scene->addObject(t2);
	//g_scene->addObject(t3);

	//create two balls
	Sphere * sphere1 = new Sphere;
	sphere1->setCenter(Vector3(0.5, 1, 1));
	sphere1->setRadius(0.2);
	sphere1->setMaterial(lambert);
	Sphere * sphere2 = new Sphere;
	sphere2->setCenter(Vector3(1, 1, 0.5));
	sphere2->setRadius(0.2);
	sphere2->setMaterial(lambert);

	Sphere * sphere3= new Sphere;
	sphere3->setCenter(Vector3(4, 1, 2));
	sphere3->setRadius(1);
	sphere3->setMaterial(glass);

	Sphere * sphere4 = new Sphere;
	sphere4->setCenter(Vector3(2, 1, 4));
	sphere4->setRadius(1);
	sphere4->setMaterial(brdf);

	g_scene->addObject(sphere1);
	g_scene->addObject(sphere2);
	g_scene->addObject(sphere3);
	g_scene->addObject(sphere4);

	g_scene->preCalc();
}
コード例 #3
0
void
makeBunny20Scene()
{
	g_camera = new Camera;
	g_scene = new Scene;
	g_image = new Image;

	g_image->resize(512, 512);

	// set up the camera
	g_camera->setBGColor(Vector3(0.0f, 0.0f, 0.2f));
	g_camera->setEye(Vector3(0, 5, 15));
	g_camera->setLookAt(Vector3(0, 0, 0));
	g_camera->setUp(Vector3(0, 1, 0));
	g_camera->setFOV(45);

	// create and place a point light source
	PointLight * light = new PointLight;
	light->setPosition(Vector3(10, 20, 10));
	light->setColor(Vector3(1, 1, 1));
	light->setWattage(4.0 * PI * 1000);
	g_scene->addLight(light);

	TriangleMesh * mesh;
	Material* material = new Lambert(Vector3(1.0f));
	Matrix4x4 xform;
	Matrix4x4 xform2;
	xform2 *= rotate(110, 0, 1, 0);
	xform2 *= scale(.6, 1, 1.1);


	// bunny 1
	xform.setIdentity();
	xform *= scale(0.3, 2.0, 0.7);
	xform *= translate(-1, .4, .3);
	xform *= rotate(25, .3, .1, .6);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 2
	xform.setIdentity();
	xform *= scale(.6, 1.2, .9);
	xform *= translate(7.6, .8, .6);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 3
	xform.setIdentity();
	xform *= translate(.7, 0, -2);
	xform *= rotate(120, 0, .6, 1);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 4
	xform.setIdentity();
	xform *= translate(3.6, 3, -1);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 5
	xform.setIdentity();
	xform *= translate(-2.4, 2, 3);
	xform *= scale(1, .8, 2);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 6
	xform.setIdentity();
	xform *= translate(5.5, -.5, 1);
	xform *= scale(1, 2, 1);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 7
	xform.setIdentity();
	xform *= rotate(15, 0, 0, 1);
	xform *= translate(-4, -.5, -6);
	xform *= scale(1, 2, 1);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 8
	xform.setIdentity();
	xform *= rotate(60, 0, 1, 0);
	xform *= translate(5, .1, 3);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 9
	xform.setIdentity();
	xform *= translate(-3, .4, 6);
	xform *= rotate(-30, 0, 1, 0);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 10
	xform.setIdentity();
	xform *= translate(3, 0.5, -2);
	xform *= rotate(180, 0, 1, 0);
	xform *= scale(1.5, 1.5, 1.5);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 11
	xform = xform2;
	xform *= scale(0.3, 2.0, 0.7);
	xform *= translate(-1, .4, .3);
	xform *= rotate(25, .3, .1, .6);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 12
	xform = xform2;
	xform *= scale(.6, 1.2, .9);
	xform *= translate(7.6, .8, .6);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 13
	xform = xform2;
	xform *= translate(.7, 0, -2);
	xform *= rotate(120, 0, .6, 1);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 14
	xform = xform2;
	xform *= translate(3.6, 3, -1);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 15
	xform = xform2;
	xform *= translate(-2.4, 2, 3);
	xform *= scale(1, .8, 2);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 16
	xform = xform2;
	xform *= translate(5.5, -.5, 1);
	xform *= scale(1, 2, 1);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 17
	xform = xform2;
	xform *= rotate(15, 0, 0, 1);
	xform *= translate(-4, -.5, -6);
	xform *= scale(1, 2, 1);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 18
	xform = xform2;
	xform *= rotate(60, 0, 1, 0);
	xform *= translate(5, .1, 3);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 19
	xform = xform2;
	xform *= translate(-3, .4, 6);
	xform *= rotate(-30, 0, 1, 0);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);

	// bunny 20
	xform = xform2;
	xform *= translate(3, 0.5, -2);
	xform *= rotate(180, 0, 1, 0);
	xform *= scale(1.5, 1.5, 1.5);
	mesh = new TriangleMesh;
	mesh->load("bunny.obj", xform);
	addMeshTrianglesToScene(mesh, material);


	// create the floor triangle
	mesh = new TriangleMesh;
	mesh->createSingleTriangle();
	mesh->setV1(Vector3(-100, 0, -100));
	mesh->setV2(Vector3(   0, 0,  100));
	mesh->setV3(Vector3( 100, 0, -100));
	mesh->setN1(Vector3(0, 1, 0));
	mesh->setN2(Vector3(0, 1, 0));
	mesh->setN3(Vector3(0, 1, 0));
    
	Triangle* t = new Triangle;
	t->setIndex(0);
	t->setMesh(mesh);
	t->setMaterial(material); 
	g_scene->addObject(t);
    
	// let objects do pre-calculations if needed
	g_scene->preCalc();
}
コード例 #4
0
void
makeTeapotScene()
{
	g_camera = new Camera;
	g_scene = new Scene;
	g_image = new Image;

	g_image->resize(512, 512);

	// set up the camera
	g_camera->setBGColor(Vector3(0.0f, 0.0f, 0.2f));
	g_camera->setEye(Vector3(0, 6, 2));
	g_camera->setLookAt(Vector3(0, 0, 0));
	g_camera->setUp(Vector3(0, 1, 0));
	g_camera->setFOV(45);

	// create and place a point light source
	PointLight * light = new PointLight;
	light->setPosition(Vector3(-2.5, 10, -2.5));
	light->setColor(Vector3(1, 1, 1));
	light->setWattage(4.0 * PI * 700);
	
	PointLight * light1 = new PointLight;
	light1->setPosition(Vector3(10, 15, 10));
	light1->setColor(Vector3(1, 1, 1));
	light1->setWattage(4.0 * PI * 700);
	
	g_scene->addLight(light);
	//g_scene->addLight(light1); //for test shadow

	Material* lambert = new Lambert(Vector3(1.0f));
	Material* mirror = new Mirror(Vector3(0.8f));
	Material* glass = new Glass(Vector3(0.95f), 1.5f);
	Material* brdf = new BPhong(Vector3(0.4f,0.4f,0.0f), Vector3(0.6f,0.6f,0.0f), 50);

	TriangleMesh * teapot = new TriangleMesh;
	Matrix4x4 xform;

	teapot->load("teapot.obj");
	addMeshTrianglesToScene(teapot, brdf);

	xform.setIdentity();
	xform *= translate(-5, 0, 0);
	teapot = new TriangleMesh;
	teapot->load("teapot.obj",xform);
	addMeshTrianglesToScene(teapot, lambert);

	xform.setIdentity();
	xform *= translate(-5, 0, -5);
	teapot = new TriangleMesh;
	teapot->load("teapot.obj", xform);
	addMeshTrianglesToScene(teapot, mirror);



	// create the floor triangle
	TriangleMesh * floor = new TriangleMesh;
	floor->createSingleTriangle();
	floor->setV1(Vector3(-100, 0, -100));
	floor->setV2(Vector3(  0, 0,  100));
	floor->setV3(Vector3( 100, 0, -100));
	floor->setN1(Vector3(0, 1, 0));
	floor->setN2(Vector3(0, 1, 0));
	floor->setN3(Vector3(0, 1, 0));
    
	Triangle* t = new Triangle;
	t->setIndex(0);
	t->setMesh(floor);
	t->setMaterial(lambert); 
	g_scene->addObject(t);




	// let objects do pre-calculations if needed
	g_scene->preCalc();
}