Fix rotation speed

pull/6/head
Tristan Daniël Maat 2022-08-12 23:25:41 +01:00
parent 0a357f0109
commit 14d1f71b2b
Signed by: tlater
GPG Key ID: 49670FD774E43268
1 changed files with 9 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import { Cube } from "./cube";
import vertexSource from "./shaders/vertices.glsl";
import fragmentSource from "./shaders/fragments.glsl";
const ROTATION_SPEED = 0.0005;
const ROTATION_SPEED = 0.25;
const BACKGROUND_COLOR = [0.0588235294118, 0.0588235294118, 0.0588235294118];
class RendererError extends Error {}
@ -20,6 +20,8 @@ class Renderer {
private lastFrameTime: number;
private dTime: number;
private rotation: number;
private buffers: {
indices?: WebGLBuffer;
positions?: WebGLBuffer;
@ -47,6 +49,7 @@ class Renderer {
this.lastFrameTime = 0;
this.dTime = 0;
this.rotation = 0;
this.buffers = {};
}
@ -161,14 +164,12 @@ class Renderer {
}
updateMatrices(gl: WebGLRenderingContext, shader: Shader) {
this.rotation += (this.dTime / 1000.0) * ROTATION_SPEED;
const modelViewMatrix = mat4.create();
mat4.translate(modelViewMatrix, modelViewMatrix, [0.0, 0.0, -1.5]);
mat4.rotateX(modelViewMatrix, modelViewMatrix, Math.PI / 6);
mat4.rotateY(
modelViewMatrix,
modelViewMatrix,
this.lastFrameTime * ROTATION_SPEED
);
mat4.translate(modelViewMatrix, modelViewMatrix, [0.0, 0.025, -1.2]);
mat4.rotateX(modelViewMatrix, modelViewMatrix, Math.PI / 16);
mat4.rotateY(modelViewMatrix, modelViewMatrix, this.rotation);
mat4.translate(modelViewMatrix, modelViewMatrix, [-1.0, 0.0, 0.0]);
gl.uniformMatrix4fv(
shader.getUniform("uModelViewMatrix"),