Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / Project / Project.html
diff options
context:
space:
mode:
Commitf5fa572ab70664129ae8c2d81665752f0f8f7f88 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-08-26 13:59:14 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-08-26 13:59:14 +0300
Filesc384599a302bf056c6ab82acf106783ad2c8c5e2 /Year 2/Computer Graphics with WebGL/Project/Project.html
uni-projects-f5fa572ab70664129ae8c2d81665752f0f8f7f88.tar
uni-projects-f5fa572ab70664129ae8c2d81665752f0f8f7f88.tar.gz
uni-projects-f5fa572ab70664129ae8c2d81665752f0f8f7f88.zip
Parent866b2608dfbc53dcd968bdf3261005a9e0be8b36 (diff)
[WGL/P] Properly implemented ray tracing, though there are issues
1 files changed, 23 insertions, 2 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/Project/Project.html25
diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html
index a97f94e..cf55554 100644
--- a/Year 2/Computer Graphics with WebGL/Project/Project.html
+++ b/Year 2/Computer Graphics with WebGL/Project/Project.html
@@ -78,6 +78,9 @@ h2 {
init();
}
+ const PERSPECTIVE_ANGLE = 30;
+ const PERSPECTIVE_NEAR = 1;
+
function init()
{
gl = getContext("picasso");
@@ -91,7 +94,7 @@ h2 {
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
identity();
- perspective(30,gl.canvas.width/gl.canvas.height,1,40000);
+ perspective(PERSPECTIVE_ANGLE,gl.canvas.width/gl.canvas.height,PERSPECTIVE_NEAR,40000);
gl.uniform1i(uUseNormalMatrix,false);
gl.uniform3f(uAmbientColor,0.3,0.3,0.3);
@@ -122,7 +125,16 @@ h2 {
gl.canvas.height = gl.canvas.offsetHeight;
gl.viewport(0,0,gl.canvas.width,gl.canvas.height);
- // gl.uniform2f(uViewPort, gl.canvas.width, gl.canvas.height);
+ // (Look at Presentation 6, Slide 21, the prespective projection diagram)
+ // Since we're gonna be raycasting, we need to know where the near side is and it's
+ // dimentions in our coordinate system, so we can offset the rays properly.
+ // First, we pass the viewPort to convert our pixel coordinates to percentage of the
+ // screen.
+ gl.uniform2f(uViewPort, gl.canvas.width, gl.canvas.height);
+ w = 2 * Math.tan(PERSPECTIVE_ANGLE / 360 * Math.PI) * PERSPECTIVE_NEAR;
+ // The height of the near wall is determined by the aspect ratio.
+ gl.uniform2f(uPerspSize, w, gl.canvas.height / gl.canvas.width * w);
+ gl.uniform1f(uPerspDist, PERSPECTIVE_NEAR);
drawFrame();
}
@@ -143,6 +155,15 @@ h2 {
requestAnimationFrame(drawFrame);
}
+ document.addEventListener('keypress', (e) => {
+ if (e.key == 'u') {
+ console.log(w);
+ console.log(w*gl.canvas.height / gl.canvas.width);
+ console.log(forward.toCartesian());
+ console.log(left.toCartesian());
+ console.log(up.toCartesian());
+ }
+ });
</script>
</head>