大神,连连看的图片轮播js代码原理是矩阵原理吗?

&>&&>&&>&&>&JS连连看游戏源码
JS连连看游戏源码
上传大小:28KB
JS连连看 游戏 源码
Javascript
综合评分:0(0位用户评分)
所需积分:0
下载次数:32
审核通过送C币
创建者:guo8ke
创建者:qq
课程推荐相关知识库
积分&33162
上传者其他资源上传者专辑
开发技术热门标签
VIP会员动态
android服务器底层网络模块的设计方法
所需积分:0
剩余积分:720
您当前C币:0
可兑换下载积分:0
兑换下载分:
兑换失败,您当前C币不够,请先充值C币
消耗C币:0
你当前的下载分为234。
JS连连看游戏源码
会员到期时间:
剩余下载次数:
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:three.js 源码注释(九)Math/Matrix4.js
转载请保留此句:商域无疆 - 本博客专注于 敏捷开发及移动和物联设备研究:数据可视化、GOLANG、Html5、WEBGL、THREE.JS,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
今天把math库中最大的对象Matrix4注释完了,发现之前好多的注释理解的不太正确,还有好多的注释因为马虎,好多小错误.能改的都在github上更新了,不过大概意思,暂时我认为是正确的.哈哈哈:)
以下代码是THREE.JS 文件中Math/Matrix4.js文件的注释.
更多更新在 : /omni360/three.js.sourcecode/blob/master/Three.js
// File:src/math/Matrix4.js
* @author mrdoob / /
* @author supereggbert / http://www.paulbrunt.co.uk/
* @author philogb / http://blog.thejit.org/
* @author jordi_ros /
* @author D1plo1d / /D1plo1d
* @author alteredq / /
* @author mikael emtinger / http://gomo.se/
* @author timknip / /
* @author bhouston /
* @author WestLangley / /WestLangley
///Matrix4对象的构造函数.用来创建一个4x4矩阵.Matrix4对象的功能函数采用
///定义构造的函数原型对象来实现,实际就是一个数组.
/// 用法: var m = new Matrix4(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44)
/// 创建一个4x4的矩阵,其实就是一个长度为9的数组,将参数(11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43, 44)传递给数组用来初始化.
/// 一个变换矩阵可以执行任意的线形3D变换(例如,平移,旋转,缩放,切边等等)并且透视变换使用齐次坐标。
/// 脚本中很少使用矩阵:最常用Vector3,Quaternion,而且Transform类的功能更简单。单纯的矩阵用于特殊情况,如设置非标准相机投影。
/// NOTE: 参数 n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, 41, 42, 43, 44 代表4x4矩阵中的元素的值,n11表示矩阵的第一行,第一列的元素值
///Matrix4
///n11第 1 行,第 1 列的元素值
///n12第 1 行,第 2 列的元素值
///n13第 1 行,第 3 列的元素值
///n13第 1 行,第 4 列的元素值
///n21第 2 行,第 1 列的元素值
///n22第 2 行,第 2 列的元素值
///n23第 2 行,第 3 列的元素值
///n23第 2 行,第 4 列的元素值
///n31第 3 行,第 1 列的元素值
///n32第 3 行,第 2 列的元素值
///n33第 3 行,第 3 列的元素值
///n33第 3 行,第 4 列的元素值
///n31第 4 行,第 1 列的元素值
///n32第 4 行,第 2 列的元素值
///n33第 4 行,第 3 列的元素值
///n33第 4 行,第 4 列的元素值
///返回新的4x4矩阵
THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
this.elements = new Float32Array( 16 );
// TODO: 如果n11没有定义,Matrix4将被初始化为一个单位矩阵.如果n11定义了值,直接复制该值到矩阵中.
// TODO: if n11 is undefined, then just set to identity, otherwise copy all other values into matrix
// 我们不支持semi规范的Matrix4(4x4矩阵),semi规范很奇怪???(英语实在不过关)
we should not support semi specification of Matrix4, it is just weird.
var te = this.
te[ 0 ] = ( n11 !== undefined ) ? n11 : 1; te[ 4 ] = n12 || 0; te[ 8 ] = n13 || 0; te[ 12 ] = n14 || 0;
te[ 1 ] = n21 || 0; te[ 5 ] = ( n22 !== undefined ) ? n22 : 1; te[ 9 ] = n23 || 0; te[ 13 ] = n24 || 0;
te[ 2 ] = n31 || 0; te[ 6 ] = n32 || 0; te[ 10 ] = ( n33 !== undefined ) ? n33 : 1; te[ 14 ] = n34 || 0;
te[ 3 ] = n41 || 0; te[ 7 ] = n42 || 0; te[ 11 ] = n43 || 0; te[ 15 ] = ( n44 !== undefined ) ? n44 : 1; //初始化Matrix4(4x4矩阵)对象.
/****************************************
****下面是Matrix4对象提供的功能函数.
****************************************/
THREE.Matrix4.prototype = {
constructor: THREE.Matrix4, //构造器
///set方法用来从新设置Matrix4(4x4矩阵)的元素值.并返回新的坐标值的Matrix4(4x4矩阵).
/// TODO:修改set方法,兼容 n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, 41, 42, 43, 44 参数省略支持多态.
///n11第 1 行,第 1 列的元素值
///n12第 1 行,第 2 列的元素值
///n13第 1 行,第 3 列的元素值
///n13第 1 行,第 4 列的元素值
///n21第 2 行,第 1 列的元素值
///n22第 2 行,第 2 列的元素值
///n23第 2 行,第 3 列的元素值
///n23第 2 行,第 4 列的元素值
///n31第 3 行,第 1 列的元素值
///n32第 3 行,第 2 列的元素值
///n33第 3 行,第 3 列的元素值
///n33第 3 行,第 4 列的元素值
///n31第 4 行,第 1 列的元素值
///n32第 4 行,第 2 列的元素值
///n33第 4 行,第 3 列的元素值
///n33第 4 行,第 4 列的元素值
///返回新的4x4矩阵
set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
var te = this.
te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
//返回新的4x4矩阵
///identity方法用来获得一个4x4矩阵的单位矩阵
/// NOTE:在矩阵的乘法中,有一种矩阵起着特殊的作用,如同数的乘法中的1,我们称这种矩阵为单位矩阵
它是个方阵,从左上角到右下角的对角线(称为主对角线)上的元素均为1以外全都为0。
对于单位矩阵,有AE=EA=A
///identity
///返回4x4矩阵的一个单位矩阵
identity: function () {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
//返回4x4矩阵的一个单位矩阵
///copy方法用来复制4x4矩阵的元素值.并返回新的Matrix4(4x4矩阵).
///Matrix4(4x4矩阵)
///返回新的Matrix4(4x4矩阵)
copy: function ( m ) {
this.elements.set( m.elements );
//返回新的Matrix4(4x4矩阵)
///extractPosition方法用来复制参数m(4x4矩阵)的平移分量.并返回新的Matrix4(4x4矩阵).
/// NOTE: extractPosition方法已经被重命名为.copyPosition()
///extractPosition
///Matrix4(4x4矩阵)
///返回新的Matrix4(4x4矩阵)
extractPosition: function ( m ) {
console.warn( 'THREEMatrix4: .extractPosition() has been renamed to .copyPosition().' );
return this.copyPosition( m ); //调用copyPosition()方法,返回新的Matrix4(4x4矩阵)
///copyPosition方法用来复制参数m(4x4矩阵)的平移分量.并返回新的Matrix4(4x4矩阵).
///copyPosition
///Matrix4(4x4矩阵)
///返回新的Matrix4(4x4矩阵)
copyPosition: function ( m ) {
var te = this.
var me = m.
te[ 12 ] = me[ 12 ];
te[ 13 ] = me[ 13 ];
te[ 14 ] = me[ 14 ];
//返回新的Matrix4(4x4矩阵)
///extractRotation方法用来提取参数m(4x4矩阵)的旋转分量.并返回新的Matrix4(4x4矩阵).
///extractRotation
///Matrix4(4x4矩阵)
///返回新的Matrix4(4x4矩阵)
extractRotation: function () {
var v1 = new THREE.Vector3();
return function ( m ) {
var te = this.
var me = m.
var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
te[ 0 ] = me[ 0 ] * scaleX;
te[ 1 ] = me[ 1 ] * scaleX;
te[ 2 ] = me[ 2 ] * scaleX;
te[ 4 ] = me[ 4 ] * scaleY;
te[ 5 ] = me[ 5 ] * scaleY;
te[ 6 ] = me[ 6 ] * scaleY;
te[ 8 ] = me[ 8 ] * scaleZ;
te[ 9 ] = me[ 9 ] * scaleZ;
te[ 10 ] = me[ 10 ] * scaleZ;
//返回新的Matrix4(4x4矩阵)
///applyEuler方法通过欧拉旋转(参数euler)对Matrix4(4x4矩阵)应用旋转变换.
///applyEuler
///THREE.Euler对象,欧拉对象
///返回变换后的Matrix4(4x4矩阵)
makeRotationFromEuler: function ( euler ) {
if ( euler instanceof THREE.Euler === false ) {
console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
var te = this.
var x = euler.x, y = euler.y, z = euler.z;
var a = Math.cos( x ), b = Math.sin( x );
var c = Math.cos( y ), d = Math.sin( y );
var e = Math.cos( z ), f = Math.sin( z );
if ( euler.order === 'XYZ' ) {
var ae = a * e, af = a * f, be = b * e, bf = b *
te[ 0 ] = c *
te[ 4 ] = - c *
te[ 1 ] = af + be *
te[ 5 ] = ae - bf *
te[ 9 ] = - b *
te[ 2 ] = bf - ae *
te[ 6 ] = be + af *
te[ 10 ] = a *
} else if ( euler.order === 'YXZ' ) {
var ce = c * e, cf = c * f, de = d * e, df = d *
te[ 0 ] = ce + df *
te[ 4 ] = de * b -
te[ 8 ] = a *
te[ 1 ] = a *
te[ 5 ] = a *
te[ 9 ] = -
te[ 2 ] = cf * b -
te[ 6 ] = df + ce *
te[ 10 ] = a *
} else if ( euler.order === 'ZXY' ) {
var ce = c * e, cf = c * f, de = d * e, df = d *
te[ 0 ] = ce - df *
te[ 4 ] = - a *
te[ 8 ] = de + cf *
te[ 1 ] = cf + de *
te[ 5 ] = a *
te[ 9 ] = df - ce *
te[ 2 ] = - a *
te[ 10 ] = a *
} else if ( euler.order === 'ZYX' ) {
var ae = a * e, af = a * f, be = b * e, bf = b *
te[ 0 ] = c *
te[ 4 ] = be * d -
te[ 8 ] = ae * d +
te[ 1 ] = c *
te[ 5 ] = bf * d +
te[ 9 ] = af * d -
te[ 2 ] = -
te[ 6 ] = b *
te[ 10 ] = a *
} else if ( euler.order === 'YZX' ) {
var ac = a * c, ad = a * d, bc = b * c, bd = b *
te[ 0 ] = c *
te[ 4 ] = bd - ac *
te[ 8 ] = bc * f +
te[ 5 ] = a *
te[ 9 ] = - b *
te[ 2 ] = - d *
te[ 6 ] = ad * f +
te[ 10 ] = ac - bd *
} else if ( euler.order === 'XZY' ) {
var ac = a * c, ad = a * d, bc = b * c, bd = b *
te[ 0 ] = c *
te[ 4 ] = -
te[ 8 ] = d *
te[ 1 ] = ac * f +
te[ 5 ] = a *
te[ 9 ] = ad * f -
te[ 2 ] = bc * f -
te[ 6 ] = b *
te[ 10 ] = bd * f +
//最后一列
// last column
te[ 3 ] = 0;
te[ 7 ] = 0;
te[ 11 ] = 0;
//最下面的一行
// bottom row
te[ 12 ] = 0;
te[ 13 ] = 0;
te[ 14 ] = 0;
te[ 15 ] = 1;
//返回变换后的Matrix4(4x4矩阵)
///setRotationFromQuaternion方法通过四元数对Matrix4(4x4矩阵)应用旋转变换.
/// NOTE: setRotationFromQuaternion()方法已经被重命名为makeRotationFromQuaternion(),这里保留是为了向下兼容.
///setRotationFromQuaternion
///返回新的Matrix4(4x4矩阵)
setRotationFromQuaternion: function ( q ) {
console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
return this.makeRotationFromQuaternion( q ); //调用makeRotationFromQuaternion()方法,应用旋转变换,并返回新的Matrix4(4x4矩阵)对象.
///makeRotationFromQuaternion方法通过四元数对Matrix4(4x4矩阵)应用旋转变换.
///setRotationFromQuaternion
///返回新的Matrix4(4x4矩阵)
makeRotationFromQuaternion: function ( q ) {
var te = this.
var x = q.x, y = q.y, z = q.z, w = q.w;
var x2 = x + x, y2 = y + y, z2 = z +
var xx = x * x2, xy = x * y2, xz = x * z2;
var yy = y * y2, yz = y * z2, zz = z * z2;
var wx = w * x2, wy = w * y2, wz = w * z2;
te[ 0 ] = 1 - ( yy + zz );
te[ 4 ] = xy -
te[ 8 ] = xz +
te[ 1 ] = xy +
te[ 5 ] = 1 - ( xx + zz );
te[ 9 ] = yz -
te[ 2 ] = xz -
te[ 6 ] = yz +
te[ 10 ] = 1 - ( xx + yy );
//最后一列
// last column
te[ 3 ] = 0;
te[ 7 ] = 0;
te[ 11 ] = 0;
//最后一行
// bottom row
te[ 12 ] = 0;
te[ 13 ] = 0;
te[ 14 ] = 0;
te[ 15 ] = 1;
//返回新的Matrix4(4x4矩阵)
///lookAt(eye,center,up)将对象设定为一个视图矩阵,参数都是Vector3对象,该矩阵只会用到eye和center的相对位置。
///该视图矩阵表示,摄像机在eye位置看向center位置,且向上的向量(这一点稍后解释)为up时的视图矩阵。
///视图矩阵又可以看做摄像机的模型矩阵,所以该函数产生的矩阵又可以表示以下变换:将物体从原点平移至位置center-eye,
///再将其旋转至向上的向量为up。向上的向量up用来固定相机,可以想象当相机固定在一点,镜头朝向固定方向的时候,
///还是可以在一个维度里自由旋转的,up向量固定相机的这个维度。
///这里的解释摘抄自:/yiyezhai/archive//2791319.html
///表示相机位置的Vector3三维向量
///表示目标的Vector3三维向量
///表示向上的Vector3三维向量
///返回新的Matrix4(4x4矩阵)
lookAt: function () {
var x = new THREE.Vector3();
var y = new THREE.Vector3();
var z = new THREE.Vector3();
return function ( eye, target, up ) {
var te = this.
z.subVectors( eye, target ).normalize();
if ( z.length() === 0 ) {
x.crossVectors( up, z ).normalize();
if ( x.length() === 0 ) {
z.x += 0.0001;
x.crossVectors( up, z ).normalize();
y.crossVectors( z, x );
te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
//返回新的Matrix4(4x4矩阵)
///multiply方法用来将当前Matrix4(4x4矩阵)与参数m相乘.并返回新的Matrix4(4x4矩阵)
/// NOTE:这里只接受一个参数,如果传递两个参数请使用.multiplyMatrices( a, b )方法替代,如果有两个参数会自动调用.multiplyMatrices( a, b )方法
///multiply
///与当前对象元素值相乘的Matrix4(4x4矩阵)
///判断是否有第二个参数w,如果有的话,调用.multiplyMatrices()方法
///返回新的Matrix4(4x4矩阵)
multiply: function ( m, n ) {
if ( n !== undefined ) { //判断是否有第二个参数w,如果有的话,调用.multiplyMatrices()方法
// NOTE:这里只接受一个参数,如果传递两个参数请使用.multiplyMatrices( a, b )方法替代,
console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
return this.multiplyMatrices( m, n ); //调用.multiplyMatrices()方法,返回新的Matrix4(4x4矩阵),矩阵m和矩阵n相乘
return this.multiplyMatrices( this, m ); //调用.multiplyMatrices()方法,返回新的Matrix4(4x4矩阵),当前矩阵和矩阵m相乘
///multiply方法用来将矩阵a,b相乘,并返回新的Matrix4(4x4矩阵).
///multiplyMatrices
///Matrix4(4x4矩阵)
///Matrix4(4x4矩阵)
///返回新的Matrix4(4x4矩阵)
multiplyMatrices: function ( a, b ) {
var ae = a.
var be = b.
var te = this.
//将矩阵a,b相乘.
var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
//返回新的Matrix4(4x4矩阵)
///multiply方法用来将矩阵a,b相乘,并返回新Matrix4(4x4矩阵)赋值给数组对象r
///multiplyMatrices
///Matrix4(4x4矩阵)
///Matrix4(4x4矩阵)
///数组对象
///返回新Matrix4(4x4矩阵)
multiplyToArray: function ( a, b, r ) {
var te = this.
this.multiplyMatrices( a, b ); //矩阵a,b相乘
//新Matrix4(4x4矩阵)赋值给数组对象
r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
= te[ 8 ]; r[ 9 ]
= te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
//返回新Matrix4(4x4矩阵)
///multiplyScalar方法用来将Matrix4(4x4矩阵)的元素直接与参数s相乘.并返回新的Matrix4(4x4矩阵).
/// NOTE:这里传递的参数s是一个标量.
///multiplyScalar
///与当前Matrix4(4x4矩阵)对象的值相乘的标量,数值
///返回新的Matrix4(4x4矩阵)
multiplyScalar: function ( s ) {
var te = this.
te[ 0 ] *= te[ 4 ] *= te[ 8 ] *= te[ 12 ] *=
te[ 1 ] *= te[ 5 ] *= te[ 9 ] *= te[ 13 ] *=
te[ 2 ] *= te[ 6 ] *= te[ 10 ] *= te[ 14 ] *=
te[ 3 ] *= te[ 7 ] *= te[ 11 ] *= te[ 15 ] *=
//返回新的Matrix4(4x4矩阵)
///multiplyVector3方法用来将3x3矩阵和一个Vector3(三维向量)相乘.并返回新Matrix4(4x4矩阵)对象.
/// NOTE:multiplyVector3方法已经被删除使用vector.applyMatrix4( matrix )方法替换,这里保留是为了向下兼容.
/// NOTE:multiplyVector3方法经常用来应用某种变换.
///multiplyVector3
///三维向量
///并返回新的Matrix4(4x4矩阵)对象
multiplyVector3: function ( vector ) {
// 提示用户multiplyVector3方法已经被删除使用vector.applyMatrix4( matrix )方法替换,这里保留是为了向下兼容.
console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
return vector.applyProjection( this ); //并返回新的Matrix4(4x4矩阵)对象
///multiplyVector4方法用来将3x3矩阵和一个Vector4(四维向量)相乘.并返回新Matrix4(4x4矩阵)对象.
/// NOTE:multiplyVector4方法已经被删除使用vector.applyMatrix4( matrix )方法替换,这里保留是为了向下兼容.
/// NOTE:multiplyVector4方法经常用来应用某种变换.
///multiplyVector4
///四维向量
///并返回新的Matrix4(4x4矩阵)对象
multiplyVector4: function ( vector ) {
// 提示用户multiplyVector4方法已经被删除使用vector.applyMatrix4( matrix )方法替换,这里保留是为了向下兼容.
console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
return vector.applyMatrix4( this ); //并返回新的Matrix4(4x4矩阵)对象
///multiplyVector3Array方法用来将数组a和一个Vector3(三维向量)相乘.并返回新的数组对象.
/// NOTE:multiplyVector3Array方法已经被删除使用matrix.applyToVector3Array( array )方法替换,这里保留是为了向下兼容.
/// NOTE:multiplyVector3Array方法经常用来应用某种变换.
///multiplyVector3Array
///数组对象
///并返回新的数组对象
multiplyVector3Array: function ( a ) {
// 提示用户multiplyVector3Array方法已经被删除使用matrix.applyToVector3Array( array )方法替换,这里保留是为了向下兼容.
console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
return this.applyToVector3Array( a ); //并返回新的Matrix4(4x4矩阵)对象
///applyToVector3Array方法用来将当前矩阵应用到一个三维向量,并将结果转换成一个数组,返回数组对象.
/// NOTE:applyToVector3Array方法经常用来对三维向量应用某种变换. 参数offset,length用来对不同长度的数组应用变换.
///applyMatrix4
///数组对象
///并返回新的数组对象
applyToVector3Array: function () {
var v1 = new THREE.Vector3();
return function ( array, offset, length ) {
if ( offset === undefined ) offset = 0;
if ( length === undefined ) length = array.
for ( var i = 0, j = offset, i & i += 3, j += 3 ) {
v1.x = array[ j ];
v1.y = array[ j + 1 ];
v1.z = array[ j + 2 ];
v1.applyMatrix4( this );
array[ j ]
array[ j + 1 ] = v1.y;
array[ j + 2 ] = v1.z;
//并返回新的数组对象
///rotateAxis方法对参数v三维向量的应用一个旋转变换
/// NOTE:rotateAxis方法已经被删除使用Vector3.transformDirection( matrix )方法替换,这里保留是为了向下兼容.
///rotateAxis
///仿射矩阵
///返回新坐标值的三维向量
rotateAxis: function ( v ) {
//提示用户rotateAxis方法已经被删除使用Vector3.transformDirection( matrix )方法替换,这里保留是为了向下兼容.
console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
v.transformDirection( this ); //调用Vector3.transformDirection( matrix ) 方法,对向量应用旋转变换
/*crossVector方法
///crossVector方法将返回两个交叉乘积,调用者变为a,b的叉乘。叉乘是一个向量,垂直于参与叉乘的两个向量并呈右手螺旋法则。
/// 返回为同时垂直于两个参数向量的向量,方向可朝上也可朝下,由两向量夹角的方向决定。
/// NOTE:crossVector方法已经被删除使用vector.applyMatrix4( matrix )方法替换,这里保留是为了向下兼容.
/// NOTE:借助右手定则辅助判断方向。参考:http://zh.wikipedia.org/zh/%E5%90%91%E9%87%8F%E7%A7%AF
/// 叉乘是一种在向量空间中向量的二元运算。与点乘不同,它的运算结果是一个伪向量而不是一个标量。
/// 叉乘的运算结果叫叉积(即交叉乘积)、外积或向量积。叉积与原来的两个向量都垂直。
1、理论知识
数学上的定义:c=axb【注:粗体小写字母表示向量】其中a,b,c均为向量。即两个向量的叉积得到的还是向量!
性质1:c&a,c&b,即向量c垂直与向量a,b所在的平面。
性质2:模长|c|=|a||b|sin
性质3:满足右手法则。从这点我们有axb & bxa,而axb = - bxa。所以我们可以使用叉积的正负值来判断向量a,b的相对位置,
即向量b是处于向量a的顺时针方向还是逆时针方向。
///crossVector
///三维向量
///三维向量
crossVector: function ( vector ) {
//提示用户crossVector方法已经被删除使用vector.applyMatrix4( matrix )方法替换,这里保留是为了向下兼容.
console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
return vector.applyMatrix4( this ); //调用Vector3.applyMatrix4( matrix ) 方法,返回参数vector和当前矩阵的差乘.
///determinant方法用来获得Matrix4(4x4矩阵)的行列式
/// NOTE:通过求解行列式值的方式来判断矩阵的逆矩阵是否存在(行列式的值不等于0,表示该矩阵有逆矩阵).
///determinant
///返回Matrix4(4x4矩阵)的四阶行列式
determinant: function () {
var te = this.
var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
//TODO: make this more efficient
//( based on /maths/algebra/matrix/functions/inverse/fourD/index.htm )
+ n14 * n23 * n32
- n13 * n24 * n32
- n14 * n22 * n33
+ n12 * n24 * n33
+ n13 * n22 * n34
- n12 * n23 * n34
+ n11 * n23 * n34
- n11 * n24 * n33
+ n14 * n21 * n33
- n13 * n21 * n34
+ n13 * n24 * n31
- n14 * n23 * n31
+ n11 * n24 * n32
- n11 * n22 * n34
- n14 * n21 * n32
+ n12 * n21 * n34
+ n14 * n22 * n31
- n12 * n24 * n31
- n13 * n22 * n31
- n11 * n23 * n32
+ n11 * n22 * n33
+ n13 * n21 * n32
- n12 * n21 * n33
+ n12 * n23 * n31
) //返回Matrix4(4x4矩阵)的四阶行列式
///transpose方法用来获得Matrix4(4x4矩阵)的转置矩阵.
/// NOTE:一个mxn的矩阵的转置矩阵式nxm矩阵,就是矩阵的行和列交换.
/// matrix A = | 4 5 6 |
///transpose
///返回Matrix4(4x4矩阵)的转置矩阵.
transpose: function () {
var te = this.
tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] =
tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] =
tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] =
tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] =
tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] =
tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] =
//返回Matrix4(4x4矩阵)的转置矩阵.
///flattenToArrayOffset方法通过参数offset指定偏移量,将矩阵展开到数组(参数array)中,返回新的数组.
/// NOTE:flattenToArrayOffset方法可以用在将3x3矩阵变换成4x4矩阵中.
/// matrix A = | 4 5 6 |
=& flattenToArrayOffset(arrary,3) =& array(0,0,0,0,1,2,3,0,0,0,0,4,5,6,0,0,0,0,7,8,9)
///flattenToArrayOffset
///Array数组对象
///返回包含矩阵元素的数组
flattenToArrayOffset: function ( array, offset ) {
var te = this.
array[ offset
] = te[ 0 ];
array[ offset + 1 ] = te[ 1 ];
array[ offset + 2 ] = te[ 2 ];
array[ offset + 3 ] = te[ 3 ];
array[ offset + 4 ] = te[ 4 ];
array[ offset + 5 ] = te[ 5 ];
array[ offset + 6 ] = te[ 6 ];
array[ offset + 7 ] = te[ 7 ];
array[ offset + 8 ]
= te[ 8 ];
array[ offset + 9 ]
= te[ 9 ];
array[ offset + 10 ] = te[ 10 ];
array[ offset + 11 ] = te[ 11 ];
array[ offset + 12 ] = te[ 12 ];
array[ offset + 13 ] = te[ 13 ];
array[ offset + 14 ] = te[ 14 ];
array[ offset + 15 ] = te[ 15 ];
//返回包含矩阵元素的数组
///getPosition方法将当前矩阵中代表位置的元素值设置给三维向量
/// NOTE:getPosition方法已经被删除使用vector.setFromMatrixPosition( matrix )方法替换,这里保留是为了向下兼容.
///getPosition
///返回三维向量
getPosition: function () {
var v1 = new THREE.Vector3();
return function () {
console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
var te = this.
return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] ); //返回三维向量
///setPosition方法将当前矩阵中代表位置的元素值设置给三维向量
///setPosition
///返回新的Matrix4(4x4矩阵)
setPosition: function ( v ) {
var te = this.
te[ 12 ] = v.x;
te[ 13 ] = v.y;
te[ 14 ] = v.z;
//返回新的Matrix4(4x4矩阵)
///getInverse方法用来获得Matrix4(4x4矩阵)的逆矩阵.
/// NOTE:逆矩阵与当前矩阵相乘得到单位矩阵.
///multiplyScalar
///THREE.Matrix4
///异常标志
///返回Matrix4(4x4矩阵)的逆矩阵.
getInverse: function ( m, throwOnInvertible ) {
// based on /maths/algebra/matrix/functions/inverse/fourD/index.htm
var te = this.
var me = m.
var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ]; //获得参数matrix行列式的值
if ( det == 0 ) {
// 没有逆矩阵
var msg = Matrix4.getInverse(): can't invert matrix, determinant is 0; //提示用户该矩阵没有逆矩阵
if ( throwOnInvertible || false ) {
throw new Error( msg );
console.warn( msg );
this.identity(); //获得一个单位矩阵
//返回单位矩阵
this.multiplyScalar( 1 / det ); //除以行列式得到逆矩阵
//返回Matrix4(4x4矩阵)的逆矩阵.
///translate方法用来变换Matrix4(4x4矩阵).
/// NOTE:translate方法已经删除.
///translate
///THREE.Vecter3
///返回带有新位置信息的Matrix4(4x4矩阵).
translate: function ( v ) {
//提示用户translate()方法已经删除.
console.warn( 'THREE.Matrix4: .translate() has been removed.' );
///rotateX方法用来变换Matrix4(4x4矩阵)的x轴.
/// NOTE:rotateX方法已经删除.
///rotateX
///返回带有新的Matrix4(4x4矩阵).
rotateX: function ( angle ) {
//提示用户rotateX()方法已经删除.
console.warn( 'THREE.Matrix4: .rotateX() has been removed.' );
///rotateY方法用来变换Matrix4(4x4矩阵)的Y轴.
/// NOTE:rotateX方法已经删除.
///rotateY
///返回带有新的Matrix4(4x4矩阵).
rotateY: function ( angle ) {
//提示用户rotateY()方法已经删除.
console.warn( 'THREE.Matrix4: .rotateY() has been removed.' );
///rotateZ方法用来变换Matrix4(4x4矩阵)的Z轴.
/// NOTE:rotateZ方法已经删除.
///rotateZ
///返回带有新的Matrix4(4x4矩阵).
rotateZ: function ( angle ) {
//提示用户rotateZ()方法已经删除.
console.warn( 'THREE.Matrix4: .rotateZ() has been removed.' );
///rotateByAxis方法用来变换Matrix4(4x4矩阵)的任意轴.
/// NOTE:rotateByAxis方法已经删除.
///rotateByAxis
///返回带有新的Matrix4(4x4矩阵).
rotateByAxis: function ( axis, angle ) {
//提示用户rotateByAxis()方法已经删除.
console.warn( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
///scale方法通过预先计算比例向量,将指定的比例向量应用到此 Matrix4(4x4矩阵)。
///比例向量Vector3
///返回新的Matrix4(4x4矩阵).
scale: function ( v ) {
var te = this.
var x = v.x, y = v.y, z = v.z;
te[ 0 ] *= te[ 4 ] *= te[ 8 ] *=
te[ 1 ] *= te[ 5 ] *= te[ 9 ] *=
te[ 2 ] *= te[ 6 ] *= te[ 10 ] *=
te[ 3 ] *= te[ 7 ] *= te[ 11 ] *=
//返回新的Matrix4(4x4矩阵).
getMaxScaleOnAxis: function () {
var te = this.
var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
///makeTranslation方法根据x, y, z生成平移矩阵.
///makeTranslation
///返回Matrix4(4x4矩阵),平移矩阵.
makeTranslation: function ( x, y, z ) {
1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1
//返回Matrix4(4x4矩阵),平移矩阵
///makeRotationX方法生成绕x轴转theta弧度的旋转矩阵
/// TODO:这里是弧度还是角度,有待确认.
///makeRotationX
///返回Matrix4(4x4矩阵),旋转矩阵.
makeRotationX: function ( theta ) {
var c = Math.cos( theta ), s = Math.sin( theta );
0, c, - s, 0,
//返回Matrix4(4x4矩阵),旋转矩阵.
///makeRotationY方法生成绕y轴转theta弧度的旋转矩阵
/// TODO:这里是弧度还是角度,有待确认.
///makeRotationY
///返回Matrix4(4x4矩阵),旋转矩阵.
makeRotationY: function ( theta ) {
var c = Math.cos( theta ), s = Math.sin( theta );
c, 0, s, 0,
0, 1, 0, 0,
- s, 0, c, 0,
0, 0, 0, 1
//返回Matrix4(4x4矩阵),旋转矩阵.
///makeRotationZ方法生成绕z轴转theta弧度的旋转矩阵
/// TODO:这里是弧度还是角度,有待确认.
///makeRotationZ
///返回Matrix4(4x4矩阵),旋转矩阵.
makeRotationZ: function ( theta ) {
var c = Math.cos( theta ), s = Math.sin( theta );
c, - s, 0, 0,
//返回Matrix4(4x4矩阵),旋转矩阵.
///makeRotationAxis方法生成绕任意轴转angle弧度的旋转矩阵
/// TODO:这里是弧度还是角度,有待确认.
///makeRotationAxis
/// 转轴向量(axis必须是单位向量)
///返回Matrix4(4x4矩阵),旋转矩阵.
makeRotationAxis: function ( axis, angle ) {
// Based on http://www.gamedev.net/reference/articles/article1199.
var c = Math.cos( angle );
var s = Math.sin( angle );
var t = 1 -
var x = axis.x, y = axis.y, z = axis.z;
var tx = t * x, ty = t *
tx * x + c, tx * y - s * z, tx * z + s * y, 0,
tx * y + s * z, ty * y + c, ty * z - s * x, 0,
tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
0, 0, 0, 1
//返回Matrix4(4x4矩阵),旋转矩阵.
///makeScale方法根据x, y, z生成缩放矩阵.
///makeScale
///返回Matrix4(4x4矩阵),缩放矩阵.
makeScale: function ( x, y, z ) {
x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1
//返回Matrix4(4x4矩阵),缩放矩阵.
///compose方法设置变换矩阵的平移、旋转和缩放设置
///compose
///平移向量
///旋转向量
///缩放向量
///返回Matrix4(4x4矩阵),变换矩阵.
compose: function ( position, quaternion, scale ) {
this.makeRotationFromQuaternion( quaternion );
this.scale( scale );
this.setPosition( position );
//返回Matrix4(4x4矩阵),变换矩阵.
///decompose方法将转换矩阵的平移、旋转和缩放设置作为由三个 Vector3 对象组成的矢量返回。第一个 Vector3 对象容纳平移元素。第二个 Vector3 对象容纳旋转元素。第三个 Vector3 对象容纳缩放元素。
///decompose
///平移向量
///旋转向量
///缩放向量
///返回Matrix4(4x4矩阵),变换矩阵.
decompose: function () {
var vector = new THREE.Vector3();
var matrix = new THREE.Matrix4();
return function ( position, quaternion, scale ) {
var te = this.
var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
// if determine is negative, we need to invert one scale
// 如果行列式是负数,把比例转换成正数
var det = this.determinant();
if ( det & 0 ) {
position.x = te[ 12 ];
position.y = te[ 13 ];
position.z = te[ 14 ];
// scale the rotation part
// 缩放有关旋转的元素
matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
//这个表示点的矩阵是不完整的,我们不能使用copy()方法
var invSX = 1 /
var invSY = 1 /
var invSZ = 1 /
matrix.elements[ 0 ] *= invSX;
matrix.elements[ 1 ] *= invSX;
matrix.elements[ 2 ] *= invSX;
matrix.elements[ 4 ] *= invSY;
matrix.elements[ 5 ] *= invSY;
matrix.elements[ 6 ] *= invSY;
matrix.elements[ 8 ] *= invSZ;
matrix.elements[ 9 ] *= invSZ;
matrix.elements[ 10 ] *= invSZ;
quaternion.setFromRotationMatrix( matrix );
//返回Matrix4(4x4矩阵),变换矩阵
///makeFrustum方法根据left, right, bottom, top, near, far生成透视投影矩阵,Frustum平截头体
///makeFrustum
///指明相对于垂直平面的左侧坐标位置
///指明相对于垂直平面的右侧坐标位置
///指明相对于垂直平面的底部坐标位置
///指明相对于垂直平面的顶部坐标位置
///指明相对于深度剪切面的近的距离,必须为正数
///指明相对于深度剪切面的远的距离,必须为正数
///返回Matrix4(4x4矩阵),透视投影矩阵.
makeFrustum: function ( left, right, bottom, top, near, far ) {
var te = this.
var x = 2 * near / ( right - left );
var y = 2 * near / ( top - bottom );
var a = ( right + left ) / ( right - left );
var b = ( top + bottom ) / ( top - bottom );
var c = - ( far + near ) / ( far - near );
var d = - 2 * far * near / ( far - near );
te[ 0 ] = te[ 4 ] = 0; te[ 8 ] = te[ 12 ] = 0;
te[ 1 ] = 0; te[ 5 ] = te[ 9 ] = te[ 13 ] = 0;
te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = te[ 14 ] =
te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
//返回Matrix4(4x4矩阵),透视投影矩阵
///makePerspective方法根据 fov, aspect, near, far 生成透视投影矩阵,对makeFrustu()方法的封装,适配人们习惯的表达方式.
///makePerspective
///指明相机的可视角度
///指明相机可视范围的长宽比
///指明相对于深度剪切面的近的距离,必须为正数
///指明相对于深度剪切面的远的距离,必须为正数
///返回Matrix4(4x4矩阵),透视投影矩阵.
makePerspective: function ( fov, aspect, near, far ) {
var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
var ymin = -
var xmin = ymin *
var xmax = ymax *
return this.makeFrustum( xmin, xmax, ymin, ymax, near, far ); //调用makeFrustum()方法,返回透视投影矩阵.
///makeOrthographic方法根据
left, right, top, bottom, near, far 生成正交矩阵.
///makePerspective
///指明相对于垂直平面的左侧坐标位置
///指明相对于垂直平面的右侧坐标位置
///指明相对于垂直平面的底部坐标位置
///指明相对于垂直平面的顶部坐标位置
///指明相对于深度剪切面的近的距离,必须为正数
///指明相对于深度剪切面的远的距离,必须为正数
///返回Matrix4(4x4矩阵),正交投影矩阵.
makeOrthographic: function ( left, right, top, bottom, near, far ) {
var te = this.
var w = right -
var h = top -
var p = far -
var x = ( right + left ) /
var y = ( top + bottom ) /
var z = ( far + near ) /
te[ 0 ] = 2 / te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = -
te[ 1 ] = 0; te[ 5 ] = 2 / te[ 9 ] = 0; te[ 13 ] = -
te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / te[ 14 ] = -
te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
//返回Matrix4(4x4矩阵),正交投影矩阵.
/*fromArray方法
///fromArray方法将存储Matrix4(4x4矩阵)元素值的数组赋值给当前Matrix4(4x4矩阵)对象
///fromArray
///Matrix4(4x4矩阵)元素值的数组array
///返回新的Matrix4(4x4矩阵)
fromArray: function ( array ) {
this.elements.set( array );
//调用set方法,将数组赋值给当前Matrix4(4x4矩阵)对象
//返回新的Matrix4(4x4矩阵)
/*toArray方法
///toArray方法将当前Matrix4(4x4矩阵)的元素值赋值给数组array.返回一个数组对象.
///toArray
///返回含有Matrix4(4x4矩阵)元素值的数组array
toArray: function () {
var te = this.
te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
//返回含有Matrix4(4x4矩阵)元素值的数组array
/*clone方法
///clone方法克隆一个Matrix4(4x4矩阵)对象.
///返回克隆的Matrix4(4x4矩阵)对象
clone: function () {
var te = this.
return new THREE.Matrix4(
te[ 0 ], te[ 4 ], te[ 8 ], te[ 12 ],
te[ 1 ], te[ 5 ], te[ 9 ], te[ 13 ],
te[ 2 ], te[ 6 ], te[ 10 ], te[ 14 ],
te[ 3 ], te[ 7 ], te[ 11 ], te[ 15 ]
//返回克隆的Matrix4(4x4矩阵)对象
商域无疆 (http://blog.csdn.net/omni360/)
本文遵循&署名-非商业用途-保持一致&创作公用协议
转载请保留此句:商域无疆 - 本博客专注于 敏捷开发及移动和物联设备研究:数据可视化、GOLANG、Html5、WEBGL、THREE.JS,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
以下代码是THREE.JS 源码文件中Math/Matrix4.js文件的注释.
更多更新在 : /omni360/three.js.sourcecode/blob/master/Three.js}

我要回帖

更多关于 js连连看源码 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信