-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.cpp
executable file
·188 lines (144 loc) · 5.83 KB
/
scene.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//
// this provide functions to set up the scene
//
// GLM lib for matrix calculation
#include "include/glm/glm.hpp"
#include "include/glm/gtc/matrix_transform.hpp"
#include "include/glm/gtc/type_ptr.hpp"
#include "object.h"
#include <cstdio>
// light 1 position and color
extern glm::vec3 light1;
extern glm::vec3 light1_ambient;
extern glm::vec3 light1_diffuse;
extern glm::vec3 light1_specular;
// global ambient term
extern glm::vec3 global_ambient;
extern Object *scene;
extern glm::vec3 background_clr;
extern float decay_a;
extern float decay_b;
extern float decay_c;
//////////////////////////////////////////////////////////////////////////
/*******************************************
* set up the default scene
*******************************************/
void set_up_default_scene() {
// set background color
background_clr = glm::vec3(0.5,0.05,0.8);
// setup global ambient term
global_ambient = glm::vec3(0.2,0.2,0.2);
// setup light 1
light1 = glm::vec3(-2.0,5.0,1.0);
light1_ambient = glm::vec3(0.1,0.1,0.1);
light1_diffuse = glm::vec3(1.0,1.0,1.0);
light1_specular = glm::vec3(1.0,1.0,1.0);
// set up decay parameters
decay_a = 0.5;
decay_b = 0.3;
decay_c = 0.0;
// sphere 1
glm::vec3 sphere1_ambient = glm::vec3(0.7, 0.7, 0.7);
glm::vec3 sphere1_diffuse = glm::vec3(0.1, 0.5, 0.8);
glm::vec3 sphere1_specular = glm::vec3(1.0, 1.0, 1.0);
float sphere1_shineness = 10;
float sphere1_reflectance = 0.4;
glm::vec3 sphere1_ctr = glm::vec3(1.5, -0.2, -3.2);
float sphere1_rad = 1.23;
addSphere(1,sphere1_ambient, sphere1_diffuse, sphere1_specular, sphere1_shineness,
sphere1_reflectance,sphere1_ctr, sphere1_rad);
// sphere 2
glm::vec3 sphere2_ambient = glm::vec3(0.6, 0.6, 0.6);
glm::vec3 sphere2_diffuse = glm::vec3(1.0, 0.0, 0.25);
glm::vec3 sphere2_specular = glm::vec3(1.0, 1.0, 1.0);
float sphere2_shineness = 6;
float sphere2_reflectance = 0.3;
glm::vec3 sphere2_ctr = glm::vec3(-1.5, 0.0, -3.5);
float sphere2_rad = 1.5;
addSphere(2, sphere2_ambient, sphere2_diffuse, sphere2_specular, sphere2_shineness,
sphere2_reflectance, sphere2_ctr, sphere2_rad);
// sphere 3
glm::vec3 sphere3_ambient = glm::vec3(0.2, 0.2, 0.2);
glm::vec3 sphere3_diffuse = glm::vec3(0.0, 1.0, 0.25);
glm::vec3 sphere3_specular = glm::vec3(0.0, 1.0, 0.0);
float sphere3_shineness = 30;
float sphere3_reflectance = 0.3;
glm::vec3 sphere3_ctr = glm::vec3(-0.35, 1.75, -2.25);
float sphere3_rad = 0.5;
addSphere(3, sphere3_ambient, sphere3_diffuse, sphere3_specular, sphere3_shineness,
sphere3_reflectance, sphere3_ctr, sphere3_rad);
}
/***************************************
* You can create your own scene here
***************************************/
void set_up_user_scene() {
// set background color
background_clr = glm::vec3(0.5,0.05,0.8);
// setup global ambient term
global_ambient = glm::vec3(0.2,0.2,0.2);
// setup light 1
light1 = glm::vec3(-2.0,5.0,1.0);
light1_ambient = glm::vec3(0.1,0.1,0.1);
light1_diffuse = glm::vec3(1.0,1.0,1.0);
light1_specular = glm::vec3(1.0,1.0,1.0);
// set up decay parameters
decay_a = 0.5;
decay_b = 0.3;
decay_c = 0.0;
// sphere 1
glm::vec3 sphere1_ambient = glm::vec3(0.7, 0.7, 0.7);
glm::vec3 sphere1_diffuse = glm::vec3(0.1, 0.5, 0.8);
glm::vec3 sphere1_specular = glm::vec3(1.0, 1.0, 1.0);
float sphere1_shineness = 10;
float sphere1_reflectance = 0.4;
glm::vec3 sphere1_ctr = glm::vec3(1.5, -0.2, -3.2);
float sphere1_rad = 1.23;
bool sphere1_refract = true;
float sphere1_refractivity = 1.5;
float sphere1_refractance = 1.0;
addSphere(1,sphere1_ambient, sphere1_diffuse, sphere1_specular, sphere1_shineness,
sphere1_reflectance,sphere1_ctr, sphere1_rad, sphere1_refract, sphere1_refractivity, sphere1_refractance);
// sphere 2
glm::vec3 sphere2_ambient = glm::vec3(0.6, 0.6, 0.6);
glm::vec3 sphere2_diffuse = glm::vec3(1.0, 0.0, 0.25);
glm::vec3 sphere2_specular = glm::vec3(1.0, 1.0, 1.0);
float sphere2_shineness = 6;
float sphere2_reflectance = 0.3;
glm::vec3 sphere2_ctr = glm::vec3(-1.5, 0.0, -3.5);
float sphere2_rad = 1.5;
bool sphere2_refract = true;
float sphere2_refractivity = 2;
float sphere2_refractance = 1.0;
addSphere(2, sphere2_ambient, sphere2_diffuse, sphere2_specular, sphere2_shineness,
sphere2_reflectance, sphere2_ctr, sphere2_rad, sphere2_refract, sphere2_refractivity, sphere2_refractance);
// sphere 3
glm::vec3 sphere3_ambient = glm::vec3(0.2, 0.2, 0.2);
glm::vec3 sphere3_diffuse = glm::vec3(0.0, 1.0, 0.25);
glm::vec3 sphere3_specular = glm::vec3(0.0, 1.0, 0.0);
float sphere3_shineness = 30;
float sphere3_reflectance = 0.3;
glm::vec3 sphere3_ctr = glm::vec3(-0.35, 1.75, -2.25);
float sphere3_rad = 0.5;
bool sphere3_refract = true;
float sphere3_refractivity = 1.5;
float sphere3_refractance = 0.5;
addSphere(3, sphere3_ambient, sphere3_diffuse, sphere3_specular, sphere3_shineness,
sphere3_reflectance, sphere3_ctr, sphere3_rad, sphere3_refract, sphere3_refractivity, sphere3_refractance);
}
/*******************************************
* set up the chessboard
*******************************************/
void set_up_chessboard(){
glm::vec3 mat_ambient = glm::vec3(0.1, 0.1, 0.1);
glm::vec3 mat_diffuse = glm::vec3(0,0,0);
glm::vec3 mat_specular = glm::vec3(1.0, 1.0, 1.0);
float mat_shineness = 40;
float reflectance = 1.0;
glm::vec3 center = glm::vec3(0.0, -2.0, -3.5);
glm::vec3 normal = glm::vec3(0,1,0);
glm::vec3 Xaxis = glm::vec3(1,0,0);
int Xlen = 8;
int Ylen = 8;
addPlane(4,mat_ambient, mat_diffuse, mat_specular, mat_shineness, reflectance,
center,normal,Xaxis,Xlen,Ylen);
}