Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·167 lines (160 loc) · 6.13 KB
/
Copy pathindex.html
File metadata and controls
executable file
·167 lines (160 loc) · 6.13 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
<!--
Code adopted from
"UCLA's Graphics Example Code (Javascript and C++ translations available),
by Garett Ridge for CS174a"
-->
<!DOCTYPE html>
<html>
<head>
<title>Yakyu VR</title>
<meta charset="UTF-8"/>
<style type="text/css">
#instructions {
display: none;
padding-left: 10px
}
</style>
<script type="text/javascript" src="MV.js" ></script>
<script type="text/javascript" src="webgl-obj-loader.js" ></script>
<script type="text/javascript" src="tinywebgl-ucla.js" ></script>
<script type="text/javascript" src="scene-components.js" ></script>
<script type="text/javascript" src="shapes.js" ></script>
<script type="text/javascript" src="shaders.js" ></script>
<script type="text/javascript"> "use strict"
function showInstructions(elem) {
document.getElementById("instructions").style = "display:block";
elem.style = "display:none";
}
// ********************* WHOLE PROGRAM'S ENTRY POINT *******************
window.onload = function init() {
/*
* Firstly, browsers support something like up to 16 instances of WebGL
* per page. Construct a Canvas_Manager, which instances a WebGL
* context for our main canvas. Set your background here, too.
*/
var background = Color(102/255, 204/255, 1, 1);
window.contexts = {
main_canvas: new Canvas_Manager("gl-canvas", background)
};
// Put all shader programs in the GPU.
var shaders = ["Phong_Model", "Funny_Shader", "Fake_Bump_Map"];
for (let s of shaders) {
contexts["main_canvas"].shaders_in_use[s] = (new window[s](
contexts["main_canvas"].gl
));
}
// IMPORTANT: Include all your new image files in the following array:
var texturesDir = "resources/"
var texture_files_to_load = [ // Put all texture images in the GPU.
"text.png",
"grass.jpg",
"stitching.jpg",
"helmet_paint.jpg",
"chain.jpg",
"large_grass.png",
"face.jpg",
"shoe_color.jpg"
];
for (let f of texture_files_to_load) {
contexts["main_canvas"].textures_in_use[f] = (new Texture(
contexts["main_canvas"].gl, texturesDir + f, true
));
}
/*
* We instantiate some of our custom "Scene_Component" subclasses
* and register objects to their master "Canvas_Manager" object --
* which WebGL calls upon every time a draw / keyboard / mouse event
* happens.
*/
var scene_components = [
"Debug_Screen",
"Camera",
"Flag_Toggler"
];
if (demos[0] == "")
scene_components.push("Baseball_Scene");
else {
for (let d of demos) {
// Parse the URL and instantiate the demos named there
scene_components.push(d.replace(/-/g,"_"));
}
}
for (let s of scene_components) {
// Register the demos with their Canvas_Manager.
contexts["main_canvas"].register_scene_component(new window[s](
contexts["main_canvas"]
));
}
for (let c in contexts) {
// Call render() for each WebGL context on this page.
// Then render() will re-queue itself for more calls.
contexts[c].render();
}
}
// Find the correct browser's version of requestAnimationFrame() needed
// for queue-ing up re-display events:
window.requestAnimFrame = (function(w) {
return w.requestAnimationFrame || w.webkitRequestAnimationFrame ||
w.mozRequestAnimationFrame || w.oRequestAnimationFrame ||
w.msRequestAnimationFrame ||
function(callback, element) {
w.setTimeout(callback, 1000/60);
};
})(window);
var demos = [];
// For explanation of this part see Stackoverflow on
// "How to pass a parameter to a javascript through a url and display it
// on a page?"
for (let q of window.location.search.substring(1).split("&")) {
demos.push(decodeURIComponent(q || "").replace(/[^_\W]+/g, (s) =>
s.charAt(0).toUpperCase() + s.substr(1).toLowerCase()));
}
</script>
</head>
<body>
<div style="width: 100%; display: table;">
<div style="display: table-row">
<div style="display: table-cell; width: 50%">
<canvas id="gl-canvas" width="800" height="600"></canvas>
</div>
<div style="display: table-cell; vertical-align: top">
<div style="text-align: center">
<a href="#" onclick="showInstructions(this)">
Click for instructions
</a>
</div>
<div id="instructions">
Controlling this Graphics Object:
<ul>
<li>
Animation will begin in a paused state upon loading, so
first you should press ALT+a to play or pause animation.
</li>
<li>
Clicking and dragging moves the first-person camera.
</li>
<li>
Press b to follow the ball. To view the perspective of a
particular position on the field, press the number
corresponding to the baseball position number as indicated in
the diagram at the bottom. For example, to view the perspective
of the first baseman, press 3.
</li>
<li>
Press t to un-hide the heads-up-display text.
</li>
<li>
Press up and down to cycle through a live feed of important
strings and values, including the frame rate, of the program.
</li>
<li>
Have fun.
</li>
<img src="resources/baseball_positions.png"
alt="Baseball Positions" />
</div>
</div>
</div>
</div>
</body>
</html>