-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinalLocal.html
More file actions
217 lines (181 loc) · 7.06 KB
/
Copy pathfinalLocal.html
File metadata and controls
217 lines (181 loc) · 7.06 KB
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
<html>
<head>
<title>CSCI-510: Tessellation</title>
<!-- vertex Shader -->
<script id="shader" type="wgsl">
struct VertexOutput {
@builtin(position) aVertexPosition: vec4<f32>,
@location(0) bary: vec3<f32>,
@location(1) color: vec4<f32>,
};
struct UniformStruct {
theta : vec4<f32>
};
struct UniformDistanceStruct {
distance : vec4<f32>
};
@group(0) @binding(0) var<uniform> uniformStruct : UniformStruct;
@group(0) @binding(1) var<uniform> uniformDistanceStruct : UniformDistanceStruct;
@vertex
fn vs_main(
@location(0) inPos: vec3<f32>,
@location(1) bary : vec3<f32>, @location(2) color : vec4<f32>) -> VertexOutput {
var out: VertexOutput;
// Compute the sines and cosines of each rotation
// about each axis - must be converted into radians first
var c = cos( uniformStruct.theta );
var s = sin( uniformStruct.theta );
var dist = uniformDistanceStruct.distance;
// translation matrix
var trans = mat4x4<f32> ( 1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
dist.x, dist.y, dist.z + 0.8, 1.0 );
// scale matrix
var scaleFactor = 1.0;
var scale = mat4x4<f32> ( scaleFactor, 0.0, 0.0, 0.0,
0.0, scaleFactor, 0.0, 0.0,
0.0, 0.0, scaleFactor, 0.0,
0.0, 0.0, 0.0, 1.0 );
// rotation matrices
var rx = mat4x4<f32> ( 1.0, 0.0, 0.0, 0.0,
0.0, c.x, s.x, 0.0,
0.0, -s.x, c.x, 0.0,
0.0, 0.0, 0.0, 1.0 );
var ry = mat4x4<f32> ( c.y, 0.0, -s.y, 0.0,
0.0, 1.0, 0.0, 0.0,
s.y, 0.0, c.y, 0.0,
0.0, 0.0, 0.0, 1.0 );
var rz = mat4x4<f32> ( c.z, s.z, 0.0, 0.0,
-s.z, c.z, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 );
var fudgeFactor = 2.0;
var vertex = trans * rz * ry * rx * scale * vec4<f32>(inPos.x, inPos.y, inPos.z, 1);
var zToDivideBy = 1.0 + vertex.z * fudgeFactor;
out.aVertexPosition = vec4(vertex.xy / zToDivideBy, vertex.zw);
out.bary = bary;
out.color = color;
return out;
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
if (in.bary.x < 0.01 || in.bary.y < 0.01 || in.bary.z < 0.01) {
//return vec4 (1.0, 1.0, 1.0, 1.0);
}
return in.color;
}
</script>
<!-- include the shape creation functions -->
<script type="text/javascript" src="./cgIShape.js"></script>
<!-- include the main tesselation functions -->
<script type="text/javascript" src="./tessMain.js"></script>
<!-- keyboard functions -->
<script type="text/javascript">
async function gotKey(event) {
var key = event.key;
// incremental rotation
if (key == 'z')
angles[1] += angleInc;
else if (key == 'x')
angles[1] -= angleInc;
else if (key == "ArrowUp" && distance[2] < 1)
distance[2] += distanceInc;
else if (key == "ArrowDown" && distance [2] > -1)
distance[2] -= distanceInc;
else if ((key == "ArrowLeft" || key == 'a') && distance[0] > -4)
distance[0] -= distanceInc;
else if ((key == "ArrowRight" || key == 'd') && distance[0] < 4)
distance[0] += distanceInc;
else if (key == 'w' && distance[1] < 2)
distance[1] += distanceInc;
else if (key == 's' && distance[1] > -2)
distance[1] -= distanceInc;
else if (key == "Enter")
advanceSeason();
// shape selection
else if (key == '1' || key == 'c') {
curShape = CUBE;
}
else if (key == '2' || key == 'C') {
curShape = CYLINDER;
}
else if (key == '3' || key == 'n') {
curShape = CONE;
} else if (key == '4') {
curShape = COMPUTECUBE;
}
// tessellation control
else if (key == '+') {
division1 = division1 + 1;
}
else if (key == '=') {
division2 = division2 + 1;
}
else if (key == '-') {
if (division1 > 1) {
division1 = division1 - 1;
}
}
else if (key == '_') {
if (division2 > 1) {
division2 = division2 - 1;
}
}
// reset
else if (key == 'r' || key == 'R') {
angles[0] = anglesReset[0];
angles[1] = anglesReset[1];
angles[2] = anglesReset[2];
}
// create a new shape and do a redo a draw
update();
}
</script>
<script type="text/javascript">
// Call init once the webpage has loaded
window.onload = init;
</script>
</head>
<body>
<h1>CSCI-510: Milestone of Final!</h1>
<table>
<tr>
<td><canvas id="webgpu" width="910" height="1080">
Your browser does not support the HTML5 canvas element.
</canvas></td>
<td>
<h3>Controls</h3>
<table border="1">
<tbody>
<tr>
<td> enter key! </td>
<td> advance season (try holding it!) </td>
</tr>
<tr>
<td> left/right arrow key</td>
<td> move camera left/right</td>
</tr>
<tr>
<td> up/down arrow key</td>
<td> move camera in/out</td>
</tr>
<tr>
<td>z, x</td>
<td>rotate camera around hill</td>
</tr>
<tr>
<td>a, d</td>
<td>move camera to the left/right</td>
</tr>
<tr>
<td>w, s</td>
<td>move camera up/down</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</body>
</html>