-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebgl-camera-v1.0.min.js
6 lines (6 loc) · 1.3 KB
/
webgl-camera-v1.0.min.js
1
2
3
4
5
6
var CAMERA=(function(){CAMERA=function(fov,min,max){this.pos={x:0,y:0,z:-5,};this.look={x:0,y:0,z:1,};this.up={x:0,y:1,z:0,};this.fov=fov||Math.PI/4;this.zMin=min||0.1;this.zMax=max||1000};CAMERA.FollowFPS=function(object){if(!object.looking){console.error("ERROR: Please give object a property 'looking'.");return!1}
if(!object.pos){console.error("ERROR: Please give object a property 'pos'.");return!1}
this.pos.x=object.pos.x;this.pos.y=object.pos.y;this.pos.z=object.pos.z;this.look.x=object.pos.x+object.looking.x;this.look.y=object.pos.y+object.looking.y;this.look.z=object.pos.z+object.looking.z;if(object.fov){this.fov=object.fov}
return this};CAMERA.FollowTPS=function(object,dist){if(!object.looking){console.error("ERROR: Please give object a property 'looking'.");return!1}
if(!object.pos){console.error("ERROR: Please give object a property 'pos'.");return!1}
let magnitude=Math.hypot(object.looking.x,object.looking.y,object.looking.z);dist=dist||2.5;this.pos.x=object.pos.x-object.looking.x/magnitude*dist;this.pos.y=object.pos.y-object.looking.y/magnitude*dist;this.pos.z=object.pos.z-object.looking.z/magnitude*dist;this.look.x=object.pos.x;this.look.y=object.pos.y;this.look.z=object.pos.z;return this};CAMERA.prototype.FollowFPS=CAMERA.FollowFPS;CAMERA.prototype.FollowTPS=CAMERA.FollowTPS;return CAMERA})()