📄 camera3d.as
字号:
/*******************ENGLISHproject: 3d engineby: ivan ivanoff (www.i2off.org)based on the work made by : stuart schoneveld (www.illogicz.com) email: avatar@i2off.orgapologies: to my wife and kids for supporting me. to jorge, valerialaura & mariano, for bothering them all the time. thx to valerialaura for the english translation--------------------ABOUT THIS CLASSAn instance of this class controls what is shown on the screen. from which angle, position, etc.--------------------ABOUT IT'S PUBLIC METHODS-setFieldOfView (a) sets the field of view. this modifies the way you see the situation.-getFieldOfView () returns the actual field of view-setCoordinates (px,py,pz) sets camera position. px, py and pz are values of position on every axis-getCoordinates () returns the position of the camera on an object with x,y and z properties ({x:px, y:py, z:pz})-setRotation (rx,ry) sets camera rotation. rx and ry are values of rotation in radians.-getRotation() returns camera rotation values on an object with x and y properties ({x:rx, y:ry})-moveBy(N) moves the camera N steps forward on the direction it was. if N is a negative number, it goes backwards.-strafeBy(N) moves the camera on it's side. N is the distance.-setPivot(b, p) sets a model as pivot for the camera. This forces the camera to point it's way. b: boolean saying whether the camera has a pivot or not. p: the model to use for pivotting. -------------------- ABOUT IT'S PUBLIC PROPERTIES-doPivot whether the camera has a pivot or not-pivot the model being used for pivotting-doLink whether the camera is linked to a model or not. if it is, the camera moves according to that model-link the linked model.-linkOffset distance offset beetwen the camera and the linked model.-doLinkRota if linked to a model, this property indicates whether the camera rotates according to the model or not.-linkRotaOffsetZ distance offset beetwen the camera and the center of the linked model. used for rotation calculations.--------------------HOW TO USE-first create an instance an set it as the active camera var c = engine.setCamera(new Camera3D());-then set it's coordinates and rotation c.setCoordinates(0, 0, -100); c.setRotation(0, 0);-it's recommended to do this inside the scene function///////////////////////ESPANOLproyecto: engine 3dpor: ivan ivanoff (www.i2off.org)basado en el trabajo de: stuart schoneveld (www.illogicz.com) email: avatar@i2off.orgperdones: A mi mujer e hijos por aguantar. A jorge, valeria y mariano, por joderlos a cada rato. --------------------ACERCA DE ESTA CLASEUna instancia de esta clase controla que es lo que se ve en pantalla. Desde que angulo, que posicion, etc.--------------------ACERCA DE SUS METODOS PUBLICOS-setFieldOfView (a) setea la amplitud de la vista. Esto modifica la forma de ver la situacion.-getFieldOfView () devuelve la amplitud de la vista-setCoordinates (px,py,pz) setea la posicion de la camara. PX, PY y PZ son la posicion sobre cada eje-getCoordinates () devuelve la posicion de la camara en un objeto dimensionado asi {x,y,z}-setRotation (rx,ry) setea la rotacion de la camara. RX y RY son la rotacion en radianes.-getRotation() devuelve rotacion de la camara en un objeto dimensionado asi {x,y}-moveBy(N) avanza la camara en la direccion en la que estaba orientado N pasos. Si N es negativo retrocede.-strafeBy(N) avanza la camara de lado. N es la distancia.-setPivot(b, p) setea un pivot para la camara. Esto hace que la camara siempre mire hacia el. b: booleano que indica si la camara tiene pivot o no. p: modelo que funciona como pivot. -------------------- ACERCA DE SUS PROPIEDADES PUBLICAS-doPivot si la camara tiene pivot o no-pivot cual es el modelo que funciona como pivot-doLink si la camara esta linkeada a algun modelo. De estarlo la camara se mueve de acuerdo a este.-link modelo al que esta linkeado-linkOffset posicion de diferencia con respecto al objeto linkeado-doLinkRota en el caso de que el objeto este linkeado, esto indica si rota de acuerdo al objeto-linkRotaOffsetZ distancia con respecto al centro para medir el giro--------------------MODO DE USO-primero hay que crear una instancia y setearla como camara activa var c = engine.setCamera(new Camera3D()); -luego se setean sus coordenadas y rotacion c.setCoordinates(0, 0, -100); c.setRotation(0, 0);-todo esto es recomendable hacerlo en la funcion de la escena*******************/class Camera3D { var _id //no es necesario var fov=350 var x var y var z var xrot var yrot var doPivot:Boolean= false var pivot:Object var pivotOldCoord:Object var doLink:Boolean = false var link:Object var linkOffset:Object //{x,y,z} var linkTipoEasyng:Number = 1 var linkParamsEasyng:Array var doLinkRota:Boolean = false var linkRotaOffsetZ:Number var linkRotaOffsetAngle:Number = 0 //en radianes //{x,y,z} var plugins function Camera3D () { setRotation(0,0) setCoordinates(0,0,0) plugins = {} } function setFieldOfView (a) { fov = a } function getFieldOfView () { return fov } function setCoordinates (px,py,pz) { x = px y =py z =pz } function getCoordinates () { return {x:x,y:y,z:z} } function setRotation (rx,ry) { xrot = rx yrot = ry } function getRotation() { return {x:xrot,y:yrot} } function moveBy (n) { var xr = xrot var yr = yrot var cr = Math.cos(xr) x += Math.sin(yr)*cr*n y -= Math.sin(xr)*n z += Math.cos(yr)*cr*n } function strafeBy (n) { var xr = xrot var yr = yrot x -= Math.cos(yr)*n z += Math.sin(yr)*n } function setPivot(b, p) { doPivot = b pivot = p } function addPlugin(n,o){ plugins[n] = o o.onAdd(this) return o } function removePlugin(n){ plugins[n].onRemove() delete plugins[n] }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -