📄 matrix.js
字号:
if(!dojo._hasResource["dojox.gfx3d.matrix"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojox.gfx3d.matrix"] = true;dojo.provide("dojox.gfx3d.matrix");// candidates for dojox.math:dojox.gfx3d.matrix._degToRad = function(degree){ return Math.PI * degree / 180; };dojox.gfx3d.matrix._radToDeg = function(radian){ return radian / Math.PI * 180; };dojox.gfx3d.matrix.Matrix3D = function(arg){ // summary: a 3D matrix object // description: Normalizes a 3D matrix-like object. If arrays is passed, // all objects of the array are normalized and multiplied sequentially. // arg: Object // a 3D matrix-like object, a number, or an array of such objects if(arg){ if(typeof arg == "number"){ this.xx = this.yy = this.zz = arg; }else if(arg instanceof Array){ if(arg.length > 0){ var m = dojox.gfx3d.matrix.normalize(arg[0]); // combine matrices for(var i = 1; i < arg.length; ++i){ var l = m; var r = dojox.gfx3d.matrix.normalize(arg[i]); m = new dojox.gfx3d.matrix.Matrix3D(); m.xx = l.xx * r.xx + l.xy * r.yx + l.xz * r.zx; m.xy = l.xx * r.xy + l.xy * r.yy + l.xz * r.zy; m.xz = l.xx * r.xz + l.xy * r.yz + l.xz * r.zz; m.yx = l.yx * r.xx + l.yy * r.yx + l.yz * r.zx; m.yy = l.yx * r.xy + l.yy * r.yy + l.yz * r.zy; m.yz = l.yx * r.xz + l.yy * r.yz + l.yz * r.zz; m.zx = l.zx * r.xx + l.zy * r.yx + l.zz * r.zx; m.zy = l.zx * r.xy + l.zy * r.yy + l.zz * r.zy; m.zz = l.zx * r.xz + l.zy * r.yz + l.zz * r.zz; m.dx = l.xx * r.dx + l.xy * r.dy + l.xz * r.dz + l.dx; m.dy = l.yx * r.dx + l.yy * r.dy + l.yz * r.dz + l.dy; m.dz = l.zx * r.dx + l.zy * r.dy + l.zz * r.dz + l.dz; } dojo.mixin(this, m); } }else{ dojo.mixin(this, arg); } }};// the default (identity) matrix, which is used to fill in missing valuesdojo.extend(dojox.gfx3d.matrix.Matrix3D, {xx: 1, xy: 0, xz: 0, yx: 0, yy: 1, yz: 0, zx: 0, zy: 0, zz: 1, dx: 0, dy: 0, dz: 0});dojo.mixin(dojox.gfx3d.matrix, { // summary: class constants, and methods of dojox.gfx3d.matrix // matrix constants // identity: dojox.gfx3d.matrix.Matrix3D // an identity matrix constant: identity * (x, y, z) == (x, y, z) identity: new dojox.gfx3d.matrix.Matrix3D(), // matrix creators translate: function(a, b, c){ // summary: forms a translation matrix // description: The resulting matrix is used to translate (move) points by specified offsets. // a: Number: an x coordinate value // b: Number: a y coordinate value // c: Number: a z coordinate value if(arguments.length > 1){ return new dojox.gfx3d.matrix.Matrix3D({dx: a, dy: b, dz: c}); // dojox.gfx3d.matrix.Matrix3D } // branch // a: Object: a point-like object, which specifies offsets for 3 dimensions // b: null return new dojox.gfx3d.matrix.Matrix3D({dx: a.x, dy: a.y, dz: a.z}); // dojox.gfx3d.matrix.Matrix3D }, scale: function(a, b, c){ // summary: forms a scaling matrix // description: The resulting matrix is used to scale (magnify) points by specified offsets. // a: Number: a scaling factor used for the x coordinate // b: Number: a scaling factor used for the y coordinate // c: Number: a scaling factor used for the z coordinate if(arguments.length > 1){ return new dojox.gfx3d.matrix.Matrix3D({xx: a, yy: b, zz: c}); // dojox.gfx3d.matrix.Matrix3D } if(typeof a == "number"){ // branch // a: Number: a uniform scaling factor used for the all coordinates // b: null return new dojox.gfx3d.matrix.Matrix3D({xx: a, yy: a, zz: a}); // dojox.gfx3d.matrix.Matrix3D } // branch // a: Object: a point-like object, which specifies scale factors for 3 dimensions // b: null return new dojox.gfx3d.matrix.Matrix3D({xx: a.x, yy: a.y, zz: a.z}); // dojox.gfx3d.matrix.Matrix3D }, rotateX: function(angle){ // summary: forms a rotating matrix (about the x axis) // description: The resulting matrix is used to rotate points // around the origin of coordinates (0, 0) by specified angle. // angle: Number: an angle of rotation in radians (>0 for CW) var c = Math.cos(angle); var s = Math.sin(angle); return new dojox.gfx3d.matrix.Matrix3D({yy: c, yz: -s, zy: s, zz: c}); // dojox.gfx3d.matrix.Matrix3D }, rotateXg: function(degree){ // summary: forms a rotating matrix (about the x axis) // description: The resulting matrix is used to rotate points // around the origin of coordinates (0, 0) by specified degree. // See dojox.gfx3d.matrix.rotateX() for comparison. // degree: Number: an angle of rotation in degrees (>0 for CW) return dojox.gfx3d.matrix.rotateX(dojox.gfx3d.matrix._degToRad(degree)); // dojox.gfx3d.matrix.Matrix3D }, rotateY: function(angle){ // summary: forms a rotating matrix (about the y axis) // description: The resulting matrix is used to rotate points // around the origin of coordinates (0, 0) by specified angle. // angle: Number: an angle of rotation in radians (>0 for CW) var c = Math.cos(angle); var s = Math.sin(angle); return new dojox.gfx3d.matrix.Matrix3D({xx: c, xz: s, zx: -s, zz: c}); // dojox.gfx3d.matrix.Matrix3D }, rotateYg: function(degree){ // summary: forms a rotating matrix (about the y axis) // description: The resulting matrix is used to rotate points // around the origin of coordinates (0, 0) by specified degree. // See dojox.gfx3d.matrix.rotateY() for comparison. // degree: Number: an angle of rotation in degrees (>0 for CW) return dojox.gfx3d.matrix.rotateY(dojox.gfx3d.matrix._degToRad(degree)); // dojox.gfx3d.matrix.Matrix3D }, rotateZ: function(angle){ // summary: forms a rotating matrix (about the z axis) // description: The resulting matrix is used to rotate points // around the origin of coordinates (0, 0) by specified angle. // angle: Number: an angle of rotation in radians (>0 for CW) var c = Math.cos(angle); var s = Math.sin(angle); return new dojox.gfx3d.matrix.Matrix3D({xx: c, xy: -s, yx: s, yy: c}); // dojox.gfx3d.matrix.Matrix3D }, rotateZg: function(degree){ // summary: forms a rotating matrix (about the z axis) // description: The resulting matrix is used to rotate points // around the origin of coordinates (0, 0) by specified degree. // See dojox.gfx3d.matrix.rotateZ() for comparison. // degree: Number: an angle of rotation in degrees (>0 for CW) return dojox.gfx3d.matrix.rotateZ(dojox.gfx3d.matrix._degToRad(degree)); // dojox.gfx3d.matrix.Matrix3D }, // camera transformation cameraTranslate: function(a, b, c){ // summary: forms a translation matrix // description: The resulting matrix is used to translate (move) points by specified offsets. // a: Number: an x coordinate value // b: Number: a y coordinate value // c: Number: a z coordinate value if(arguments.length > 1){ return new dojox.gfx3d.matrix.Matrix3D({dx: -a, dy: -b, dz: -c}); // dojox.gfx3d.matrix.Matrix3D } // branch // a: Object: a point-like object, which specifies offsets for 3 dimensions // b: null return new dojox.gfx3d.matrix.Matrix3D({dx: -a.x, dy: -a.y, dz: -a.z}); // dojox.gfx3d.matrix.Matrix3D }, cameraRotateX: function(angle){ // summary: forms a rotating matrix (about the x axis) in cameraTransform manner // description: The resulting matrix is used to rotate points // around the origin of coordinates (0, 0) by specified angle. // angle: Number: an angle of rotation in radians (>0 for CW) var c = Math.cos(-angle); var s = Math.sin(-angle); return new dojox.gfx3d.matrix.Matrix3D({yy: c, yz: -s, zy: s, zz: c}); // dojox.gfx3d.matrix.Matrix3D },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -