Fix rotation speed

This commit is contained in:
Tristan Daniël Maat 2022-08-12 23:25:41 +01:00
parent 0a357f0109
commit 14d1f71b2b
Signed by: tlater
GPG key ID: 49670FD774E43268

View file

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