-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
348 lines (284 loc) · 14.2 KB
/
index.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<html>
<head>
<title>Lattice Structures</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="crystal.css">
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="src/assert.js"></script>
<script type="text/javascript" src="src/webgl-utils.js"></script>
<script type="text/javascript" src="src/gl-matrix/common.js"></script>
<script type="text/javascript" src="src/gl-matrix/mat3.js"></script>
<script type="text/javascript" src="src/gl-matrix/mat4.js"></script>
<script type="text/javascript" src="src/gl-matrix/vec2.js"></script>
<script type="text/javascript" src="src/gl-matrix/vec3.js"></script>
<script type="text/javascript" src="src/gl-matrix/vec4.js"></script>
<script type="text/javascript" src="src/graphics/program.js"></script>
<script type="text/javascript" src="src/graphics/shader.js"></script>
<script type="text/javascript" src="src/graphics/obj-loader.js"></script>
<script type="text/javascript" src="src/graphics/shape.js"></script>
<script type="text/javascript" src="src/graphics/matrixStack.js"></script>
<script type="text/javascript" src="src/graphics/stack.js"></script>
<script type="text/javascript" src="src/graphics/camera.js"></script>
<script type="text/javascript" src="src/graphics/angleAxis.js"></script>
<script type="text/javascript" src="src/lattices/unitCell.js"></script>
<script type="text/javascript" src="src/lattices/simpleCubic.js"></script>
<script type="text/javascript" src="src/lattices/layer.js"></script>
<script type ="text/javascript" src="src/lattices/NaClLayer.js"></script>
<script type ="text/javascript" src="src/lattices/CaF2Layer.js"></script>
<script type="text/javascript" src="src/lattices/bodyCentered.js"></script>
<script type="text/javascript" src="src/lattices/faceCentered.js"></script>
<script type="text/javascript" src="src/lattices/sodiumChloride.js"></script>
<script type="text/javascript" src="src/lattices/CalciumFluoride.js"></script>
<script type="text/javascript" src="src/lattices/legend.js"></script>
<script type="text/javascript" src="src/lattices/hcp.js"></script>
<script type="text/javascript" src="src/lattices/faceCenteredLayer.js"></script>
<script type="text/javascript" src="src/UI/user.js"></script>
<script type="text/javascript" src="src/UI/scene.js"></script>
<script type="text/javascript" src="src/UI/crystal.js"></script>
<script type="text/javascript" src="src/UI/CoordCheck.js"></script>
<script type="text/javascript">
var gl;
var prog;
var camera;
var sphere = new Shape();
var type = "";
function webGLStart() {
// Initialize scene
Scene.load("resources/", $('#displaySelector'));
initGL(); // sets up canvas element for webgl
gl.enable(gl.DEPTH_TEST);
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
gl.enable(gl.CULL_FACE);
// Setup shader
prog = new Program("shader-vs", "shader-fs");
prog.load();
prog.bind();
prog.addHandle("vertPos", "attribute")
prog.addHandle("vertNor", "attribute");
prog.addHandle("P", "uniform");
prog.addHandle("MV", "uniform");
prog.addHandle("kdFront", "uniform");
prog.addHandle("alpha", "uniform");
// Setup camera
camera = new Camera();
camera.setAspect(1200.0 / 900.0);
// Setup key events
User.setup($('#displaySelector'), $('#crystalSelector'));
$('#aboutText').hide();
$('#legendText').hide();
tick();
}
function tick() {
requestAnimFrame(tick);
// configure gl viewport and clean buffers
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.clearColor(1.0, 1.0, 1.0, 1.0);
var MV = new MatrixStack();
var P = new MatrixStack();
P.pushMatrix();
camera.applyProjectionMatrix(P);
MV.pushMatrix();
camera.applyViewMatrix(MV, type);
prog.bind();
gl.uniformMatrix4fv(prog.getHandle("P"), false, P.top());
MV.pushMatrix();
type = Scene.draw(MV, prog);
MV.popMatrix();
prog.unbind();
P.popMatrix();
MV.popMatrix();
}
var instructions = "mouse : rotate view\n"
+ "mouse + ctrl : zoom\n"
+ "scroll : zoom\n"
+ "shift (command on mac) + scroll: expand/contract\n"
+ "'e' : expand\n"
+ "'c' : contract\n"
+ "'i' : inspect unit cell makeup\n"
+ "'t' : translucent view\n"
+ "'r' : coordination view\n"
+ "'s' : single cell view\n"
+ "'n' : toggle cell coloring\n"
+ "'l' : toggle layer animation\n"
+ "shift + 'l' : lattice view\n";
function instruct() {
alert(instructions);
}
function expand() {
Scene.expand();
}
function contract() {
Scene.contract();
}
function layer() {
goToLattice();
Scene.toggleLayers();
}
function goToCrystal(crystalType) {
if(crystalType == 5) {
$('#legendText').show();
$('#crystalSelector').val('-1');
$('#displaySelector').hide();
}
else {
$('#legendText').hide();
$('#displaySelector').show();
}
Scene.goToCrystal(crystalType);
document.getElementById("crystalType").innerHTML = Scene.getCrystalName();
}
function about() {
if ($('#aboutText').is(":visible")) {
$('#aboutText').hide();
$('#simulation').show();
} else {
$('#aboutText').show();
$('#simulation').hide();
}
}
function changeCrystal(value) {
goToCrystal(value);
if($('#displaySelector').val() == 3) {
Scene.activateCoord($('displaySelector'), value);
}
}
function showDisplay(value) {
if(value == "0") {
goToLattice();
}
else if(value == "1") {
Scene.toggleTranslucency();
}
else if(value == "2") {
Scene.toggleInspection();
}
else if(value == "3") {
Scene.activateCoord($('#displaySelector'), $('#crystalSelector').val());
}
else if(value == "4") {
Scene.toggleSingle();
}
}
function goToLattice() {
Scene.goToLattice();
// change display selector back to lattice
$('#displaySelector').val('0');
}
function amuse() {
window.open('https://www.inorganicventures.com/fun-chemists');
}
function color() {
Scene.toggleColor();
}
</script>
</head>
<body onload="webGLStart();">
<div id="simulation">
<div id="navigation">
<p>Lattice Structures</p>
</div>
<div id="cells">
<center>
<button id="jokes" onclick="amuse()">Amuse me</button>
<button id="instructions" onclick="instruct()" type="button">Key Controls</button>
<select id="crystalSelector" onchange="changeCrystal(value)">
<option value="-1" disabled>--- Select a Lattice ---</option>
<option value="0" selected>Simple Cubic</option>
<option value="1">Body-Centered Cubic</option>
<option value="2">Face-Centered Cubic</option>
<option value="3">Sodium Chloride</option>
<option value="4">Calcium Fluoride</option>
<!-- <option value="6">HCP</option>-->
</select>
<button id="legend" onclick="goToCrystal(5)" type="button">Legend</button>
<button id="about" onclick="about()" type="button">About...</button>
</center>
</div>
<div id="container">
<center>
<canvas id="canvas" width="900px" height="675"></canvas>
<div id="legendText">
<center>
<p id="Ca"><strong>Calcium</strong></p>
<p id="F"><strong>Fluoride</strong></p>
<p id="Na"><strong>Sodium</strong></p>
<p id="Cl"><strong>Chloride</strong></p>
</center>
</div>
<p id="crystalType">Simple Cubic</p>
<p id="controlButtons">
<button id="expand" onclick="expand()" type="button">Expand</button>
<button id="contract" onclick="contract()" type="button">Contract</button>
<select id="displaySelector" onchange="showDisplay(value)">
<option selected value="0">Lattice</option>
<option value="1">Translucency</option>
<option value="2">Inspect</option>
<option value="3">Coordination</option>
<option value="4">Single</option>
</select>
<button id="layer" onclick="layer()" type="button">Layering</button>
<button id="color" onclick="color()" type="button">Coloring</button>
</p>
</center>
</div>
</div>
<center><div id="aboutText">
<center><h1>About</h1></center>
<p>
This is a Unit Cell Visualization simulation designed for use in
CHEM 124/127 at Cal Poly. The simulation is designed with student
interaction in mind, and provides many features to facilitate
student's understanding of concepts relative to lattice structures.
</p>
<p>
This is an open source project. It is developed in JavaScript,
using WebGL for all graphics. The project's code is open source
and currently resides
<a href="https://github.com/smrtalec95/UnitCellVisualizer">on Github</a>.
</p>
<center><h1>Contributors</h1></center>
<h2>Dr. Zahra Alghoul</h2>
<p>
Initial project specifications, and Chemistry knowledge. Ensured the
simulation's displays were accurate to their real world
counterparts. Specified simulation features.
</p>
<h2>Dr. Zoe Wood</h2>
<p>
Initial project specifications, and Graphics
knowledge. Oversaw Corbin's work on the simulation as his senior
project advisor, as well as oversaw Alec's work on the simulation
as his final project for CPE 471, Into to Computer Graphics.
</p>
<h2>Corbin Gruber</h2>
<p>
Initial project design and implementation. Created initial design
for the simulation. Implementation and testing. Created the SC, BCC,
and FCC simulations, along with expand, contract, rotations,
zooming, translucency, inspection, and layering views. Original
control schema involving primarily keystroke controls, along with
mouse movement for rotating the views.
</p>
<h2>Alec James</h2>
<p>
Updated project design and implementation. Added on
Sodium Chloride and Calcium Fluoride along with all features
implemented by Corbin in the simple crystal types. Added on
coordination number views for the simple crystal types. Updated
control schema using buttons and dropdowns for easier navigation
and control, as well as improved zooming and expand/contract controls.
Added option to change lattice coloring to deactivated, colored
fractional atoms (on FCC), and deactivate ions (for NaCl and CaF2).
</p>
<center><h1>Special thanks</h1></center>
<p>
Thanks to Dr. Gregory Scott for putting the simulation under
Cal Poly's chemistry department site, and keeping it updated for
all future modifications.
</p>
<button id="return" onclick="about()">Return</button>
</div></center>
</body>
</html>