diff options
[WGL/P] Added a lot of comments and reworked formatting of certain code
1 files changed, 12 insertions, 4 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/Project.html | 16 |
diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html index a74b065..e43f213 100644 --- a/Year 2/Computer Graphics with WebGL/Project/Project.html +++ b/Year 2/Computer Graphics with WebGL/Project/Project.html @@ -77,10 +77,8 @@ body > div, #noscript { }
</style>
- <script src="spaceship.js"></script>
+ <script src="camera-movement.js"></script>
<script src="skybox.js"></script>
- <script src="star.js"></script>
- <script src="blackhole.js"></script>
<script src="level.js"></script>
<script>
/*
@@ -102,16 +100,19 @@ body > div, #noscript { function init()
{
+ /* Get WebGL stuff */
gl = getContext('picasso');
glprog = getProgram(vShader,fShader);
getVariables();
+ /* WebGL settings */
gl.enable(gl.DEPTH_TEST);
gl.clearColor(1,1,1,1);
// For proper transparency
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
+ /* Matricies (for color in shaders) */
identity();
gl.uniform1i(uUseNormalMatrix,false);
@@ -119,12 +120,17 @@ body > div, #noscript { gl.uniform3f(uDiffuseColor,1,1,1);
gl.uniform3f(uLightDir,0,0,-1);
+ /* Fragment shader settings */
+ gl.uniform3fv(uStarColor, STAR_COLOR);
gl.uniform4f(uBlack, 0,0,0,1);
gl.uniform4f(uBHBlack, 0,0,0,1);
gl.uniform1i(uDisableRayMarching, false);
+ /* Create physical objects */
skybox = new Skybox(10000, [0,0,0], undefined);
createLevels();
+
+ /* Since we have the gl context, run stuff that depend on it */
initMenu();
resizeglcanvas();
@@ -146,11 +152,13 @@ body > div, #noscript { var frames = 0;
function drawFrame()
{
+ /* Update time t */
if (startT == -1) { startT = Date.now(); t = 0; }
var candidat = Math.floor(Date.now() - startT) / 100; // tenths of a second
if (pauseAnimations) startT += (candidat - t)*100;
else t = candidat;
+ /* Update fps counter */
var now = Math.floor(Date.now() / 1000);
if (now - lastTime >= 1) {
fpsElem.innerText = Math.floor(frames / (now - lastTime));
@@ -161,8 +169,8 @@ body > div, #noscript { gl.clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT);
updateCamera();
- gl.uniform3fv(uEye, pos);
+ /* Draw scene objects */
if (!pauseAnimations || t == 0) animations.forEach((a) => a(t));
skybox.draw();
stars.forEach((s) => s.draw());
|
