@giraphics/grpkggfx
Version:
40 lines (39 loc) • 1.28 kB
JavaScript
import { mat4, vec3 } from 'gl-matrix';
export class Camera {
constructor(aspect) {
this.x = 0;
this.y = 0;
this.z = 0;
this.rotX = 0;
this.rotY = 0;
this.rotZ = 0;
this.fovy = (2 * Math.PI) / 5;
this.aspect = 16 / 9;
this.near = 1;
this.far = 1000;
this.aspect = aspect;
}
getViewMatrix() {
const viewMatrix = mat4.create();
mat4.lookAt(viewMatrix, vec3.fromValues(this.x, this.y, this.z), vec3.fromValues(0, 0, 0), vec3.fromValues(0, 1, 0));
mat4.rotateX(viewMatrix, viewMatrix, this.rotX);
mat4.rotateY(viewMatrix, viewMatrix, this.rotY);
mat4.rotateZ(viewMatrix, viewMatrix, this.rotZ);
return viewMatrix;
}
getProjectionMatrix() {
const projectionMatrix = mat4.create();
mat4.perspective(projectionMatrix, this.fovy, this.aspect, this.near, this.far);
return projectionMatrix;
}
getCameraViewProjMatrix() {
const viewProjMatrix = mat4.create();
const view = this.getViewMatrix();
const proj = this.getProjectionMatrix();
mat4.multiply(viewProjMatrix, proj, view);
return viewProjMatrix;
}
hello() {
return "Hello from camera";
}
}