-
Notifications
You must be signed in to change notification settings - Fork 0
/
3d-object-modelling-flying-helicopter.html
278 lines (229 loc) Β· 8.16 KB
/
3d-object-modelling-flying-helicopter.html
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!-- FCT NOVA | FCT-UNL (Faculty of Sciences and Technology of New University of Lisbon) -->
<!-- Integrated Master (BSc./MSc.) of Computer Engineering -->
<!-- Computer Graphics and Interfaces (2017-2018) -->
<!-- Lab Work 3 - 3D Object Modelling - Flying Helicopter -->
<!-- RΓΊben AndrΓ© Barreiro - no. 42648 - r.barreiro@campus.fct.unl.pt -->
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head>
<link rel="shortcut icon" type="image/x-icon" href="https://raw.githubusercontent.com/rubenandrebarreiro/rubenandrebarreiro.github.io/master/assets/images/javascript-logo-1.png"/>
<script id="vertex-shader-2" type="x-shader/x-vertex">
const vec4 lightPosition = vec4(0.0, 0.0, 10.0, 1.0); // in WC
attribute vec4 vPosition; // vertex position in modelling coordinates
attribute vec4 vNormal; // vertex normal in modelling coordinates
uniform mat4 mView; // view transformation matrix (for points)
uniform mat4 mModelView; // model-view transformation (for points)
uniform mat4 mNormals; // model-view transformation (for vectors/normals)
uniform mat4 mProjection; // projection matrix
varying vec3 fNormal; // normal vector in camera space (to be interpolated)
varying vec3 fLight;
varying vec3 fViewer;
void main(){
// Compute position in camera frame
vec3 posC = (mModelView * vPosition).xyz;
// Compute normal in camera frame
fNormal = (mNormals * vNormal).xyz;
// Compute light vector in camera frame
if(lightPosition.w == 0.0)
fLight = normalize((mNormals * lightPosition).xyz);
else
fLight = normalize((mView*lightPosition).xyz - posC);
// Compute the view vector
// fViewer = -fPosition; // Perspective projection
fViewer = vec3(0,0,1); // Parallel projection only
// Compute vertex position in clip coordinates (as usual)
gl_Position = mProjection * mModelView * vPosition;
// Make correction for left handed system of clip space
//gl_Position.z = -gl_Position.z;
}
</script>
<script id="fragment-shader-2" type="x-shader/x-fragment">
precision mediump float;
varying vec3 fPosition;
varying vec3 fNormal;
uniform vec3 color;
const float shininess = 60.0;
const vec3 lightAmb = vec3(0.2, 0.2, 0.2);
const vec3 lightDif = vec3(0.5, 0.5, 0.5);
const vec3 lightSpe = vec3(1.0, 1.0, 1.0);
vec3 ambientColor = lightAmb * color;
vec3 diffuseColor = lightDif * color;
vec3 specularColor = lightSpe * vec3(1.0, 1.0, 1.0);
varying vec3 fLight;
varying vec3 fViewer;
void main() {
vec3 L = normalize(fLight);
vec3 V = normalize(fViewer);
vec3 N = normalize(fNormal);
// Compute the halfway vector for Phong-Blinn model
vec3 H = normalize(L+V);
// Compute diffuse reflection, don't let the vertex be illuminated from behind...
float diffuseFactor = max( dot(L,N), 0.0 );
vec3 diffuse = diffuseFactor * diffuseColor;
// Compute specular reflection
float specularFactor = pow(max(dot(N,H), 0.0), shininess);
vec3 specular = specularFactor * specularColor;
// Specular reflection should be 0 if normal is pointing away from light source
if( dot(L,N) < 0.0 ) {
specular = vec3(0.0, 0.0, 0.0);
}
// Add all 3 components from the illumination model (ambient, diffuse and specular)
gl_FragColor = vec4(ambientColor + diffuse + specular, 1.0);
}
</script>
<script type="text/javascript" src="common/webgl-utils.js"></script>
<script type="text/javascript" src="common/initShaders.js"></script>
<script type="text/javascript" src="common/MV.js"></script>
<script type="text/javascript" src="common/cube.js"></script>
<script type="text/javascript" src="common/sphere.js"></script>
<script type="text/javascript" src="common/cylinder.js"></script>
<script type="text/javascript" src="3d-object-modelling-flying-helicopter.js"></script>
<style>
body {
color: #000;
font-family:Tahoma;
font-size:13px;
font-weight: bold;
background-color: #000000;
background-image: url("imgs/JPGs/background.jpg");
}
#container {
position: absolute;
border-radius: 5px;
}
#workDescription {
background:#eeeeee;
position: absolute;
left: 960px; top: 8px;
padding:0;
margin:0;
overflow:hidden;
width: 600px;
border-radius: 5px;
text-align: center;
}
#authorsInfo {
background:#eeeeee;
position: absolute;
left: 960px; top: 248px;
padding:0;
margin:0;
overflow:hidden;
width: 600px;
border-radius: 5px;
text-align: center;
}
#instructions {
background:#eeeeee;
position: absolute;
left: 960px; top: 379px;
padding:0;
margin:0;
overflow:hidden;
width: 600px;
border-radius: 5px;
text-align: center;
}
#settings {
background:#eeeeee;
position: absolute;
left: 960px; top: 538px;
padding:0;
margin:0;
overflow:hidden;
width: 600px;
border-radius: 5px;
text-align: center;
}
a {
color: #35b0ab;
}
</style>
</head>
<body>
<title>3D Object Modelling - Flying Helicopter</title>
<div id="container" style="display: inline-block">
<canvas id="gl-canvas" width="946" height="946" style="border-radius: 5px;">
Oops... your browser doesn't support the HTML5 canvas element"
</canvas>
</div>
<br/>
<br/>
<div id="workDescription">
<h2>
<a href="https://www.fct.unl.pt/en/education/course/integrated-master-computer-science">
Computer Science and Engineering
<br/>
Integrated Master
</a>
</h2>
<h3>
@ <a href="https://www.fct.unl.pt/en"><i>FCT NOVA | FCT/UNL
<br/>
(Faculty of Sciences and Technology of New University of Lisbon)</i></a>
</h3>
<h3>
<a href="http://www.unl.pt/guia/2018/fct/UNLGI_getUC?uc=8150">
Computer Graphics and Interfaces
</a>
<br/>
(2017/2018)
</h3>
<h4>
Lab Work 3
<br/>
(3D Object Modelling - Flying Helicopter)
</h4>
</div>
<div id="authorsInfo">
<h2>
Authors/Contributors
</h2>
<h3>
<u><i>Rúben André Barreiro</i></u>
</h3>
<h4>
no. 42648 (<a href="mailto:r.barreiro@campus.fct.unl.pt">r.barreiro@campus.fct.unl.pt</a>)
</h4>
</div>
<div id="instructions">
<h2>
Instructions
</h2>
<font size="2">
- Use <i>Up arrow (β)</i> key to move up the <i>Flying Helicopter</i>;
<br/>
- Use <i>Down arrow (β)</i> key to move down the <i>Flying Helicopter</i>;
<br/>
- Use <i>Left arrow (β)</i> key to make a circular move for the <i>Flying Helicopter</i>;
<br/>
- Choose the pretended <i>Angles Factors</i> (<i>θ</i> and <i>γ Angles</i>) for adjust the settings
<br/>
for the <i>Axonometric Projection</i>;
<br/>
<br/>
</font>
</div>
<div id="settings">
<h2>
Settings/Adjustments
</h2>
<u><i>Axonometric Projection</i></u>
<br/>
<br/>
<dt>
<i>θ Angle</i>
</dt>
<i>0.01°</i>
<input id="axonometricAngleTheta" type="range" min="0.0" max="360.00" step="1.0" value="68.16"> <i>360°</i>
<dt>
<i>γ Angle</i>
</dt>
<i>0.01°</i>
<input id="axonometricAngleGamma" type="range" min="0.0" max="360.00" step="1.0" value="19.42"> <i>360°</i>
<br/>
<br/>
</div>
</body>
</html>