From 9f4a12aae501548efd4f1721b3cd0576dc5fdb97 Mon Sep 17 00:00:00 2001 From: s Date: Wed, 18 Sep 2024 00:49:29 +0900 Subject: [PATCH] :sparkles: implement rotationY and rotationX --- src/webgl.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/webgl.ts b/src/webgl.ts index 3878f07..6a7070f 100644 --- a/src/webgl.ts +++ b/src/webgl.ts @@ -189,6 +189,26 @@ const m4 = { 0, 0, 0, 1 ]) }, + rotationY: (degrees: number) => { + const cos = Math.cos(degrees / 180 * Math.PI) + const sin = Math.sin(degrees / 180 * Math.PI) + return new Float32Array([ + cos, 0, sin, 0, + 0, 1, 0, 0, + -sin, 0, cos, 0, + 0, 0, 0, 1 + ]) + }, + rotationX: (degrees: number) => { + const cos = Math.cos(degrees / 180 * Math.PI) + const sin = Math.sin(degrees / 180 * Math.PI) + return new Float32Array([ + 1, 0, 0, 0, + 0, cos, -sin, 0, + 0, sin, cos, 0, + 0, 0, 0, 1 + ]) + }, dot: (m0: Float32Array, m1: Float32Array) => { const newMatrix = new Float32Array(16) for (let i = 0; i < 4; i++) { @@ -219,7 +239,7 @@ const m4 = { return new Float32Array([ 2 / width, 0, 0, -1, 0, -2 / height, 0, 1, - 0, 0, 2 / depth, 0, + 0, 0, 2 / depth, 0, // imo it should be 1/depth instead of 2/depth as that way a triangle the len of the screen can rotate around Z without clipping 0, 0, 0, 1 // , 0, -1,