mirror of
https://github.com/MapMakersAndProgrammers/alternativa-editor-mod.git
synced 2025-10-26 01:49:05 -07:00
working on object3d mouse events
This commit is contained in:
Binary file not shown.
@@ -439,7 +439,8 @@
|
|||||||
private function newLevel():void
|
private function newLevel():void
|
||||||
{
|
{
|
||||||
this.mainScene.clear();
|
this.mainScene.clear();
|
||||||
this.cursorScene.updateMaterial();
|
//this.cursorScene.updateMaterial();
|
||||||
|
this.cursorScene.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onImportFromTanksClick(param1:NativeMenuItem):void
|
private function onImportFromTanksClick(param1:NativeMenuItem):void
|
||||||
@@ -526,7 +527,8 @@
|
|||||||
{
|
{
|
||||||
this.mainScene.clear();
|
this.mainScene.clear();
|
||||||
this.mainScene.changed = true;
|
this.mainScene.changed = true;
|
||||||
this.cursorScene.updateMaterial();
|
//this.cursorScene.updateMaterial();
|
||||||
|
this.cursorScene.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onSelectAll(param1:NativeMenuItem):void
|
private function onSelectAll(param1:NativeMenuItem):void
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ package alternativa.editor
|
|||||||
this.cameraContainer.addChild(this.camera);
|
this.cameraContainer.addChild(this.camera);
|
||||||
this.camera.setPositionXYZ(0,-100,40);
|
this.camera.setPositionXYZ(0,-100,40);
|
||||||
this.scene.root.addChild(this.cameraContainer);
|
this.scene.root.addChild(this.cameraContainer);
|
||||||
this.view = new View(100,100);
|
this.view = new View(this.camera,100,100);
|
||||||
this.camera.view = this.view;
|
|
||||||
addChild(this.view);
|
addChild(this.view);
|
||||||
//this.view.graphics.beginFill(16777215);
|
//this.view.graphics.beginFill(16777215);
|
||||||
//this.view.graphics.drawRect(0,0,1,1);
|
//this.view.graphics.drawRect(0,0,1,1);
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ package alternativa.editor.scene
|
|||||||
this.containerController.object = this.container;
|
this.containerController.object = this.container;
|
||||||
this.containerController.mouseEnabled = false;
|
this.containerController.mouseEnabled = false;
|
||||||
this.container.addChild(this.mainScene.camera);
|
this.container.addChild(this.mainScene.camera);
|
||||||
|
this.container.mouseChildren = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set object(param1:Prop) : void
|
public function set object(param1:Prop) : void
|
||||||
@@ -219,7 +220,7 @@ package alternativa.editor.scene
|
|||||||
{
|
{
|
||||||
if(this._object)
|
if(this._object)
|
||||||
{
|
{
|
||||||
if(this.mainScene.root.getChildByName(this._object.name))
|
if(this.mainScene.root.contains(this._object))
|
||||||
{
|
{
|
||||||
this.mainScene.root.removeChild(this._object);
|
this.mainScene.root.removeChild(this._object);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,12 +65,12 @@ package alternativa.editor.scene
|
|||||||
protected function initScene() : void
|
protected function initScene() : void
|
||||||
{
|
{
|
||||||
root = new Object3DContainer();
|
root = new Object3DContainer();
|
||||||
|
root.name = "EditorRoot";
|
||||||
this.camera = new Camera3D();
|
this.camera = new Camera3D();
|
||||||
this.camera.rotationX = -MathUtils.DEG90 - MathUtils.DEG30;
|
this.camera.rotationX = -MathUtils.DEG90 - MathUtils.DEG30;
|
||||||
this.camera.setPositionXYZ(250,-7800,4670);
|
this.camera.setPositionXYZ(250,-7800,4670);
|
||||||
//root.addChild(this.camera);
|
//root.addChild(this.camera);
|
||||||
this.view = new View(100,100);
|
this.view = new View(this.camera,100,100);
|
||||||
this.camera.view = view;
|
|
||||||
this.view.interactive = true;
|
this.view.interactive = true;
|
||||||
this.view.buttonMode = true;
|
this.view.buttonMode = true;
|
||||||
this.view.useHandCursor = false;
|
this.view.useHandCursor = false;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ package alternativa.engine3d.core
|
|||||||
private static const constantsVertexBuffer:VertexBufferResource = createConstantsVertexBuffer((constantsMaxTriangles * 3));
|
private static const constantsVertexBuffer:VertexBufferResource = createConstantsVertexBuffer((constantsMaxTriangles * 3));
|
||||||
private static const constantsIndexBuffer:IndexBufferResource = createConstantsIndexBuffer((constantsMaxTriangles * 3));
|
private static const constantsIndexBuffer:IndexBufferResource = createConstantsIndexBuffer((constantsMaxTriangles * 3));
|
||||||
|
|
||||||
public var view:View;
|
alternativa3d var view:View;
|
||||||
public var fov:Number = 1.5707963267949;
|
public var fov:Number = 1.5707963267949;
|
||||||
public var nearClipping:Number = 1;
|
public var nearClipping:Number = 1;
|
||||||
public var farClipping:Number = 1000000;
|
public var farClipping:Number = 1000000;
|
||||||
@@ -197,6 +197,7 @@ package alternativa.engine3d.core
|
|||||||
this.lastWrapper = this.firstWrapper;
|
this.lastWrapper = this.firstWrapper;
|
||||||
this.lastVertex = this.firstVertex;
|
this.lastVertex = this.firstVertex;
|
||||||
this.lastFace = this.firstFace;
|
this.lastFace = this.firstFace;
|
||||||
|
this.mouseEnabled = false;
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -228,6 +228,13 @@ package alternativa.engine3d.core
|
|||||||
public function get transformation() : Matrix4
|
public function get transformation() : Matrix4
|
||||||
{
|
{
|
||||||
tA.composeMatrixFromSource(this);
|
tA.composeMatrixFromSource(this);
|
||||||
|
var _local_1:Object3D = this;
|
||||||
|
while (_local_1._parent != null)
|
||||||
|
{
|
||||||
|
_local_1 = _local_1._parent;
|
||||||
|
tB.composeMatrixFromSource(_local_1);
|
||||||
|
tA.appendMatrix(tB);
|
||||||
|
};
|
||||||
return new Matrix4(tA.ma, tA.mb, tA.mc, tA.md, tA.me, tA.mf, tA.mg, tA.mh, tA.mi, tA.mj, tA.mk, tA.ml);
|
return new Matrix4(tA.ma, tA.mb, tA.mc, tA.md, tA.me, tA.mf, tA.mg, tA.mh, tA.mi, tA.mj, tA.mk, tA.ml);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +268,7 @@ package alternativa.engine3d.core
|
|||||||
return (new Matrix3D(Vector.<Number>([tA.ma, tA.me, tA.mi, 0, tA.mb, tA.mf, tA.mj, 0, tA.mc, tA.mg, tA.mk, 0, tA.md, tA.mh, tA.ml, 1])));
|
return (new Matrix3D(Vector.<Number>([tA.ma, tA.me, tA.mi, 0, tA.mb, tA.mf, tA.mj, 0, tA.mc, tA.mg, tA.mk, 0, tA.md, tA.mh, tA.ml, 1])));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function localToGlobal(_arg_1:Vector3D):Vector3D
|
public function localToGlobal(_arg_1:Vector3D, vector:Boolean = false):Vector3D
|
||||||
{
|
{
|
||||||
tA.composeMatrixFromSource(this);
|
tA.composeMatrixFromSource(this);
|
||||||
var _local_2:Object3D = this;
|
var _local_2:Object3D = this;
|
||||||
@@ -272,9 +279,15 @@ package alternativa.engine3d.core
|
|||||||
tA.appendMatrix(tB);
|
tA.appendMatrix(tB);
|
||||||
};
|
};
|
||||||
var _local_3:Vector3D = new Vector3D();
|
var _local_3:Vector3D = new Vector3D();
|
||||||
_local_3.x = ((((tA.ma * _arg_1.x) + (tA.mb * _arg_1.y)) + (tA.mc * _arg_1.z)) + tA.md);
|
_local_3.x = (((tA.ma * _arg_1.x) + (tA.mb * _arg_1.y)) + (tA.mc * _arg_1.z));
|
||||||
_local_3.y = ((((tA.me * _arg_1.x) + (tA.mf * _arg_1.y)) + (tA.mg * _arg_1.z)) + tA.mh);
|
_local_3.y = (((tA.me * _arg_1.x) + (tA.mf * _arg_1.y)) + (tA.mg * _arg_1.z));
|
||||||
_local_3.z = ((((tA.mi * _arg_1.x) + (tA.mj * _arg_1.y)) + (tA.mk * _arg_1.z)) + tA.ml);
|
_local_3.z = (((tA.mi * _arg_1.x) + (tA.mj * _arg_1.y)) + (tA.mk * _arg_1.z));
|
||||||
|
if(!vector)
|
||||||
|
{
|
||||||
|
_local_3.x += tA.md;
|
||||||
|
_local_3.y += tA.mh;
|
||||||
|
_local_3.z += tA.ml;
|
||||||
|
}
|
||||||
return (_local_3);
|
return (_local_3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -420,6 +420,9 @@ package alternativa.engine3d.core
|
|||||||
var _local_8:Number = 1E22;
|
var _local_8:Number = 1E22;
|
||||||
var _local_9:Object3D = this.childrenList;
|
var _local_9:Object3D = this.childrenList;
|
||||||
while (_local_9 != null)
|
while (_local_9 != null)
|
||||||
|
{
|
||||||
|
var cont:Object3DContainer = _local_9 as Object3DContainer;
|
||||||
|
if((cont == null && _local_9.mouseEnabled) || (cont && cont.mouseChildren))
|
||||||
{
|
{
|
||||||
_local_9.composeMatrix();
|
_local_9.composeMatrix();
|
||||||
_local_9.invertMatrix();
|
_local_9.invertMatrix();
|
||||||
@@ -440,6 +443,7 @@ package alternativa.engine3d.core
|
|||||||
_local_8 = _local_10.time;
|
_local_8 = _local_10.time;
|
||||||
_local_7 = _local_10;
|
_local_7 = _local_10;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
_local_9 = _local_9.next;
|
_local_9 = _local_9.next;
|
||||||
};
|
};
|
||||||
return (_local_7);
|
return (_local_7);
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ package alternativa.engine3d.core{
|
|||||||
import __AS3__.vec.*;
|
import __AS3__.vec.*;
|
||||||
import alternativa.engine3d.alternativa3d;
|
import alternativa.engine3d.alternativa3d;
|
||||||
import flash.display3D.Context3D;
|
import flash.display3D.Context3D;
|
||||||
|
import mx.controls.Alert;
|
||||||
|
import flash.geom.Vector3D;
|
||||||
|
import alternativa.math.Quaternion;
|
||||||
|
import alternativa.engine3d.primitives.Box;
|
||||||
|
import alternativa.engine3d.materials.FillMaterial;
|
||||||
|
import alternativa.math.Matrix3;
|
||||||
|
|
||||||
use namespace alternativa3d;
|
use namespace alternativa3d;
|
||||||
|
|
||||||
@@ -40,6 +46,9 @@ package alternativa.engine3d.core{
|
|||||||
private static var configured:Boolean = false;
|
private static var configured:Boolean = false;
|
||||||
private static var cleared:Boolean = true;
|
private static var cleared:Boolean = true;
|
||||||
|
|
||||||
|
private static const tmpVec1:Vector3D = new Vector3D();
|
||||||
|
private static const tmpMatrix3:Matrix3 = new Matrix3();
|
||||||
|
|
||||||
private var presented:Boolean = false;
|
private var presented:Boolean = false;
|
||||||
private var globalCoords:Point;
|
private var globalCoords:Point;
|
||||||
alternativa3d var rect:Rectangle = new Rectangle();
|
alternativa3d var rect:Rectangle = new Rectangle();
|
||||||
@@ -75,10 +84,12 @@ package alternativa.engine3d.core{
|
|||||||
|
|
||||||
private var _interactive:Boolean = false;
|
private var _interactive:Boolean = false;
|
||||||
|
|
||||||
public function View(width:Number, height:Number, constrainedMode:Boolean=false){
|
public function View(camera:Camera3D, width:Number, height:Number, constrainedMode:Boolean=false){
|
||||||
super();
|
super();
|
||||||
this._width = width;
|
this._width = width;
|
||||||
this._height = height;
|
this._height = height;
|
||||||
|
this.camera = camera;
|
||||||
|
camera.view = this;
|
||||||
this.constrained = constrainedMode;
|
this.constrained = constrainedMode;
|
||||||
mouseEnabled = true;
|
mouseEnabled = true;
|
||||||
mouseChildren = true;
|
mouseChildren = true;
|
||||||
@@ -289,6 +300,7 @@ package alternativa.engine3d.core{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onMouseMove(_arg_1:MouseEvent):void{
|
private function onMouseMove(_arg_1:MouseEvent):void{
|
||||||
|
return;
|
||||||
this.onMouse(_arg_1);
|
this.onMouse(_arg_1);
|
||||||
this.defineTarget(_arg_1);
|
this.defineTarget(_arg_1);
|
||||||
if (this.target != null)
|
if (this.target != null)
|
||||||
@@ -603,72 +615,66 @@ package alternativa.engine3d.core{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private function defineTarget(_arg_1:MouseEvent):void{
|
private function defineTarget(_arg_1:MouseEvent):void
|
||||||
var _local_2:Object3D;
|
{
|
||||||
var _local_3:Object3D;
|
|
||||||
var _local_6:Canvas;
|
|
||||||
var _local_7:DisplayObject;
|
|
||||||
var _local_8:Object3D;
|
|
||||||
var _local_9:Object3D;
|
|
||||||
mouse.x = _arg_1.localX;
|
mouse.x = _arg_1.localX;
|
||||||
mouse.y = _arg_1.localY;
|
mouse.y = _arg_1.localY;
|
||||||
var _local_4:Array = ((stage != null) ? stage.getObjectsUnderPoint(localToGlobal(mouse)) : super.getObjectsUnderPoint(mouse));
|
|
||||||
var _local_5:int = (_local_4.length - 1);
|
//idk how to make this to work, pls help
|
||||||
while (_local_5 >= 0)
|
|
||||||
|
this.target = null;
|
||||||
|
|
||||||
|
var root:Object3DContainer = this.camera.parent;
|
||||||
|
|
||||||
|
while(root != null)
|
||||||
{
|
{
|
||||||
_local_6 = null;
|
var parent:Object3DContainer = root.parent;
|
||||||
_local_7 = _local_4[_local_5];
|
if(parent == null)
|
||||||
while (_local_7.parent != stage)
|
|
||||||
{
|
|
||||||
_local_6 = (_local_7 as Canvas);
|
|
||||||
if (_local_6 != null) break;
|
|
||||||
_local_7 = _local_7.parent;
|
|
||||||
};
|
|
||||||
if (_local_6 != null)
|
|
||||||
{
|
|
||||||
if (_local_3 != null)
|
|
||||||
{
|
|
||||||
_local_8 = null;
|
|
||||||
_local_9 = _local_3;
|
|
||||||
while (_local_9 != null)
|
|
||||||
{
|
|
||||||
if (((_local_9 is Object3DContainer) && (!(Object3DContainer(_local_9).mouseChildren))))
|
|
||||||
{
|
|
||||||
_local_8 = null;
|
|
||||||
};
|
|
||||||
if (((_local_8 == null) && (_local_9.mouseEnabled)))
|
|
||||||
{
|
|
||||||
_local_8 = _local_9;
|
|
||||||
};
|
|
||||||
_local_9 = _local_9._parent;
|
|
||||||
};
|
|
||||||
if (_local_8 != null)
|
|
||||||
{
|
|
||||||
if (this.target != null)
|
|
||||||
{
|
|
||||||
_local_9 = _local_8;
|
|
||||||
while (_local_9 != null)
|
|
||||||
{
|
|
||||||
if (_local_9 == this.target)
|
|
||||||
{
|
|
||||||
_local_2 = _local_3;
|
|
||||||
this.target = _local_8;
|
|
||||||
break;
|
break;
|
||||||
};
|
if(!parent.mouseChildren)
|
||||||
_local_9 = _local_9._parent;
|
continue;
|
||||||
};
|
root = parent;
|
||||||
}
|
}
|
||||||
else
|
if(!root.mouseChildren)
|
||||||
{
|
return;
|
||||||
_local_2 = _local_3;
|
|
||||||
this.target = _local_8;
|
//ErrorHandler.clearMessages();
|
||||||
};
|
|
||||||
if (_local_2 == this.target) break;
|
tmpVec1.setTo(mouse.x,mouse.y,0);
|
||||||
};
|
var origin:Vector3D = this.camera.projectGlobal(tmpVec1);
|
||||||
};
|
|
||||||
};
|
tmpVec1.setTo(0,0,1);
|
||||||
_local_5--;
|
|
||||||
};
|
//ErrorHandler.addText("local dir: " + tmpVec1);
|
||||||
|
|
||||||
|
var dir:Vector3D = camera.localToGlobal(tmpVec1,true);
|
||||||
|
|
||||||
|
//debugging:
|
||||||
|
/*ErrorHandler.addText("ray: origin="+origin + " ; dir=" + dir);
|
||||||
|
|
||||||
|
var box:Box = new Box(10,10,30);
|
||||||
|
box.setMaterialToAllFaces(new FillMaterial(0xff0000));
|
||||||
|
root.addChild(box);
|
||||||
|
|
||||||
|
tmpMatrix3.setDirectionVector(dir);
|
||||||
|
var rotation:Vector3D = new Vector3D();
|
||||||
|
tmpMatrix3.getEulerAngles(rotation);
|
||||||
|
|
||||||
|
box.setPositionXYZ(origin.x,origin.y,origin.z);
|
||||||
|
box.setRotationXYZ(rotation.x,rotation.y,rotation.z);*/
|
||||||
|
|
||||||
|
var rayHit:RayIntersectionData = root.intersectRay(origin, dir, null, this.camera);
|
||||||
|
|
||||||
|
/*setTimeout(function():void{
|
||||||
|
ErrorHandler.showWindow();
|
||||||
|
},10);*/
|
||||||
|
|
||||||
|
if(rayHit == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.target = rayHit.object;
|
||||||
|
|
||||||
|
//ErrorHandler.addText("hit: " + rayHit);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function getObjectsUnderPoint(_arg_1:Point):Array{
|
override public function getObjectsUnderPoint(_arg_1:Point):Array{
|
||||||
|
|||||||
420
src/alternativa/math/Matrix3.as
Normal file
420
src/alternativa/math/Matrix3.as
Normal file
@@ -0,0 +1,420 @@
|
|||||||
|
package alternativa.math
|
||||||
|
{
|
||||||
|
import alternativa.engine3d.core.Object3D;
|
||||||
|
import flash.geom.Vector3D;
|
||||||
|
import flash.utils.getQualifiedClassName;
|
||||||
|
|
||||||
|
public class Matrix3
|
||||||
|
{
|
||||||
|
|
||||||
|
public static const ZERO:Matrix3 = new Matrix3(0,0,0,0,0,0,0,0,0);
|
||||||
|
|
||||||
|
public static const IDENTITY:Matrix3 = new Matrix3();
|
||||||
|
|
||||||
|
private static const xAxis:Vector3D = new Vector3D();
|
||||||
|
|
||||||
|
private static const yAxis:Vector3D = new Vector3D();
|
||||||
|
|
||||||
|
private static const zAxis:Vector3D = new Vector3D();
|
||||||
|
|
||||||
|
|
||||||
|
public static const V_X_AXIS:Vector3D = new Vector3D(1,0,0);
|
||||||
|
|
||||||
|
public static const V_Y_AXIS:Vector3D = new Vector3D(0,1,0);
|
||||||
|
|
||||||
|
public static const V_Z_AXIS:Vector3D = new Vector3D(0,0,1);
|
||||||
|
|
||||||
|
|
||||||
|
public var m00:Number;
|
||||||
|
|
||||||
|
public var m01:Number;
|
||||||
|
|
||||||
|
public var m02:Number;
|
||||||
|
|
||||||
|
public var m10:Number;
|
||||||
|
|
||||||
|
public var m11:Number;
|
||||||
|
|
||||||
|
public var m12:Number;
|
||||||
|
|
||||||
|
public var m20:Number;
|
||||||
|
|
||||||
|
public var m21:Number;
|
||||||
|
|
||||||
|
public var m22:Number;
|
||||||
|
|
||||||
|
public function Matrix3(param1:Number = 1, param2:Number = 0, param3:Number = 0, param4:Number = 0, param5:Number = 1, param6:Number = 0, param7:Number = 0, param8:Number = 0, param9:Number = 1)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.m00 = param1;
|
||||||
|
this.m01 = param2;
|
||||||
|
this.m02 = param3;
|
||||||
|
this.m10 = param4;
|
||||||
|
this.m11 = param5;
|
||||||
|
this.m12 = param6;
|
||||||
|
this.m20 = param7;
|
||||||
|
this.m21 = param8;
|
||||||
|
this.m22 = param9;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toIdentity() : Matrix3
|
||||||
|
{
|
||||||
|
this.m00 = this.m11 = this.m22 = 1;
|
||||||
|
this.m01 = this.m02 = this.m10 = this.m12 = this.m20 = this.m21 = 0;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invert() : Matrix3
|
||||||
|
{
|
||||||
|
var _loc1_:Number = this.m00;
|
||||||
|
var _loc2_:Number = this.m01;
|
||||||
|
var _loc3_:Number = this.m02;
|
||||||
|
var _loc4_:Number = this.m10;
|
||||||
|
var _loc5_:Number = this.m11;
|
||||||
|
var _loc6_:Number = this.m12;
|
||||||
|
var _loc7_:Number = this.m20;
|
||||||
|
var _loc8_:Number = this.m21;
|
||||||
|
var _loc9_:Number = this.m22;
|
||||||
|
var _loc10_:Number = 1 / (-_loc3_ * _loc5_ * _loc7_ + _loc2_ * _loc6_ * _loc7_ + _loc3_ * _loc4_ * _loc8_ - _loc1_ * _loc6_ * _loc8_ - _loc2_ * _loc4_ * _loc9_ + _loc1_ * _loc5_ * _loc9_);
|
||||||
|
this.m00 = (_loc5_ * _loc9_ - _loc6_ * _loc8_) * _loc10_;
|
||||||
|
this.m01 = (_loc3_ * _loc8_ - _loc2_ * _loc9_) * _loc10_;
|
||||||
|
this.m02 = (_loc2_ * _loc6_ - _loc3_ * _loc5_) * _loc10_;
|
||||||
|
this.m10 = (_loc6_ * _loc7_ - _loc4_ * _loc9_) * _loc10_;
|
||||||
|
this.m11 = (_loc1_ * _loc9_ - _loc3_ * _loc7_) * _loc10_;
|
||||||
|
this.m12 = (_loc3_ * _loc4_ - _loc1_ * _loc6_) * _loc10_;
|
||||||
|
this.m20 = (_loc4_ * _loc8_ - _loc5_ * _loc7_) * _loc10_;
|
||||||
|
this.m21 = (_loc2_ * _loc7_ - _loc1_ * _loc8_) * _loc10_;
|
||||||
|
this.m22 = (_loc1_ * _loc5_ - _loc2_ * _loc4_) * _loc10_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function append(param1:Matrix3) : Matrix3
|
||||||
|
{
|
||||||
|
var _loc2_:Number = this.m00;
|
||||||
|
var _loc3_:Number = this.m01;
|
||||||
|
var _loc4_:Number = this.m02;
|
||||||
|
var _loc5_:Number = this.m10;
|
||||||
|
var _loc6_:Number = this.m11;
|
||||||
|
var _loc7_:Number = this.m12;
|
||||||
|
var _loc8_:Number = this.m20;
|
||||||
|
var _loc9_:Number = this.m21;
|
||||||
|
var _loc10_:Number = this.m22;
|
||||||
|
this.m00 = param1.m00 * _loc2_ + param1.m01 * _loc5_ + param1.m02 * _loc8_;
|
||||||
|
this.m01 = param1.m00 * _loc3_ + param1.m01 * _loc6_ + param1.m02 * _loc9_;
|
||||||
|
this.m02 = param1.m00 * _loc4_ + param1.m01 * _loc7_ + param1.m02 * _loc10_;
|
||||||
|
this.m10 = param1.m10 * _loc2_ + param1.m11 * _loc5_ + param1.m12 * _loc8_;
|
||||||
|
this.m11 = param1.m10 * _loc3_ + param1.m11 * _loc6_ + param1.m12 * _loc9_;
|
||||||
|
this.m12 = param1.m10 * _loc4_ + param1.m11 * _loc7_ + param1.m12 * _loc10_;
|
||||||
|
this.m20 = param1.m20 * _loc2_ + param1.m21 * _loc5_ + param1.m22 * _loc8_;
|
||||||
|
this.m21 = param1.m20 * _loc3_ + param1.m21 * _loc6_ + param1.m22 * _loc9_;
|
||||||
|
this.m22 = param1.m20 * _loc4_ + param1.m21 * _loc7_ + param1.m22 * _loc10_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepend(param1:Matrix3) : Matrix3
|
||||||
|
{
|
||||||
|
var _loc2_:Number = this.m00;
|
||||||
|
var _loc3_:Number = this.m01;
|
||||||
|
var _loc4_:Number = this.m02;
|
||||||
|
var _loc5_:Number = this.m10;
|
||||||
|
var _loc6_:Number = this.m11;
|
||||||
|
var _loc7_:Number = this.m12;
|
||||||
|
var _loc8_:Number = this.m20;
|
||||||
|
var _loc9_:Number = this.m21;
|
||||||
|
var _loc10_:Number = this.m22;
|
||||||
|
this.m00 = _loc2_ * param1.m00 + _loc3_ * param1.m10 + _loc4_ * param1.m20;
|
||||||
|
this.m01 = _loc2_ * param1.m01 + _loc3_ * param1.m11 + _loc4_ * param1.m21;
|
||||||
|
this.m02 = _loc2_ * param1.m02 + _loc3_ * param1.m12 + _loc4_ * param1.m22;
|
||||||
|
this.m10 = _loc5_ * param1.m00 + _loc6_ * param1.m10 + _loc7_ * param1.m20;
|
||||||
|
this.m11 = _loc5_ * param1.m01 + _loc6_ * param1.m11 + _loc7_ * param1.m21;
|
||||||
|
this.m12 = _loc5_ * param1.m02 + _loc6_ * param1.m12 + _loc7_ * param1.m22;
|
||||||
|
this.m20 = _loc8_ * param1.m00 + _loc9_ * param1.m10 + _loc10_ * param1.m20;
|
||||||
|
this.m21 = _loc8_ * param1.m01 + _loc9_ * param1.m11 + _loc10_ * param1.m21;
|
||||||
|
this.m22 = _loc8_ * param1.m02 + _loc9_ * param1.m12 + _loc10_ * param1.m22;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prependTransposed(param1:Matrix3) : Matrix3
|
||||||
|
{
|
||||||
|
var _loc2_:Number = this.m00;
|
||||||
|
var _loc3_:Number = this.m01;
|
||||||
|
var _loc4_:Number = this.m02;
|
||||||
|
var _loc5_:Number = this.m10;
|
||||||
|
var _loc6_:Number = this.m11;
|
||||||
|
var _loc7_:Number = this.m12;
|
||||||
|
var _loc8_:Number = this.m20;
|
||||||
|
var _loc9_:Number = this.m21;
|
||||||
|
var _loc10_:Number = this.m22;
|
||||||
|
this.m00 = _loc2_ * param1.m00 + _loc3_ * param1.m01 + _loc4_ * param1.m02;
|
||||||
|
this.m01 = _loc2_ * param1.m10 + _loc3_ * param1.m11 + _loc4_ * param1.m12;
|
||||||
|
this.m02 = _loc2_ * param1.m20 + _loc3_ * param1.m21 + _loc4_ * param1.m22;
|
||||||
|
this.m10 = _loc5_ * param1.m00 + _loc6_ * param1.m01 + _loc7_ * param1.m02;
|
||||||
|
this.m11 = _loc5_ * param1.m10 + _loc6_ * param1.m11 + _loc7_ * param1.m12;
|
||||||
|
this.m12 = _loc5_ * param1.m20 + _loc6_ * param1.m21 + _loc7_ * param1.m22;
|
||||||
|
this.m20 = _loc8_ * param1.m00 + _loc9_ * param1.m01 + _loc10_ * param1.m02;
|
||||||
|
this.m21 = _loc8_ * param1.m10 + _loc9_ * param1.m11 + _loc10_ * param1.m12;
|
||||||
|
this.m22 = _loc8_ * param1.m20 + _loc9_ * param1.m21 + _loc10_ * param1.m22;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add(param1:Matrix3) : Matrix3
|
||||||
|
{
|
||||||
|
this.m00 += param1.m00;
|
||||||
|
this.m01 += param1.m01;
|
||||||
|
this.m02 += param1.m02;
|
||||||
|
this.m10 += param1.m10;
|
||||||
|
this.m11 += param1.m11;
|
||||||
|
this.m12 += param1.m12;
|
||||||
|
this.m20 += param1.m20;
|
||||||
|
this.m21 += param1.m21;
|
||||||
|
this.m22 += param1.m22;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function subtract(param1:Matrix3) : Matrix3
|
||||||
|
{
|
||||||
|
this.m00 -= param1.m00;
|
||||||
|
this.m01 -= param1.m01;
|
||||||
|
this.m02 -= param1.m02;
|
||||||
|
this.m10 -= param1.m10;
|
||||||
|
this.m11 -= param1.m11;
|
||||||
|
this.m12 -= param1.m12;
|
||||||
|
this.m20 -= param1.m20;
|
||||||
|
this.m21 -= param1.m21;
|
||||||
|
this.m22 -= param1.m22;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transpose() : Matrix3
|
||||||
|
{
|
||||||
|
var _loc1_:Number = this.m01;
|
||||||
|
this.m01 = this.m10;
|
||||||
|
this.m10 = _loc1_;
|
||||||
|
_loc1_ = this.m02;
|
||||||
|
this.m02 = this.m20;
|
||||||
|
this.m20 = _loc1_;
|
||||||
|
_loc1_ = this.m12;
|
||||||
|
this.m12 = this.m21;
|
||||||
|
this.m21 = _loc1_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transformVector(param1:Vector3D, param2:Vector3D) : void
|
||||||
|
{
|
||||||
|
param2.x = this.m00 * param1.x + this.m01 * param1.y + this.m02 * param1.z;
|
||||||
|
param2.y = this.m10 * param1.x + this.m11 * param1.y + this.m12 * param1.z;
|
||||||
|
param2.z = this.m20 * param1.x + this.m21 * param1.y + this.m22 * param1.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transformVectorInverse(param1:Vector3D, param2:Vector3D) : void
|
||||||
|
{
|
||||||
|
param2.x = this.m00 * param1.x + this.m10 * param1.y + this.m20 * param1.z;
|
||||||
|
param2.y = this.m01 * param1.x + this.m11 * param1.y + this.m21 * param1.z;
|
||||||
|
param2.z = this.m02 * param1.x + this.m12 * param1.y + this.m22 * param1.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transformVector3To3D(param1:Vector3D, param2:Vector3D) : void
|
||||||
|
{
|
||||||
|
param2.x = this.m00 * param1.x + this.m01 * param1.y + this.m02 * param1.z;
|
||||||
|
param2.y = this.m10 * param1.x + this.m11 * param1.y + this.m12 * param1.z;
|
||||||
|
param2.z = this.m20 * param1.x + this.m21 * param1.y + this.m22 * param1.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createSkewSymmetric(param1:Vector3D) : Matrix3
|
||||||
|
{
|
||||||
|
this.m00 = this.m11 = this.m22 = 0;
|
||||||
|
this.m01 = -param1.z;
|
||||||
|
this.m02 = param1.y;
|
||||||
|
this.m10 = param1.z;
|
||||||
|
this.m12 = -param1.x;
|
||||||
|
this.m20 = -param1.y;
|
||||||
|
this.m21 = param1.x;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function copy(param1:Matrix3) : Matrix3
|
||||||
|
{
|
||||||
|
this.m00 = param1.m00;
|
||||||
|
this.m01 = param1.m01;
|
||||||
|
this.m02 = param1.m02;
|
||||||
|
this.m10 = param1.m10;
|
||||||
|
this.m11 = param1.m11;
|
||||||
|
this.m12 = param1.m12;
|
||||||
|
this.m20 = param1.m20;
|
||||||
|
this.m21 = param1.m21;
|
||||||
|
this.m22 = param1.m22;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRotationMatrix(param1:Number, param2:Number, param3:Number) : Matrix3
|
||||||
|
{
|
||||||
|
var _loc4_:Number = Math.cos(param1);
|
||||||
|
var _loc5_:Number = Math.sin(param1);
|
||||||
|
var _loc6_:Number = Math.cos(param2);
|
||||||
|
var _loc7_:Number = Math.sin(param2);
|
||||||
|
var _loc8_:Number = Math.cos(param3);
|
||||||
|
var _loc9_:Number = Math.sin(param3);
|
||||||
|
var _loc10_:Number = _loc8_ * _loc7_;
|
||||||
|
var _loc11_:Number = _loc9_ * _loc7_;
|
||||||
|
this.m00 = _loc8_ * _loc6_;
|
||||||
|
this.m01 = _loc10_ * _loc5_ - _loc9_ * _loc4_;
|
||||||
|
this.m02 = _loc10_ * _loc4_ + _loc9_ * _loc5_;
|
||||||
|
this.m10 = _loc9_ * _loc6_;
|
||||||
|
this.m11 = _loc11_ * _loc5_ + _loc8_ * _loc4_;
|
||||||
|
this.m12 = _loc11_ * _loc4_ - _loc8_ * _loc5_;
|
||||||
|
this.m20 = -_loc7_;
|
||||||
|
this.m21 = _loc6_ * _loc5_;
|
||||||
|
this.m22 = _loc6_ * _loc4_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRotationMatrixForObject3D(param1:Object3D) : void
|
||||||
|
{
|
||||||
|
this.setRotationMatrix(param1.rotationX,param1.rotationY,param1.rotationZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromAxisAngle(param1:Vector3D, param2:Number) : void
|
||||||
|
{
|
||||||
|
var _loc3_:Number = Math.cos(param2);
|
||||||
|
var _loc4_:Number = Math.sin(param2);
|
||||||
|
var _loc5_:Number = 1 - _loc3_;
|
||||||
|
var _loc6_:Number = param1.x;
|
||||||
|
var _loc7_:Number = param1.y;
|
||||||
|
var _loc8_:Number = param1.z;
|
||||||
|
this.m00 = _loc5_ * _loc6_ * _loc6_ + _loc3_;
|
||||||
|
this.m01 = _loc5_ * _loc6_ * _loc7_ - _loc8_ * _loc4_;
|
||||||
|
this.m02 = _loc5_ * _loc6_ * _loc8_ + _loc7_ * _loc4_;
|
||||||
|
this.m10 = _loc5_ * _loc6_ * _loc7_ + _loc8_ * _loc4_;
|
||||||
|
this.m11 = _loc5_ * _loc7_ * _loc7_ + _loc3_;
|
||||||
|
this.m12 = _loc5_ * _loc7_ * _loc8_ - _loc6_ * _loc4_;
|
||||||
|
this.m20 = _loc5_ * _loc6_ * _loc8_ - _loc7_ * _loc4_;
|
||||||
|
this.m21 = _loc5_ * _loc7_ * _loc8_ + _loc6_ * _loc4_;
|
||||||
|
this.m22 = _loc5_ * _loc8_ * _loc8_ + _loc3_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clone() : Matrix3
|
||||||
|
{
|
||||||
|
return new Matrix3(this.m00,this.m01,this.m02,this.m10,this.m11,this.m12,this.m20,this.m21,this.m22);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toString() : String
|
||||||
|
{
|
||||||
|
return getQualifiedClassName(this) + " (" + this.m00 + ", " + this.m01 + ", " + this.m02 + "), (" + this.m10 + ", " + this.m11 + ", " + this.m12 + "), (" + this.m20 + ", " + this.m21 + ", " + this.m22 + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEulerAngles(param1:Vector3D) : void
|
||||||
|
{
|
||||||
|
if(-1 < this.m20 && this.m20 < 1)
|
||||||
|
{
|
||||||
|
param1.x = Math.atan2(this.m21,this.m22);
|
||||||
|
param1.y = -Math.asin(this.m20);
|
||||||
|
param1.z = Math.atan2(this.m10,this.m00);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
param1.x = 0;
|
||||||
|
param1.y = this.m20 <= -1 ? Math.PI : -Math.PI;
|
||||||
|
param1.y *= 0.5;
|
||||||
|
param1.z = Math.atan2(-this.m01,this.m11);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRight(param1:Vector3D) : void
|
||||||
|
{
|
||||||
|
this.getAxis(0,param1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getForward(param1:Vector3D) : void
|
||||||
|
{
|
||||||
|
this.getAxis(1,param1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUp(param1:Vector3D) : void
|
||||||
|
{
|
||||||
|
this.getAxis(2,param1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAxis(param1:int, param2:Vector3D) : void
|
||||||
|
{
|
||||||
|
switch(param1)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
param2.setTo(this.m00,this.m10,this.m20);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
param2.setTo(this.m01,this.m11,this.m21);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
param2.setTo(this.m02,this.m12,this.m22);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDirectionVector(param1:Vector3D) : void
|
||||||
|
{
|
||||||
|
yAxis.copyFrom(param1);
|
||||||
|
yAxis.normalize();
|
||||||
|
if(yAxis.dotProduct(V_X_AXIS) < 0.9)
|
||||||
|
{
|
||||||
|
zAxis.crossProductToOutput(V_X_AXIS,yAxis);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zAxis.crossProductToOutput(yAxis,V_Y_AXIS);
|
||||||
|
}
|
||||||
|
zAxis.normalize();
|
||||||
|
xAxis.crossProductToOutput(yAxis,zAxis).normalize();
|
||||||
|
this.setAxis(xAxis,yAxis,zAxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAxis(param1:Vector3D, param2:Vector3D, param3:Vector3D) : void
|
||||||
|
{
|
||||||
|
this.m00 = param1.x;
|
||||||
|
this.m01 = param2.x;
|
||||||
|
this.m02 = param3.x;
|
||||||
|
this.m10 = param1.y;
|
||||||
|
this.m11 = param2.y;
|
||||||
|
this.m12 = param3.y;
|
||||||
|
this.m20 = param1.z;
|
||||||
|
this.m21 = param2.z;
|
||||||
|
this.m22 = param3.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rotationMatrixToQuaternion(param1:Quaternion) : void
|
||||||
|
{
|
||||||
|
var _loc3_:Number = NaN;
|
||||||
|
var _loc2_:Number = this.m00 + this.m11 + this.m22;
|
||||||
|
if(_loc2_ > 0)
|
||||||
|
{
|
||||||
|
_loc3_ = Math.sqrt(_loc2_ + 1) * 2;
|
||||||
|
param1.w = 0.25 * _loc3_;
|
||||||
|
param1.x = (this.m21 - this.m12) / _loc3_;
|
||||||
|
param1.y = (this.m02 - this.m20) / _loc3_;
|
||||||
|
param1.z = (this.m10 - this.m01) / _loc3_;
|
||||||
|
}
|
||||||
|
else if(this.m00 > this.m11 && this.m00 > this.m22)
|
||||||
|
{
|
||||||
|
_loc3_ = Math.sqrt(1 + this.m00 - this.m11 - this.m22) * 2;
|
||||||
|
param1.w = (this.m21 - this.m12) / _loc3_;
|
||||||
|
param1.x = 0.25 * _loc3_;
|
||||||
|
param1.y = (this.m01 + this.m10) / _loc3_;
|
||||||
|
param1.z = (this.m02 + this.m20) / _loc3_;
|
||||||
|
}
|
||||||
|
else if(this.m11 > this.m22)
|
||||||
|
{
|
||||||
|
_loc3_ = Math.sqrt(1 + this.m11 - this.m00 - this.m22) * 2;
|
||||||
|
param1.w = (this.m02 - this.m20) / _loc3_;
|
||||||
|
param1.x = (this.m01 + this.m10) / _loc3_;
|
||||||
|
param1.y = 0.25 * _loc3_;
|
||||||
|
param1.z = (this.m12 + this.m21) / _loc3_;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_loc3_ = Math.sqrt(1 + this.m22 - this.m00 - this.m11) * 2;
|
||||||
|
param1.w = (this.m10 - this.m01) / _loc3_;
|
||||||
|
param1.x = (this.m02 + this.m20) / _loc3_;
|
||||||
|
param1.y = (this.m12 + this.m21) / _loc3_;
|
||||||
|
param1.z = 0.25 * _loc3_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
478
src/alternativa/math/Quaternion.as
Normal file
478
src/alternativa/math/Quaternion.as
Normal file
@@ -0,0 +1,478 @@
|
|||||||
|
package alternativa.math
|
||||||
|
{
|
||||||
|
import flash.geom.Vector3D;
|
||||||
|
import flash.utils.getQualifiedClassName;
|
||||||
|
|
||||||
|
public class Quaternion
|
||||||
|
{
|
||||||
|
|
||||||
|
private static const _q:Quaternion = new Quaternion();
|
||||||
|
|
||||||
|
|
||||||
|
public var w:Number;
|
||||||
|
|
||||||
|
public var x:Number;
|
||||||
|
|
||||||
|
public var y:Number;
|
||||||
|
|
||||||
|
public var z:Number;
|
||||||
|
|
||||||
|
public function Quaternion(param1:Number = 1, param2:Number = 0, param3:Number = 0, param4:Number = 0)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.w = param1;
|
||||||
|
this.x = param2;
|
||||||
|
this.y = param3;
|
||||||
|
this.z = param4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function multiply(param1:Quaternion, param2:Quaternion, param3:Quaternion) : void
|
||||||
|
{
|
||||||
|
param3.w = param1.w * param2.w - param1.x * param2.x - param1.y * param2.y - param1.z * param2.z;
|
||||||
|
param3.x = param1.w * param2.x + param1.x * param2.w + param1.y * param2.z - param1.z * param2.y;
|
||||||
|
param3.y = param1.w * param2.y + param1.y * param2.w + param1.z * param2.x - param1.x * param2.z;
|
||||||
|
param3.z = param1.w * param2.z + param1.z * param2.w + param1.x * param2.y - param1.y * param2.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function createFromAxisAngle(param1:Vector3D, param2:Number) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc3_:Quaternion = new Quaternion();
|
||||||
|
_loc3_.setFromAxisAngle(param1,param2);
|
||||||
|
return _loc3_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function createFromAxisAngleComponents(param1:Number, param2:Number, param3:Number, param4:Number) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc5_:Quaternion = new Quaternion();
|
||||||
|
_loc5_.setFromAxisAngleComponents(param1,param2,param3,param4);
|
||||||
|
return _loc5_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reset(param1:Number = 1, param2:Number = 0, param3:Number = 0, param4:Number = 0) : Quaternion
|
||||||
|
{
|
||||||
|
this.w = param1;
|
||||||
|
this.x = param2;
|
||||||
|
this.y = param3;
|
||||||
|
this.z = param4;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function normalize() : Quaternion
|
||||||
|
{
|
||||||
|
var _loc1_:Number = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
|
||||||
|
if(_loc1_ == 0)
|
||||||
|
{
|
||||||
|
this.w = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_loc1_ = 1 / Math.sqrt(_loc1_);
|
||||||
|
this.w *= _loc1_;
|
||||||
|
this.x *= _loc1_;
|
||||||
|
this.y *= _loc1_;
|
||||||
|
this.z *= _loc1_;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepend(param1:Quaternion) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc2_:Number = this.w * param1.w - this.x * param1.x - this.y * param1.y - this.z * param1.z;
|
||||||
|
var _loc3_:Number = this.w * param1.x + this.x * param1.w + this.y * param1.z - this.z * param1.y;
|
||||||
|
var _loc4_:Number = this.w * param1.y + this.y * param1.w + this.z * param1.x - this.x * param1.z;
|
||||||
|
var _loc5_:Number = this.w * param1.z + this.z * param1.w + this.x * param1.y - this.y * param1.x;
|
||||||
|
this.w = _loc2_;
|
||||||
|
this.x = _loc3_;
|
||||||
|
this.y = _loc4_;
|
||||||
|
this.z = _loc5_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function append(param1:Quaternion) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc2_:Number = param1.w * this.w - param1.x * this.x - param1.y * this.y - param1.z * this.z;
|
||||||
|
var _loc3_:Number = param1.w * this.x + param1.x * this.w + param1.y * this.z - param1.z * this.y;
|
||||||
|
var _loc4_:Number = param1.w * this.y + param1.y * this.w + param1.z * this.x - param1.x * this.z;
|
||||||
|
var _loc5_:Number = param1.w * this.z + param1.z * this.w + param1.x * this.y - param1.y * this.x;
|
||||||
|
this.w = _loc2_;
|
||||||
|
this.x = _loc3_;
|
||||||
|
this.y = _loc4_;
|
||||||
|
this.z = _loc5_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rotateByVector(param1:Vector3D) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc2_:Number = -param1.x * this.x - param1.y * this.y - param1.z * this.z;
|
||||||
|
var _loc3_:Number = param1.x * this.w + param1.y * this.z - param1.z * this.y;
|
||||||
|
var _loc4_:Number = param1.y * this.w + param1.z * this.x - param1.x * this.z;
|
||||||
|
var _loc5_:Number = param1.z * this.w + param1.x * this.y - param1.y * this.x;
|
||||||
|
this.w = _loc2_;
|
||||||
|
this.x = _loc3_;
|
||||||
|
this.y = _loc4_;
|
||||||
|
this.z = _loc5_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addScaledVector(param1:Vector3D, param2:Number) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc3_:Number = param1.x * param2;
|
||||||
|
var _loc4_:Number = param1.y * param2;
|
||||||
|
var _loc5_:Number = param1.z * param2;
|
||||||
|
var _loc6_:Number = -this.x * _loc3_ - this.y * _loc4_ - this.z * _loc5_;
|
||||||
|
var _loc7_:Number = _loc3_ * this.w + _loc4_ * this.z - _loc5_ * this.y;
|
||||||
|
var _loc8_:Number = _loc4_ * this.w + _loc5_ * this.x - _loc3_ * this.z;
|
||||||
|
var _loc9_:Number = _loc5_ * this.w + _loc3_ * this.y - _loc4_ * this.x;
|
||||||
|
this.w += 0.5 * _loc6_;
|
||||||
|
this.x += 0.5 * _loc7_;
|
||||||
|
this.y += 0.5 * _loc8_;
|
||||||
|
this.z += 0.5 * _loc9_;
|
||||||
|
var _loc10_:Number = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
|
||||||
|
if(_loc10_ == 0)
|
||||||
|
{
|
||||||
|
this.w = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_loc10_ = 1 / Math.sqrt(_loc10_);
|
||||||
|
this.w *= _loc10_;
|
||||||
|
this.x *= _loc10_;
|
||||||
|
this.y *= _loc10_;
|
||||||
|
this.z *= _loc10_;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*fpublic function toMatrix3(param1:Matrix3) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc7_:Number = NaN;
|
||||||
|
var _loc8_:Number = NaN;
|
||||||
|
var _loc9_:Number = NaN;
|
||||||
|
var _loc2_:Number = 2 * this.x * this.x;
|
||||||
|
var _loc3_:Number = 2 * this.y * this.y;
|
||||||
|
var _loc4_:Number = 2 * this.z * this.z;
|
||||||
|
var _loc5_:Number = 2 * this.x * this.y;
|
||||||
|
var _loc6_:Number = 2 * this.y * this.z;
|
||||||
|
_loc7_ = 2 * this.z * this.x;
|
||||||
|
_loc8_ = 2 * this.w * this.x;
|
||||||
|
_loc9_ = 2 * this.w * this.y;
|
||||||
|
var _loc10_:Number = 2 * this.w * this.z;
|
||||||
|
param1.m00 = 1 - _loc3_ - _loc4_;
|
||||||
|
param1.m01 = _loc5_ - _loc10_;
|
||||||
|
param1.m02 = _loc7_ + _loc9_;
|
||||||
|
param1.m10 = _loc5_ + _loc10_;
|
||||||
|
param1.m11 = 1 - _loc2_ - _loc4_;
|
||||||
|
param1.m12 = _loc6_ - _loc8_;
|
||||||
|
param1.m20 = _loc7_ - _loc9_;
|
||||||
|
param1.m21 = _loc6_ + _loc8_;
|
||||||
|
param1.m22 = 1 - _loc2_ - _loc3_;
|
||||||
|
return this;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public function getYAxis(param1:Vector3D) : Vector3D
|
||||||
|
{
|
||||||
|
var _loc5_:Number = NaN;
|
||||||
|
var _loc2_:Number = 2 * this.x * this.x;
|
||||||
|
var _loc3_:Number = 2 * this.z * this.z;
|
||||||
|
var _loc4_:Number = 2 * this.x * this.y;
|
||||||
|
_loc5_ = 2 * this.y * this.z;
|
||||||
|
var _loc6_:Number = 2 * this.w * this.x;
|
||||||
|
var _loc7_:Number = 2 * this.w * this.z;
|
||||||
|
param1.x = _loc4_ - _loc7_;
|
||||||
|
param1.y = 1 - _loc2_ - _loc3_;
|
||||||
|
param1.z = _loc5_ + _loc6_;
|
||||||
|
return param1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getZAxis(param1:Vector3D) : Vector3D
|
||||||
|
{
|
||||||
|
var _loc2_:Number = NaN;
|
||||||
|
_loc2_ = 2 * this.x * this.x;
|
||||||
|
var _loc3_:Number = 2 * this.y * this.y;
|
||||||
|
var _loc4_:Number = 2 * this.y * this.z;
|
||||||
|
var _loc5_:Number = 2 * this.z * this.x;
|
||||||
|
var _loc6_:Number = 2 * this.w * this.x;
|
||||||
|
var _loc7_:Number = 2 * this.w * this.y;
|
||||||
|
param1.x = _loc5_ + _loc7_;
|
||||||
|
param1.y = _loc4_ - _loc6_;
|
||||||
|
param1.z = 1 - _loc2_ - _loc3_;
|
||||||
|
return param1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public function toMatrix4(param1:Matrix4) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc2_:Number = NaN;
|
||||||
|
var _loc4_:Number = NaN;
|
||||||
|
var _loc6_:Number = NaN;
|
||||||
|
var _loc8_:Number = NaN;
|
||||||
|
_loc2_ = 2 * this.x * this.x;
|
||||||
|
var _loc3_:Number = 2 * this.y * this.y;
|
||||||
|
_loc4_ = 2 * this.z * this.z;
|
||||||
|
var _loc5_:Number = 2 * this.x * this.y;
|
||||||
|
_loc6_ = 2 * this.y * this.z;
|
||||||
|
var _loc7_:Number = 2 * this.z * this.x;
|
||||||
|
_loc8_ = 2 * this.w * this.x;
|
||||||
|
var _loc9_:Number = 2 * this.w * this.y;
|
||||||
|
var _loc10_:Number = 2 * this.w * this.z;
|
||||||
|
param1.m00 = 1 - _loc3_ - _loc4_;
|
||||||
|
param1.m01 = _loc5_ - _loc10_;
|
||||||
|
param1.m02 = _loc7_ + _loc9_;
|
||||||
|
param1.m10 = _loc5_ + _loc10_;
|
||||||
|
param1.m11 = 1 - _loc2_ - _loc4_;
|
||||||
|
param1.m12 = _loc6_ - _loc8_;
|
||||||
|
param1.m20 = _loc7_ - _loc9_;
|
||||||
|
param1.m21 = _loc6_ + _loc8_;
|
||||||
|
param1.m22 = 1 - _loc2_ - _loc3_;
|
||||||
|
return this;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public function length() : Number
|
||||||
|
{
|
||||||
|
return Math.sqrt(this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function lengthSqr() : Number
|
||||||
|
{
|
||||||
|
return this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFromAxisAngle(param1:Vector3D, param2:Number) : Quaternion
|
||||||
|
{
|
||||||
|
this.w = Math.cos(0.5 * param2);
|
||||||
|
var _loc3_:Number = Math.sin(0.5 * param2) / Math.sqrt(param1.x * param1.x + param1.y * param1.y + param1.z * param1.z);
|
||||||
|
this.x = param1.x * _loc3_;
|
||||||
|
this.y = param1.y * _loc3_;
|
||||||
|
this.z = param1.z * _loc3_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFromAxisAngleComponents(param1:Number, param2:Number, param3:Number, param4:Number) : Quaternion
|
||||||
|
{
|
||||||
|
this.w = Math.cos(0.5 * param4);
|
||||||
|
var _loc5_:Number = Math.sin(0.5 * param4) / Math.sqrt(param1 * param1 + param2 * param2 + param3 * param3);
|
||||||
|
this.x = param1 * _loc5_;
|
||||||
|
this.y = param2 * _loc5_;
|
||||||
|
this.z = param3 * _loc5_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toAxisVector(param1:Vector3D = null) : Vector3D
|
||||||
|
{
|
||||||
|
var _loc2_:Number = NaN;
|
||||||
|
var _loc3_:Number = NaN;
|
||||||
|
if(this.w < -1 || this.w > 1)
|
||||||
|
{
|
||||||
|
this.normalize();
|
||||||
|
}
|
||||||
|
if(param1 == null)
|
||||||
|
{
|
||||||
|
param1 = new Vector3D();
|
||||||
|
}
|
||||||
|
if(this.w > -1 && this.w < 1)
|
||||||
|
{
|
||||||
|
if(this.w == 0)
|
||||||
|
{
|
||||||
|
param1.x = this.x;
|
||||||
|
param1.y = this.y;
|
||||||
|
param1.z = this.z;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_loc2_ = 2 * Math.acos(this.w);
|
||||||
|
_loc3_ = 1 / Math.sqrt(1 - this.w * this.w);
|
||||||
|
param1.x = this.x * _loc3_ * _loc2_;
|
||||||
|
param1.y = this.y * _loc3_ * _loc2_;
|
||||||
|
param1.z = this.z * _loc3_ * _loc2_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
param1.x = 0;
|
||||||
|
param1.y = 0;
|
||||||
|
param1.z = 0;
|
||||||
|
}
|
||||||
|
return param1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEulerAngles(param1:Vector3D) : Vector3D
|
||||||
|
{
|
||||||
|
var _loc2_:Number = 2 * this.x * this.x;
|
||||||
|
var _loc3_:Number = 2 * this.y * this.y;
|
||||||
|
var _loc4_:Number = 2 * this.z * this.z;
|
||||||
|
var _loc5_:Number = 2 * this.x * this.y;
|
||||||
|
var _loc6_:Number = 2 * this.y * this.z;
|
||||||
|
var _loc7_:Number = 2 * this.z * this.x;
|
||||||
|
var _loc8_:Number = 2 * this.w * this.x;
|
||||||
|
var _loc9_:Number = 2 * this.w * this.y;
|
||||||
|
var _loc10_:Number = 2 * this.w * this.z;
|
||||||
|
var _loc11_:Number = 1 - _loc3_ - _loc4_;
|
||||||
|
var _loc12_:Number = _loc5_ - _loc10_;
|
||||||
|
var _loc13_:Number = _loc5_ + _loc10_;
|
||||||
|
var _loc14_:Number = 1 - _loc2_ - _loc4_;
|
||||||
|
var _loc15_:Number = _loc7_ - _loc9_;
|
||||||
|
var _loc16_:Number = _loc6_ + _loc8_;
|
||||||
|
var _loc17_:Number = 1 - _loc2_ - _loc3_;
|
||||||
|
if(-1 < _loc15_ && _loc15_ < 1)
|
||||||
|
{
|
||||||
|
if(param1 == null)
|
||||||
|
{
|
||||||
|
param1 = new Vector3D(Math.atan2(_loc16_,_loc17_),-Math.asin(_loc15_),Math.atan2(_loc13_,_loc11_));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
param1.x = Math.atan2(_loc16_,_loc17_);
|
||||||
|
param1.y = -Math.asin(_loc15_);
|
||||||
|
param1.z = Math.atan2(_loc13_,_loc11_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(param1 == null)
|
||||||
|
{
|
||||||
|
param1 = new Vector3D(0,0.5 * (_loc15_ <= -1 ? Math.PI : -Math.PI),Math.atan2(-_loc12_,_loc14_));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
param1.x = 0;
|
||||||
|
param1.y = _loc15_ <= -1 ? Math.PI : -Math.PI;
|
||||||
|
param1.y *= 0.5;
|
||||||
|
param1.z = Math.atan2(-_loc12_,_loc14_);
|
||||||
|
}
|
||||||
|
return param1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFromEulerAnglesXYZ(param1:Number, param2:Number, param3:Number) : void
|
||||||
|
{
|
||||||
|
this.setFromAxisAngleComponents(1,0,0,param1);
|
||||||
|
_q.setFromAxisAngleComponents(0,1,0,param2);
|
||||||
|
this.append(_q);
|
||||||
|
this.normalize();
|
||||||
|
_q.setFromAxisAngleComponents(0,0,1,param3);
|
||||||
|
this.append(_q);
|
||||||
|
this.normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFromEulerAngles(param1:Vector3D) : void
|
||||||
|
{
|
||||||
|
this.setFromEulerAnglesXYZ(param1.x,param1.y,param1.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function conjugate() : void
|
||||||
|
{
|
||||||
|
this.x = -this.x;
|
||||||
|
this.y = -this.y;
|
||||||
|
this.z = -this.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function nlerp(param1:Quaternion, param2:Quaternion, param3:Number) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc4_:Number = 1 - param3;
|
||||||
|
this.w = param1.w * _loc4_ + param2.w * param3;
|
||||||
|
this.x = param1.x * _loc4_ + param2.x * param3;
|
||||||
|
this.y = param1.y * _loc4_ + param2.y * param3;
|
||||||
|
this.z = param1.z * _loc4_ + param2.z * param3;
|
||||||
|
_loc4_ = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
|
||||||
|
if(_loc4_ == 0)
|
||||||
|
{
|
||||||
|
this.w = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_loc4_ = 1 / Math.sqrt(_loc4_);
|
||||||
|
this.w *= _loc4_;
|
||||||
|
this.x *= _loc4_;
|
||||||
|
this.y *= _loc4_;
|
||||||
|
this.z *= _loc4_;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function subtract(param1:Quaternion) : Quaternion
|
||||||
|
{
|
||||||
|
this.w -= param1.w;
|
||||||
|
this.x -= param1.x;
|
||||||
|
this.y -= param1.y;
|
||||||
|
this.z -= param1.z;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function diff(param1:Quaternion, param2:Quaternion) : Quaternion
|
||||||
|
{
|
||||||
|
this.w = param2.w - param1.w;
|
||||||
|
this.x = param2.x - param1.x;
|
||||||
|
this.y = param2.y - param1.y;
|
||||||
|
this.z = param2.z - param1.z;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function copy(param1:Quaternion) : Quaternion
|
||||||
|
{
|
||||||
|
this.w = param1.w;
|
||||||
|
this.x = param1.x;
|
||||||
|
this.y = param1.y;
|
||||||
|
this.z = param1.z;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toVector3D(param1:Vector3D) : Vector3D
|
||||||
|
{
|
||||||
|
param1.x = this.x;
|
||||||
|
param1.y = this.y;
|
||||||
|
param1.z = this.z;
|
||||||
|
param1.w = this.w;
|
||||||
|
return param1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clone() : Quaternion
|
||||||
|
{
|
||||||
|
return new Quaternion(this.w,this.x,this.y,this.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toString() : String
|
||||||
|
{
|
||||||
|
return getQualifiedClassName(this) + "(" + this.w + ", " + this.x + ", " + this.y + ", " + this.z + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function slerp(param1:Quaternion, param2:Quaternion, param3:Number) : Quaternion
|
||||||
|
{
|
||||||
|
var _loc6_:Number = NaN;
|
||||||
|
var _loc7_:Number = NaN;
|
||||||
|
var _loc8_:Number = NaN;
|
||||||
|
var _loc9_:Number = NaN;
|
||||||
|
var _loc10_:Number = NaN;
|
||||||
|
var _loc11_:Number = NaN;
|
||||||
|
var _loc4_:Number = 1;
|
||||||
|
var _loc5_:Number = param1.w * param2.w + param1.x * param2.x + param1.y * param2.y + param1.z * param2.z;
|
||||||
|
if(_loc5_ < 0)
|
||||||
|
{
|
||||||
|
_loc5_ = -_loc5_;
|
||||||
|
_loc4_ = -1;
|
||||||
|
}
|
||||||
|
if(1 - _loc5_ < 0.001)
|
||||||
|
{
|
||||||
|
_loc6_ = 1 - param3;
|
||||||
|
_loc7_ = param3 * _loc4_;
|
||||||
|
this.w = param1.w * _loc6_ + param2.w * _loc7_;
|
||||||
|
this.x = param1.x * _loc6_ + param2.x * _loc7_;
|
||||||
|
this.y = param1.y * _loc6_ + param2.y * _loc7_;
|
||||||
|
this.z = param1.z * _loc6_ + param2.z * _loc7_;
|
||||||
|
this.normalize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_loc8_ = Math.acos(_loc5_);
|
||||||
|
_loc9_ = Math.sin(_loc8_);
|
||||||
|
_loc10_ = Math.sin((1 - param3) * _loc8_) / _loc9_;
|
||||||
|
_loc11_ = Math.sin(param3 * _loc8_) / _loc9_ * _loc4_;
|
||||||
|
this.w = param1.w * _loc10_ + param2.w * _loc11_;
|
||||||
|
this.x = param1.x * _loc10_ + param2.x * _loc11_;
|
||||||
|
this.y = param1.y * _loc10_ + param2.y * _loc11_;
|
||||||
|
this.z = param1.z * _loc10_ + param2.z * _loc11_;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isFiniteQuaternion() : Boolean
|
||||||
|
{
|
||||||
|
return isFinite(this.w) && isFinite(this.x) && isFinite(this.y) && isFinite(this.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user