-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_lightsource.cpp
153 lines (128 loc) · 5.25 KB
/
single_lightsource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// Created by liwen on 6/27/18.
//
#include "Tracer.h"
#include "Object/InfinitePlane.h"
#include "Object/Sphere.h"
#include "Object/Circle.h"
#include "Object/LightSource/SunLight.h"
#include "Object/LightSource/PointLightSource.h"
#include "Object/Material/DefaultMaterial.h"
#include "Object/Material/Phong.h"
#include "Object/Triangle.h"
#include "Object/Cylinder.h"
#include "Object/Square.h"
#define N 1
int main(int argc, char* argv[]){
Camera *cam = new Camera(Vector3(0,5,50),Vector3(0,0,-1),Vector3(0,1,0),50,50);
cam->setCanvas(1000,1000);
//InfinitePlane *plane1 = new InfinitePlane(Vector3(0,-10,0),Vector3(0,1,0));
InfinitePlane *plane2 = new InfinitePlane(Vector3(-15,0,0),Vector3(1,0,0));
InfinitePlane *plane3 = new InfinitePlane(Vector3(0,0,-40),Vector3(0,0,1));
InfinitePlane *plane4 = new InfinitePlane(Vector3(15,0,0),Vector3(-1,0,0));
InfinitePlane *plane5 = new InfinitePlane(Vector3(0,20,0),Vector3(0,-1,0));
Square *plane1 = new Square(Vector3(0,-10,0),Vector3(0,1,0), Vector3(1,0,0), Vector3(0,1,0), 14.99, 20);
Sphere *sphere1 = new Sphere(Vector3(-6,-5,-1),5);
Sphere *sphere2 = new Sphere(Vector3(2,-4,10),2);
Circle *circle1 = new Circle(Vector3(-8,19.99,5), 1, Vector3(0,-1,0));
Circle *circle2 = new Circle(Vector3(-8,19.99,-20), 1, Vector3(0,-1,0));
Cylinder *cylinder1 = new Cylinder(Vector3(3,0,-15), Vector3(0,1,0), 5, 20);
Triangle *t1 = new Triangle(Vector3(8,0,0),Vector3(8,-5,5),Vector3(13,-5,0));
Triangle *t2 = new Triangle(Vector3(8,0,0),Vector3(13,-5,0),Vector3(8,-5,-5));
Triangle *t3 = new Triangle(Vector3(8,0,0),Vector3(8,-5,-5),Vector3(3,-5,0));
Triangle *t4 = new Triangle(Vector3(8,0,0),Vector3(3,-5,0),Vector3(8,-5,5));
Triangle *t5 = new Triangle(Vector3(8,-10,0),Vector3(8,-5,5),Vector3(13,-5,0));
Triangle *t6 = new Triangle(Vector3(8,-10,0),Vector3(13,-5,0),Vector3(8,-5,-5));
Triangle *t7 = new Triangle(Vector3(8,-10,0),Vector3(8,-5,-5),Vector3(3,-5,0));
Triangle *t8 = new Triangle(Vector3(8,-10,0),Vector3(3,-5,0),Vector3(8,-5,5));
PointLightSource *light2 = new PointLightSource(Vector3(-8,19.999,5),Color3(72));
light2->setHost(circle1);
//=====================================================================
// light host
DefaultMaterial *material1 = new DefaultMaterial();
material1->ambient = Color3(255,255,255);
// poly
Phong *material2 = new Phong(Color3(1), Color3(1), 24);
material2->trace_reflectivity = 0.5;
material2->ambient = Color3(80,40,130);
// top plane
Phong *material3 = new Phong(Color3(1), Color3(1), 32, 0.1);
material3->trace_reflectivity = 0.2;
material3->ambient = Color3(25, 45, 70);
// back plane
Phong *material4 = new Phong(Color3(1, 1, 1), Color3(1), 16, 0.4);
material4->trace_reflectivity =0;
material4->ambient = Color3(40,120,40);
// left plane
Phong *material5 = new Phong(Color3(1, 1, 0.7), Color3(0.5), 16, 1);
material5->trace_reflectivity =0;
material5->ambient = Color3(250, 245, 143)/1.3;
// right plane
Phong *material6 = new Phong(Color3(0.8, 1, 0.8), Color3(1), 8, 1);
material6->trace_reflectivity =0;
material6->ambient = Color3(150,54,54);
// bottom plane
Phong *material7 = new Phong(Color3(1), Color3(1), 16, 0.1);
material7->trace_reflectivity = 1.2;
material7->ambient = Color3(5,5,5);
// transparent
Phong *material8 = new Phong(Color3(0.15), Color3(1), 256, 3, 1);
material8->trace_reflectivity = 0.3;
material8->n = 1.6;
material8->ambient = Color3(0,0,0);
// left sphere
Phong *material9 = new Phong(Color3(1, 1, 1), Color3(1, 1, 1), 128, 1);
material9->trace_reflectivity = 0.3;
material9->ambient = Color3(120,60,10)*1.2;
// cylinder
Phong *material10 = new Phong(Color3(1), Color3(1), 64, 1);
material10->trace_reflectivity = 0.3;
material10->ambient = Color3(30, 144, 255)/1.7;
//******************* material
plane1->material = material7;
plane2->material = material5;
plane3->material = material4;
plane4->material = material6;
plane5->material = material3;
sphere1->material = material9;
sphere2->material = material8;
cylinder1->material = material10;
t1->material = material2;
t2->material = material2;
t3->material = material2;
t4->material = material2;
t5->material = material2;
t6->material = material2;
t7->material = material2;
t8->material = material2;
circle1->material = material1;
circle2->material = material1;
//******************* material
vector<Object*> v_obj;
vector<LightSource*> v_light;
v_obj.push_back(plane1);
v_obj.push_back(plane2);
v_obj.push_back(plane3);
v_obj.push_back(plane4);
v_obj.push_back(plane5);
v_obj.push_back(sphere1);
v_obj.push_back(sphere2);
v_obj.push_back(t1);
v_obj.push_back(t2);
v_obj.push_back(t3);
v_obj.push_back(t4);
v_obj.push_back(t5);
v_obj.push_back(t6);
v_obj.push_back(t7);
v_obj.push_back(t8);
v_obj.push_back(light2);
v_obj.push_back(cylinder1);
v_light.push_back(light2);
Tracer *tracer = new Tracer(v_light,v_obj,cam);
tracer->Scan(3);
if(argc>1)
tracer->render(argv[1]);
else
tracer->render("opencv");
return 0;
}