-
Notifications
You must be signed in to change notification settings - Fork 0
/
flight.html
96 lines (73 loc) · 3.24 KB
/
flight.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
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Flight Simulator </title>
<meta charset="utf-8">
</head>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexNormal;
attribute vec3 aVertexPosition;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
uniform vec3 uLightPosition;
uniform vec3 uAmbientLightColor;
uniform vec3 uDiffuseLightColor;
uniform vec3 uSpecularLightColor;
const float shininess = 32.0;
varying vec4 vColor;
void main(void) {
// Get the vertex position in eye coordinates
vec4 vertexPositionEye4 = uMVMatrix * vec4(aVertexPosition, 1.0);
vec3 vertexPositionEye3 = vertexPositionEye4.xyz / vertexPositionEye4.w;
// Calculate the vector (l) to the light source
vec3 vectorToLightSource = normalize(uLightPosition - vertexPositionEye3);
// Transform the normal (n) to eye coordinates
vec3 normalEye = normalize(uNMatrix * aVertexNormal);
// Calculate n dot l for diffuse lighting
float diffuseLightWeightning = max(dot(normalEye,
vectorToLightSource), 0.0);
// Calculate the reflection vector (r) that is needed for specular light
vec3 reflectionVector = normalize(reflect(-vectorToLightSource,
normalEye));
// The camera in eye coordinates is located in the origin and is pointing
// along the negative z-axis. Calculate viewVector (v)
// in eye coordinates as:
// (0.0, 0.0, 0.0) - vertexPositionEye3
vec3 viewVectorEye = -normalize(vertexPositionEye3);
float rdotv = max(dot(reflectionVector, viewVectorEye), 0.0);
float specularLightWeightning = pow(rdotv, shininess);
// Sum up all three reflection components and send to the fragment shader
vColor = vec4((uAmbientLightColor
+ uDiffuseLightColor * diffuseLightWeightning
+ uSpecularLightColor * specularLightWeightning),1.0);
gl_Position = uPMatrix*uMVMatrix*vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec4 vColor;
void main(void) {
gl_FragColor = vColor;
}
</script>
<script src="gl-matrix-min.js"></script>
<script src="webgl-utils.js"></script>
<script src="simpleModeling.js"></script>
<script src="terrainModeling.js"></script>
<script src="flight.js"></script>
<body onload="startup();">
<p> Pitch Up: Up Key | Pitch Up: Up Key </p>
<p> Rotate Left: Left Key | Rotate Right: Right Key </p>
<p> Yaw Left: J | Yaw Right: K </p>
<canvas id="myGLCanvas" width="800" height="800"></canvas>
<form id="input_form">
<fieldset>
<legend>Rendering Parameters</legend>
<input type="radio" name="primitive" id="wireframe" value="wireframe"> Wireframe
<input type="radio" name="primitive" id="polygon" id="polygon" value="polygon"> Polygon
<input type="radio" name="primitive" id="wirepoly" value="wirepoly" checked > Polygon with Edges
</fieldset>
</form>
</body>
</html>