From 9f422c80917db7b553ba685bb58afefc74737c05 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Mon, 26 Jan 2026 12:42:36 -0800 Subject: [PATCH] Simplify vec3 usage. There were lots of superfluous calls to `vec3.fromValues` and `vec3.create`. The library is designed to accept native arrays to be easy to use and the code gets simpler. --- meshes/mesh.ts | 4 ++-- sample/a-buffer/main.ts | 6 +++--- sample/cornell/common.ts | 12 ++++-------- sample/cubemap/main.ts | 13 ++++--------- sample/deferredRendering/main.ts | 10 +++++----- sample/fractalCube/main.ts | 11 +++-------- sample/instancedCube/main.ts | 22 ++++++++-------------- sample/normalMap/main.ts | 6 +++--- sample/particles/main.ts | 4 ++-- sample/primitivePicking/main.ts | 6 +++--- sample/renderBundles/main.ts | 4 ++-- sample/reversedZ/main.ts | 20 +++++++++----------- sample/rotatingCube/main.ts | 11 +++-------- sample/shadowMapping/main.ts | 8 ++++---- sample/skinnedMesh/main.ts | 20 ++++++++++---------- sample/textRenderingMsdf/main.ts | 13 ++++--------- sample/texturedCube/main.ts | 11 +++-------- sample/timestampQuery/main.ts | 11 +++-------- sample/transparentCanvas/main.ts | 11 +++-------- sample/twoCubes/main.ts | 22 ++++++---------------- sample/worker/worker.ts | 11 +++-------- 21 files changed, 87 insertions(+), 149 deletions(-) diff --git a/meshes/mesh.ts b/meshes/mesh.ts index 0f4a42c7..e78f0434 100644 --- a/meshes/mesh.ts +++ b/meshes/mesh.ts @@ -74,7 +74,7 @@ export const getMeshPosAtIndex = (mesh: Mesh, index: number) => { index * mesh.vertexStride + 0, 3 ); - return vec3.fromValues(arr[0], arr[1], arr[2]); + return [arr[0], arr[1], arr[2]]; }; export const getMeshNormalAtIndex = (mesh: Mesh, index: number) => { @@ -83,7 +83,7 @@ export const getMeshNormalAtIndex = (mesh: Mesh, index: number) => { index * mesh.vertexStride + 3 * Float32Array.BYTES_PER_ELEMENT, 3 ); - return vec3.fromValues(arr[0], arr[1], arr[2]); + return [arr[0], arr[1], arr[2]]; }; export const getMeshUVAtIndex = (mesh: Mesh, index: number) => { diff --git a/sample/a-buffer/main.ts b/sample/a-buffer/main.ts index 9241c76f..0b894615 100644 --- a/sample/a-buffer/main.ts +++ b/sample/a-buffer/main.ts @@ -514,9 +514,9 @@ const configure = () => { 2000.0 ); - const upVector = vec3.fromValues(0, 1, 0); - const origin = vec3.fromValues(0, 0, 0); - const eyePosition = vec3.fromValues(0, 5, -100); + const upVector = [0, 1, 0]; + const origin = [0, 0, 0]; + const eyePosition = [0, 5, -100]; const rad = Math.PI * (Date.now() / 5000); const rotation = mat4.rotateY(mat4.translation(origin), rad); diff --git a/sample/cornell/common.ts b/sample/cornell/common.ts index 4b0f2587..8c658068 100644 --- a/sample/cornell/common.ts +++ b/sample/cornell/common.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import commonWGSL from './common.wgsl'; /** @@ -80,13 +80,9 @@ export default class Common { const viewRotation = params.rotateCamera ? this.frame / 1000 : 0; const viewMatrix = mat4.lookAt( - vec3.fromValues( - Math.sin(viewRotation) * 15, - 5, - Math.cos(viewRotation) * 15 - ), - vec3.fromValues(0, 5, 0), - vec3.fromValues(0, 1, 0) + [Math.sin(viewRotation) * 15, 5, Math.cos(viewRotation) * 15], + [0, 5, 0], + [0, 1, 0] ); const mvp = mat4.multiply(projectionMatrix, viewMatrix); const invMVP = mat4.invert(mvp); diff --git a/sample/cubemap/main.ts b/sample/cubemap/main.ts index 28452a5f..615cd99a 100644 --- a/sample/cubemap/main.ts +++ b/sample/cubemap/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -193,7 +193,7 @@ const renderPassDescriptor: GPURenderPassDescriptor = { const aspect = canvas.width / canvas.height; const projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 1, 3000); -const modelMatrix = mat4.scaling(vec3.fromValues(1000, 1000, 1000)); +const modelMatrix = mat4.scaling([1000, 1000, 1000]); const modelViewProjectionMatrix = mat4.create(); const viewMatrix = mat4.identity(); @@ -204,13 +204,8 @@ const tmpMat4 = mat4.create(); function updateTransformationMatrix() { const now = Date.now() / 800; - mat4.rotate( - viewMatrix, - vec3.fromValues(1, 0, 0), - (Math.PI / 10) * Math.sin(now), - tmpMat4 - ); - mat4.rotate(tmpMat4, vec3.fromValues(0, 1, 0), now * 0.2, tmpMat4); + mat4.rotate(viewMatrix, [1, 0, 0], (Math.PI / 10) * Math.sin(now), tmpMat4); + mat4.rotate(tmpMat4, [0, 1, 0], now * 0.2, tmpMat4); mat4.multiply(tmpMat4, modelMatrix, modelViewProjectionMatrix); mat4.multiply( diff --git a/sample/deferredRendering/main.ts b/sample/deferredRendering/main.ts index 689d90d1..56819987 100644 --- a/sample/deferredRendering/main.ts +++ b/sample/deferredRendering/main.ts @@ -14,8 +14,8 @@ import { } from '../util'; const kMaxNumLights = 1024; -const lightExtentMin = vec3.fromValues(-50, -30, -50); -const lightExtentMax = vec3.fromValues(50, 50, 50); +const lightExtentMin = [-50, -30, -50]; +const lightExtentMax = [50, 50, 50]; const canvas = document.querySelector('canvas') as HTMLCanvasElement; const adapter = await navigator.gpu?.requestAdapter({ @@ -458,9 +458,9 @@ const lightsBufferComputeBindGroup = device.createBindGroup({ //-------------------- // Scene matrices -const eyePosition = vec3.fromValues(0, 50, -100); -const upVector = vec3.fromValues(0, 1, 0); -const origin = vec3.fromValues(0, 0, 0); +const eyePosition = [0, 50, -100]; +const upVector = [0, 1, 0]; +const origin = [0, 0, 0]; const projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 1, 2000.0); diff --git a/sample/fractalCube/main.ts b/sample/fractalCube/main.ts index 5220d160..e9f668a4 100644 --- a/sample/fractalCube/main.ts +++ b/sample/fractalCube/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -158,14 +158,9 @@ const modelViewProjectionMatrix = mat4.create(); function getTransformationMatrix() { const viewMatrix = mat4.identity(); - mat4.translate(viewMatrix, vec3.fromValues(0, 0, -4), viewMatrix); + mat4.translate(viewMatrix, [0, 0, -4], viewMatrix); const now = Date.now() / 1000; - mat4.rotate( - viewMatrix, - vec3.fromValues(Math.sin(now), Math.cos(now), 0), - 1, - viewMatrix - ); + mat4.rotate(viewMatrix, [Math.sin(now), Math.cos(now), 0], 1, viewMatrix); mat4.multiply(projectionMatrix, viewMatrix, modelViewProjectionMatrix); diff --git a/sample/instancedCube/main.ts b/sample/instancedCube/main.ts index f2106ab5..12c9f57c 100644 --- a/sample/instancedCube/main.ts +++ b/sample/instancedCube/main.ts @@ -1,4 +1,4 @@ -import { mat4, Mat4, vec3 } from 'wgpu-matrix'; +import { mat4, Mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -131,18 +131,16 @@ const step = 4.0; let m = 0; for (let x = 0; x < xCount; x++) { for (let y = 0; y < yCount; y++) { - modelMatrices[m] = mat4.translation( - vec3.fromValues( - step * (x - xCount / 2 + 0.5), - step * (y - yCount / 2 + 0.5), - 0 - ) - ); + modelMatrices[m] = mat4.translation([ + step * (x - xCount / 2 + 0.5), + step * (y - yCount / 2 + 0.5), + 0, + ]); m++; } } -const viewMatrix = mat4.translation(vec3.fromValues(0, 0, -12)); +const viewMatrix = mat4.translation([0, 0, -12]); const tmpMat4 = mat4.create(); @@ -156,11 +154,7 @@ function updateTransformationMatrix() { for (let y = 0; y < yCount; y++) { mat4.rotate( modelMatrices[i], - vec3.fromValues( - Math.sin((x + 0.5) * now), - Math.cos((y + 0.5) * now), - 0 - ), + [Math.sin((x + 0.5) * now), Math.cos((y + 0.5) * now), 0], 1, tmpMat4 ); diff --git a/sample/normalMap/main.ts b/sample/normalMap/main.ts index ae7e8e25..38c1931c 100644 --- a/sample/normalMap/main.ts +++ b/sample/normalMap/main.ts @@ -329,11 +329,11 @@ function frame() { ]); // Update mapInfoBuffer - const lightPosWS = vec3.create( + const lightPosWS = [ settings.lightPosX, settings.lightPosY, - settings.lightPosZ - ); + settings.lightPosZ, + ]; const lightPosVS = vec3.transformMat4(lightPosWS, viewMatrix); const mode = getMode(); device.queue.writeBuffer( diff --git a/sample/particles/main.ts b/sample/particles/main.ts index 43a54fc4..89237ff6 100644 --- a/sample/particles/main.ts +++ b/sample/particles/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { GUI } from 'dat.gui'; import particleWGSL from './particle.wgsl'; @@ -388,7 +388,7 @@ function frame() { device.queue.writeBuffer(simulationUBOBuffer, 0, uboDataF32); mat4.identity(view); - mat4.translate(view, vec3.fromValues(0, 0, -3), view); + mat4.translate(view, [0, 0, -3], view); mat4.rotateX(view, Math.PI * -0.2, view); mat4.multiply(projection, view, mvp); diff --git a/sample/primitivePicking/main.ts b/sample/primitivePicking/main.ts index 24b88a1d..e7eceb36 100644 --- a/sample/primitivePicking/main.ts +++ b/sample/primitivePicking/main.ts @@ -295,9 +295,9 @@ const pickBindGroup = device.createBindGroup({ //-------------------- // Scene matrices -const eyePosition = vec3.fromValues(0, 12, -25); -const upVector = vec3.fromValues(0, 1, 0); -const origin = vec3.fromValues(0, 0, 0); +const eyePosition = [0, 12, -25]; +const upVector = [0, 1, 0]; +const origin = [0, 0, 0]; const projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 1, 2000.0); diff --git a/sample/renderBundles/main.ts b/sample/renderBundles/main.ts index 46c30494..2ec90b4a 100644 --- a/sample/renderBundles/main.ts +++ b/sample/renderBundles/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { GUI } from 'dat.gui'; import { createSphereMesh, SphereLayout } from '../../meshes/sphere'; import Stats from 'stats.js'; @@ -293,7 +293,7 @@ const frameBindGroup = device.createBindGroup({ function getTransformationMatrix() { const viewMatrix = mat4.identity(); - mat4.translate(viewMatrix, vec3.fromValues(0, 0, -4), viewMatrix); + mat4.translate(viewMatrix, [0, 0, -4], viewMatrix); const now = Date.now() / 1000; // Tilt the view matrix so the planet looks like it's off-axis. mat4.rotateZ(viewMatrix, Math.PI * 0.1, viewMatrix); diff --git a/sample/reversedZ/main.ts b/sample/reversedZ/main.ts index 91b7df49..b6ca1b56 100644 --- a/sample/reversedZ/main.ts +++ b/sample/reversedZ/main.ts @@ -1,4 +1,4 @@ -import { mat4, Mat4, vec3 } from 'wgpu-matrix'; +import { mat4, Mat4 } from 'wgpu-matrix'; import { GUI } from 'dat.gui'; import vertexWGSL from './vertex.wgsl'; @@ -472,20 +472,18 @@ for (let x = 0; x < xCount; x++) { const z = -800 * m; const s = 1 + 50 * m; - modelMatrices[m] = mat4.translation( - vec3.fromValues( - x - xCount / 2 + 0.5, - (4.0 - 0.2 * z) * (y - yCount / 2 + 1.0), - z - ) - ); - mat4.scale(modelMatrices[m], vec3.fromValues(s, s, s), modelMatrices[m]); + modelMatrices[m] = mat4.translation([ + x - xCount / 2 + 0.5, + (4.0 - 0.2 * z) * (y - yCount / 2 + 1.0), + z, + ]); + mat4.scale(modelMatrices[m], [s, s, s], modelMatrices[m]); m++; } } -const viewMatrix = mat4.translation(vec3.fromValues(0, 0, -12)); +const viewMatrix = mat4.translation([0, 0, -12]); const aspect = (0.5 * canvas.width) / canvas.height; // wgpu-matrix perspective doesn't handle zFar === Infinity now. @@ -513,7 +511,7 @@ function updateTransformationMatrix() { for (let i = 0, m = 0; i < numInstances; i++, m += matrixFloatCount) { mat4.rotate( modelMatrices[i], - vec3.fromValues(Math.sin(now), Math.cos(now), 0), + [Math.sin(now), Math.cos(now), 0], (Math.PI / 180) * 30, tmpMat4 ); diff --git a/sample/rotatingCube/main.ts b/sample/rotatingCube/main.ts index f33d212d..c5fbed33 100644 --- a/sample/rotatingCube/main.ts +++ b/sample/rotatingCube/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -136,14 +136,9 @@ const modelViewProjectionMatrix = mat4.create(); function getTransformationMatrix() { const viewMatrix = mat4.identity(); - mat4.translate(viewMatrix, vec3.fromValues(0, 0, -4), viewMatrix); + mat4.translate(viewMatrix, [0, 0, -4], viewMatrix); const now = Date.now() / 1000; - mat4.rotate( - viewMatrix, - vec3.fromValues(Math.sin(now), Math.cos(now), 0), - 1, - viewMatrix - ); + mat4.rotate(viewMatrix, [Math.sin(now), Math.cos(now), 0], 1, viewMatrix); mat4.multiply(projectionMatrix, viewMatrix, modelViewProjectionMatrix); diff --git a/sample/shadowMapping/main.ts b/sample/shadowMapping/main.ts index 18c14058..0dcd4318 100644 --- a/sample/shadowMapping/main.ts +++ b/sample/shadowMapping/main.ts @@ -258,9 +258,9 @@ const modelBindGroup = device.createBindGroup({ entries: [{ binding: 0, resource: modelUniformBuffer }], }); -const eyePosition = vec3.fromValues(0, 50, -100); -const upVector = vec3.fromValues(0, 1, 0); -const origin = vec3.fromValues(0, 0, 0); +const eyePosition = [0, 50, -100]; +const upVector = [0, 1, 0]; +const origin = [0, 0, 0]; const projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 1, 2000.0); @@ -299,7 +299,7 @@ const modelMatrix = mat4.translation([0, -45, 0]); // Rotates the camera around the origin based on time. function getCameraViewProjMatrix() { - const eyePosition = vec3.fromValues(0, 50, -100); + const eyePosition = [0, 50, -100]; const rad = Math.PI * (Date.now() / 2000); const rotation = mat4.rotateY(mat4.translation(origin), rad); diff --git a/sample/skinnedMesh/main.ts b/sample/skinnedMesh/main.ts index 6dd76e28..d0ce2c04 100644 --- a/sample/skinnedMesh/main.ts +++ b/sample/skinnedMesh/main.ts @@ -2,7 +2,7 @@ import { GUI } from 'dat.gui'; import { convertGLBToJSONAndBinary, GLTFSkin } from './glbUtils'; import gltfWGSL from './gltf.wgsl'; import gridWGSL from './grid.wgsl'; -import { Mat4, mat4, quat, vec3 } from 'wgpu-matrix'; +import { Mat4, mat4, quat } from 'wgpu-matrix'; import { createBindGroupCluster } from '../bitonicSort/utils'; import { createSkinnedGridBuffers, @@ -323,17 +323,17 @@ function getViewMatrix() { if (settings.object === 'Skinned Grid') { mat4.translate( viewMatrix, - vec3.fromValues( + [ settings.cameraX * settings.objectScale, settings.cameraY * settings.objectScale, - settings.cameraZ - ), + settings.cameraZ, + ], viewMatrix ); } else { mat4.translate( viewMatrix, - vec3.fromValues(settings.cameraX, settings.cameraY, settings.cameraZ), + [settings.cameraX, settings.cameraY, settings.cameraZ], viewMatrix ); } @@ -342,11 +342,11 @@ function getViewMatrix() { function getModelMatrix() { const modelMatrix = mat4.identity(); - const scaleVector = vec3.fromValues( + const scaleVector = [ settings.objectScale, settings.objectScale, - settings.objectScale - ); + settings.objectScale, + ]; mat4.scale(modelMatrix, scaleVector, modelMatrix); if (settings.object === 'Whale') { mat4.rotateY(modelMatrix, (Date.now() / 1000) * 0.5, modelMatrix); @@ -389,9 +389,9 @@ const skinnedGridRenderPassDescriptor: GPURenderPassDescriptor = { const animSkinnedGrid = (boneTransforms: Mat4[], angle: number) => { const m = mat4.identity(); mat4.rotateZ(m, angle, boneTransforms[0]); - mat4.translate(boneTransforms[0], vec3.create(4, 0, 0), m); + mat4.translate(boneTransforms[0], [4, 0, 0], m); mat4.rotateZ(m, angle, boneTransforms[1]); - mat4.translate(boneTransforms[1], vec3.create(4, 0, 0), m); + mat4.translate(boneTransforms[1], [4, 0, 0], m); mat4.rotateZ(m, angle, boneTransforms[2]); }; diff --git a/sample/textRenderingMsdf/main.ts b/sample/textRenderingMsdf/main.ts index f169f42e..8041ef79 100644 --- a/sample/textRenderingMsdf/main.ts +++ b/sample/textRenderingMsdf/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -260,16 +260,11 @@ const start = Date.now(); function getTransformationMatrix() { const now = Date.now() / 5000; const viewMatrix = mat4.identity(); - mat4.translate(viewMatrix, vec3.fromValues(0, 0, -5), viewMatrix); + mat4.translate(viewMatrix, [0, 0, -5], viewMatrix); const modelMatrix = mat4.identity(); - mat4.translate(modelMatrix, vec3.fromValues(0, 2, -3), modelMatrix); - mat4.rotate( - modelMatrix, - vec3.fromValues(Math.sin(now), Math.cos(now), 0), - 1, - modelMatrix - ); + mat4.translate(modelMatrix, [0, 2, -3], modelMatrix); + mat4.rotate(modelMatrix, [Math.sin(now), Math.cos(now), 0], 1, modelMatrix); // Update the matrix for the cube mat4.multiply(projectionMatrix, viewMatrix, modelViewProjectionMatrix); diff --git a/sample/texturedCube/main.ts b/sample/texturedCube/main.ts index 29757429..5c13798a 100644 --- a/sample/texturedCube/main.ts +++ b/sample/texturedCube/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -167,14 +167,9 @@ const modelViewProjectionMatrix = mat4.create(); function getTransformationMatrix() { const viewMatrix = mat4.identity(); - mat4.translate(viewMatrix, vec3.fromValues(0, 0, -4), viewMatrix); + mat4.translate(viewMatrix, [0, 0, -4], viewMatrix); const now = Date.now() / 1000; - mat4.rotate( - viewMatrix, - vec3.fromValues(Math.sin(now), Math.cos(now), 0), - 1, - viewMatrix - ); + mat4.rotate(viewMatrix, [Math.sin(now), Math.cos(now), 0], 1, viewMatrix); mat4.multiply(projectionMatrix, viewMatrix, modelViewProjectionMatrix); diff --git a/sample/timestampQuery/main.ts b/sample/timestampQuery/main.ts index 4d5686c2..313ff32e 100644 --- a/sample/timestampQuery/main.ts +++ b/sample/timestampQuery/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -171,14 +171,9 @@ const modelViewProjectionMatrix = mat4.create(); function getTransformationMatrix() { const viewMatrix = mat4.identity(); - mat4.translate(viewMatrix, vec3.fromValues(0, 0, -4), viewMatrix); + mat4.translate(viewMatrix, [0, 0, -4], viewMatrix); const now = Date.now() / 1000; - mat4.rotate( - viewMatrix, - vec3.fromValues(Math.sin(now), Math.cos(now), 0), - 1, - viewMatrix - ); + mat4.rotate(viewMatrix, [Math.sin(now), Math.cos(now), 0], 1, viewMatrix); mat4.multiply(projectionMatrix, viewMatrix, modelViewProjectionMatrix); diff --git a/sample/transparentCanvas/main.ts b/sample/transparentCanvas/main.ts index 6f365148..44ba453f 100644 --- a/sample/transparentCanvas/main.ts +++ b/sample/transparentCanvas/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -132,14 +132,9 @@ const modelViewProjectionMatrix = mat4.create(); function getTransformationMatrix() { const viewMatrix = mat4.identity(); - mat4.translate(viewMatrix, vec3.fromValues(0, 0, -4), viewMatrix); + mat4.translate(viewMatrix, [0, 0, -4], viewMatrix); const now = Date.now() / 1000; - mat4.rotate( - viewMatrix, - vec3.fromValues(Math.sin(now), Math.cos(now), 0), - 1, - viewMatrix - ); + mat4.rotate(viewMatrix, [Math.sin(now), Math.cos(now), 0], 1, viewMatrix); mat4.multiply(projectionMatrix, viewMatrix, modelViewProjectionMatrix); diff --git a/sample/twoCubes/main.ts b/sample/twoCubes/main.ts index 25b852b2..c2c1cfc8 100644 --- a/sample/twoCubes/main.ts +++ b/sample/twoCubes/main.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -159,11 +159,11 @@ const renderPassDescriptor: GPURenderPassDescriptor = { const aspect = canvas.width / canvas.height; const projectionMatrix = mat4.perspective((2 * Math.PI) / 5, aspect, 1, 100.0); -const modelMatrix1 = mat4.translation(vec3.create(-2, 0, 0)); -const modelMatrix2 = mat4.translation(vec3.create(2, 0, 0)); +const modelMatrix1 = mat4.translation([-2, 0, 0]); +const modelMatrix2 = mat4.translation([2, 0, 0]); const modelViewProjectionMatrix1 = mat4.create(); const modelViewProjectionMatrix2 = mat4.create(); -const viewMatrix = mat4.translation(vec3.fromValues(0, 0, -7)); +const viewMatrix = mat4.translation([0, 0, -7]); const tmpMat41 = mat4.create(); const tmpMat42 = mat4.create(); @@ -171,18 +171,8 @@ const tmpMat42 = mat4.create(); function updateTransformationMatrix() { const now = Date.now() / 1000; - mat4.rotate( - modelMatrix1, - vec3.fromValues(Math.sin(now), Math.cos(now), 0), - 1, - tmpMat41 - ); - mat4.rotate( - modelMatrix2, - vec3.fromValues(Math.cos(now), Math.sin(now), 0), - 1, - tmpMat42 - ); + mat4.rotate(modelMatrix1, [Math.sin(now), Math.cos(now), 0], 1, tmpMat41); + mat4.rotate(modelMatrix2, [Math.cos(now), Math.sin(now), 0], 1, tmpMat42); mat4.multiply(viewMatrix, tmpMat41, modelViewProjectionMatrix1); mat4.multiply( diff --git a/sample/worker/worker.ts b/sample/worker/worker.ts index 69151da5..acd15c4a 100644 --- a/sample/worker/worker.ts +++ b/sample/worker/worker.ts @@ -1,4 +1,4 @@ -import { mat4, vec3 } from 'wgpu-matrix'; +import { mat4 } from 'wgpu-matrix'; import { cubeVertexArray, @@ -159,14 +159,9 @@ async function init(canvas) { function getTransformationMatrix() { const viewMatrix = mat4.identity(); - mat4.translate(viewMatrix, vec3.fromValues(0, 0, -4), viewMatrix); + mat4.translate(viewMatrix, [0, 0, -4], viewMatrix); const now = Date.now() / 1000; - mat4.rotate( - viewMatrix, - vec3.fromValues(Math.sin(now), Math.cos(now), 0), - 1, - viewMatrix - ); + mat4.rotate(viewMatrix, [Math.sin(now), Math.cos(now), 0], 1, viewMatrix); mat4.multiply(projectionMatrix, viewMatrix, modelViewProjectionMatrix);