diff --git a/src/camera.ts b/src/camera.ts new file mode 100644 index 0000000..4eea6cb --- /dev/null +++ b/src/camera.ts @@ -0,0 +1,31 @@ +import {mat4, vec3, quat, mat3} from "gl-matrix"; + +export class Camera{ + pos:vec3; + rot:quat; + constructor(pos:vec3,rot?:quat){ + this.pos = pos; + if(rot == undefined){ + const lookAt = mat4.lookAt(mat4.create(),this.pos,[0,0,0],[0,0,1]) + const rotMat = mat3.fromMat4(mat3.create(),lookAt); + this.rot = quat.fromMat3(quat.create(), rotMat); + } + else{ + this.rot = rot; + } + } + rotateRight(rad:number){ + quat.rotateY(this.rot,this.rot,rad); + } + rotateUp(rad:number){ + quat.rotateX(this.rot,this.rot,rad); + } + rotateClockwise(rad:number){ + quat.rotateZ(this.rot,this.rot,rad); + } + getViewMat(){ + const r = mat4.fromQuat(mat4.create(),this.rot); + mat4.translate(r,r,this.pos); + return r; + } +}; \ No newline at end of file