📄 matrix3d.as
字号:
package away3d.core.math{ /** * A 3D transformation 4x3 matrix */ public final class Matrix3D { private const toDEGREES:Number = 180 / Math.PI; private var _position:Number3D = new Number3D(); private var m111:Number, m211:Number; private var m121:Number, m221:Number; private var m131:Number, m231:Number; private var m112:Number, m212:Number; private var m122:Number, m222:Number; private var m132:Number, m232:Number; private var m113:Number, m213:Number; private var m123:Number, m223:Number; private var m133:Number, m233:Number; private var m114:Number, m214:Number; private var m124:Number, m224:Number; private var m134:Number, m234:Number; private var nCos:Number; private var nSin:Number; private var scos:Number; private var suv:Number; private var svw:Number; private var suw:Number; private var sw:Number; private var sv:Number; private var su:Number; private var d:Number; private var x:Number; private var y:Number; private var z:Number; private var w:Number; private var xx:Number; private var xy:Number; private var xz:Number; private var xw:Number; private var yy:Number; private var yz:Number; private var yw:Number; private var zz:Number; private var zw:Number; /** * The value in the first row and first column of the Matrix object, * which affect the rotation and scaling of a 3d object. */ public var sxx:Number; /** * The value in the first row and second column of the Matrix object, * which affect the rotation and scaling of a 3d object. */ public var sxy:Number; /** * The value in the first row and third column of the Matrix object, * which affect the rotation and scaling of a 3d object. */ public var sxz:Number; /** * The value in the first row and forth column of the Matrix object, * which affects the positioning along the x axis of a 3d object. */ public var tx:Number; /** * The value in the second row and first column of the Matrix object, * which affect the rotation and scaling of a 3d object. */ public var syx:Number; /** * The value in the second row and second column of the Matrix object, * which affect the rotation and scaling of a 3d object. */ public var syy:Number; /** * The value in the second row and third column of the Matrix object, * which affect the rotation and scaling of a 3d object. */ public var syz:Number; /** * The value in the second row and fourth column of the Matrix object, * which affects the positioning along the y axis of a 3d object. */ public var ty:Number; /** * The value in the third row and first column of the Matrix object, * which affects the rotation and scaling of a 3d object. */ public var szx:Number; /** * The value in the third row and second column of the Matrix object, * which affect the rotation and scaling of a 3d object. */ public var szy:Number; /** * The value in the third row and third column of the Matrix object, * which affect the rotation and scaling of a 3d object. */ public var szz:Number; /** * The value in the third row and fourth column of the Matrix object, * which affects the positioning along the z axis of a 3d object. */ public var tz:Number; /** * Returns a 3d number representing the translation imposed by the 3dmatrix. */ public function get position():Number3D { _position.x = tx; _position.y = ty; _position.z = tz; return _position; } /** * Returns the 3d matrix object's determinant. * * @return The determinant of the 3d matrix. */ public function get det():Number { return (sxx * syy - syx * sxy) * szz - (sxx * szy - szx * sxy) * syz + (syx * szy - szx * syy) * sxz; } /** * Creates a new <code>Matrix3D</code> object. */ public function Matrix3D() { sxx = syy = szz = 1; sxy = sxz = tx = syx = syz = ty = szx = szy = tz = 0; } /** * Fills the 3d matrix object with values from an array with 3d matrix values * ordered from right to left and up to down. */ public function array2matrix(ar:Array):void { if (ar.length >= 12) { sxx = ar[0]; sxy = ar[1]; sxz = ar[2]; tx = ar[3]; syx = ar[4]; syy = ar[5]; syz = ar[6]; ty = ar[7]; szx = ar[8]; szy = ar[9]; szz = ar[10]; tz = ar[11]; } } /** * Used to trace the values of a 3d matrix. * * @return A string representation of the 3d matrix object. */ public function toString(): String { var s:String = ""; s += int(sxx*1000) / 1000 + "\t\t" + int(sxy*1000) / 1000 + "\t\t" + int(sxz*1000) / 1000 + "\t\t" + int(tx*1000) / 1000 + "\n"; s += int(syx*1000) / 1000 + "\t\t" + int(syy*1000) / 1000 + "\t\t" + int(syz*1000) / 1000 + "\t\t" + int(ty*1000) / 1000 + "\n"; s += int(szx*1000) / 1000 + "\t\t" + int(szy*1000) / 1000 + "\t\t" + int(szz*1000) / 1000 + "\t\t" + int(tz*1000) / 1000 + "\n"; return s; } /** * Fills the 3d matrix object with the result from a 3x3 multipication of two 3d matrix objects. * The translation values are taken from the first matrix. * * @param m1 The first 3d matrix in the multipication. * @oaram m2 The second 3d matrix in the multipication. */ public function multiply3x3(m1:Matrix3D, m2:Matrix3D):void { m111 = m1.sxx; m211 = m2.sxx; m121 = m1.syx; m221 = m2.syx; m131 = m1.szx; m231 = m2.szx; m112 = m1.sxy; m212 = m2.sxy; m122 = m1.syy; m222 = m2.syy; m132 = m1.szy; m232 = m2.szy; m113 = m1.sxz; m213 = m2.sxz; m123 = m1.syz; m223 = m2.syz; m133 = m1.szz; m233 = m2.szz; sxx = m111 * m211 + m112 * m221 + m113 * m231; sxy = m111 * m212 + m112 * m222 + m113 * m232; sxz = m111 * m213 + m112 * m223 + m113 * m233; syx = m121 * m211 + m122 * m221 + m123 * m231; syy = m121 * m212 + m122 * m222 + m123 * m232; syz = m121 * m213 + m122 * m223 + m123 * m233; szx = m131 * m211 + m132 * m221 + m133 * m231; szy = m131 * m212 + m132 * m222 + m133 * m232; szz = m131 * m213 + m132 * m223 + m133 * m233; tx = m1.tx; ty = m1.ty; tz = m1.tz; } /** * Fills the 3d matrix object with the result from a 3x4 multipication of two 3d matrix objects. * * @param m1 The first 3d matrix in the multipication. * @oaram m2 The second 3d matrix in the multipication. */ public function multiply(m1:Matrix3D, m2:Matrix3D):void { m111 = m1.sxx; m211 = m2.sxx; m121 = m1.syx; m221 = m2.syx; m131 = m1.szx; m231 = m2.szx; m112 = m1.sxy; m212 = m2.sxy; m122 = m1.syy; m222 = m2.syy; m132 = m1.szy; m232 = m2.szy; m113 = m1.sxz; m213 = m2.sxz; m123 = m1.syz; m223 = m2.syz; m133 = m1.szz; m233 = m2.szz;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -