add camera
This commit is contained in:
		
							parent
							
								
									2795ee3ada
								
							
						
					
					
						commit
						72f9691c67
					
				
					 1 changed files with 31 additions and 0 deletions
				
			
		
							
								
								
									
										31
									
								
								src/camera.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/camera.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue