diff options
[WGL/P] Removed old black hole logic, started rework on movement, proper forward, backward, up, down movement and horizontal mouse movement
1 files changed, 12 insertions, 72 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/Project.html | 84 |
diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html index 627e21a..cacc8bc 100644 --- a/Year 2/Computer Graphics with WebGL/Project/Project.html +++ b/Year 2/Computer Graphics with WebGL/Project/Project.html @@ -13,7 +13,7 @@ body { }
canvas {
display: block;
- position: fixed;
+ pos: fixed;
left: 0;
top: 0;
width: 100vw;
@@ -23,62 +23,20 @@ canvas { </style>
<script>
- /*
- * Keyboard navigation
- */
-
- const MOVE_SPEED = 0.1;
- const ROTATION_SPEED = 0.05;
-
- var position = [10, 0, 3];
- var lookingVec = [-MOVE_SPEED,0,-0.02];
- var movementVec = [0,0,0];
-
- function vecSum(a, b) {
- return [a[0]+b[0], a[1]+b[1], a[2]+b[2]];
- }
- function vecSub(a, b) {
- return [a[0]-b[0], a[1]-b[1], a[2]-b[2]];
- }
-
- addEventListener("keydown", (event) => {
- switch (event.key) {
- case 'ArrowUp':
- case 'w':
- position = vecSum(position, lookingVec);
- break;
- case 'ArrowDown':
- case 's':
- position = vecSub(position, lookingVec);
- break;
- case 'ArrowLeft':
- case 'a':
- position = [0,-MOVE_SPEED,0];
- break;
- case 'ArrowRight':
- case 'd':
- position = [0,MOVE_SPEED,0];
- break;
- }
- });
-
- addEventListener("mousemove", (event) => {
- var screenCenterX = document.body.clientWidth / 2;
- var screenCenterY = document.body.clientHeight / 2;
-
- // lookingVec = [];
- });
-
+ </script>
+ <script src="spaceship.js"></script>
+ <script>
/*
* WebGL
*/
function start()
{
- var canvas = document.getElementById("picasso");
+ canvas = document.getElementById("picasso");
canvas.addEventListener('webglcontextlost',function(event){event.preventDefault();},false);
canvas.addEventListener('webglcontextrestored',function(){init();},false);
+ mouseInit();
init();
}
@@ -94,9 +52,6 @@ canvas { gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
- // Black Hole variables
- gl.vertexAttrib1f(aBH, 0);
-
identity();
perspective(30,gl.canvas.width/gl.canvas.height,1,40000);
gl.uniform1i(uUseNormalMatrix,false);
@@ -105,29 +60,16 @@ canvas { gl.uniform3f(uDiffuseColor,1,1,1);
gl.uniform3f(uLightDir,0,0,-1);
- blackHole = new BlackHole([0,0,0], 1);
- planets = [new Sphere([-3,0,0.5], 0.5), new Sphere([-3,0,-1.2], 0.5), new Sphere([-3,0,-2.4], 0.5)];
+ planets = [new Sphere([1000,0,1000], 50),
+ new Sphere([1000,0,-1000], 50),
+ new Sphere([700,0,1000], 40),
+ new Sphere([0,0,0], 100),
+ new Sphere([1000, 0, -30], 20)];
planets.forEach((p) => p.color = [1,0,0]);
resizeglcanvas();
}
- BlackHole = function(center, size) {
- this.sphere = new Sphere(center, size);
- this.shwarzschildRadius = 0.5; // bad
- }
-
- BlackHole.prototype.draw = function() {
- gl.vertexAttrib1f(aBH, 1);
- gl.vertexAttrib1f(aSR, this.shwarzschildRadius);
- gl.vertexAttrib1f(aR, this.sphere.size + 0.03);
- gl.vertexAttrib3f(aBHXYZ, ...this.sphere.center);
-
- this.sphere.draw();
-
- gl.vertexAttrib1f(aBH, 0);
- }
-
function resizeglcanvas() {
gl.canvas.width = gl.canvas.offsetWidth;
gl.canvas.height = gl.canvas.offsetHeight;
@@ -144,13 +86,11 @@ canvas { {
gl.clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT);
- lookAt(position, vecSum(position, lookingVec), [0,0,1]);
+ lookUpdate();
planets.forEach((p) => p.draw());
- blackHole.draw();
requestAnimationFrame(drawFrame);
}
-
</script>
</head>
|
