4x4矩阵,可作为列主顺序数组进行索引。对于代码可读性,构造函数参数按行主顺序排列。
new Matrix4(column0Row0, column1Row0, column2Row0, column3Row0, column0Row1, column1Row1, column2Row1, column3Row1, column0Row2, column1Row2, column2Row2, column3Row2, column0Row3, column1Row3, column2Row3, column3Row3)
Parameters:
column0Row0
(Number)
(default 0.0)
第0列第0行的值。
column1Row0
(Number)
(default 0.0)
第1列第0行的值。
column2Row0
(Number)
(default 0.0)
第2列第0行的值。
column3Row0
(Number)
(default 0.0)
第3列第0行的值。
column0Row1
(Number)
(default 0.0)
第0列第1行的值。
column1Row1
(Number)
(default 0.0)
第1列第1行的值。
column2Row1
(Number)
(default 0.0)
第2列第1行的值。
column3Row1
(Number)
(default 0.0)
第3列第1行的值。
column0Row2
(Number)
(default 0.0)
第0列第2行的值。
column1Row2
(Number)
(default 0.0)
第1列第2行的值。
column2Row2
(Number)
(default 0.0)
第2列第2行的值。
column3Row2
(Number)
(default 0.0)
第3列第2行的值。
column0Row3
(Number)
(default 0.0)
第0列第3行的值。
column1Row3
(Number)
(default 0.0)
第1列第3行的值。
column2Row3
(Number)
(default 0.0)
第2列第3行的值。
column3Row3
(Number)
(default 0.0)
第3列第3行的值。
- Matrix4.fromColumnMajorArray
- Matrix4.fromRowMajorArray
- Matrix4.fromRotationTranslation
- Matrix4.fromTranslationRotationScale
- Matrix4.fromTranslationQuaternionRotationScale
- Matrix4.fromTranslation
- Matrix4.fromScale
- Matrix4.fromUniformScale
- Matrix4.fromCamera
- Matrix4.computePerspectiveFieldOfView
- Matrix4.computeOrthographicOffCenter
- Matrix4.computePerspectiveOffCenter
- Matrix4.computeInfinitePerspectiveOffCenter
- Matrix4.computeViewportTransformation
- Matrix4.computeView
- Matrix2
- Matrix3
- Packable
See:
Members
length : Number
获取集合中的项数。
(static, constant) COLUMN0ROW0 : Number
Matrix4中第0列第0行的索引。
(static, constant) COLUMN0ROW1 : Number
第0列第1行的matrix4索引。
(static, constant) COLUMN0ROW2 : Number
Matrix4中第0列第2行的索引。
(static, constant) COLUMN0ROW3 : Number
Matrix4中第0列第3行的索引。
(static, constant) COLUMN1ROW0 : Number
Matrix4中第1列第0行的索引。
(static, constant) COLUMN1ROW1 : Number
Matrix4中第1列第1行的索引。
(static, constant) COLUMN1ROW2 : Number
Matrix4中第1列第2行的索引。
(static, constant) COLUMN1ROW3 : Number
Matrix4中第1列第3行的索引。
(static, constant) COLUMN2ROW0 : Number
Matrix4中第2列第0行的索引。
(static, constant) COLUMN2ROW1 : Number
Matrix4中第2列第1行的索引。
(static, constant) COLUMN2ROW2 : Number
Matrix4中第2列第2行的索引。
(static, constant) COLUMN2ROW3 : Number
Matrix4中第2列第3行的索引。
(static, constant) COLUMN3ROW0 : Number
Matrix4中第3列第0行的索引。
(static, constant) COLUMN3ROW1 : Number
Matrix4中第3列第1行的索引。
(static, constant) COLUMN3ROW2 : Number
Matrix4中第3列第2行的索引。
(static, constant) COLUMN3ROW3 : Number
Matrix4中第3列第3行的索引。
(static, constant) IDENTITY : Matrix4
初始化为标识矩阵的不可变矩阵4实例。
(static) packedLength : Number
用于将对象打包到数组中的元素数。
(static, constant) ZERO : Matrix4
初始化为零矩阵的不可变矩阵4实例。
Methods
clone(result) → {Matrix4}
复制提供的matrix4实例。
Parameters:
将此矩阵与提供的矩阵组件进行比较,如果相等,则返回
true,否则返回false。
Parameters:
将此矩阵与提供的矩阵组件进行比较,如果它们在提供的epsilon中,则返回
true,否则返回false。
Parameters:
epsilon
(Number)
用于相等性测试的epsilon。
计算表示此矩阵的字符串,每一行都位于单独的行上,格式为“(第0列、第1列、第2列、第3列)”。
计算包含所提供矩阵元素的绝对(无符号)值的矩阵。
Parameters:
计算两个矩阵的和。
Parameters:
复制Matrix4实例。
Parameters:
计算表示无限偏心透视转换的Matrix4实例。
Parameters:
left
(Number)
摄像机左侧将在视图中的米数。
right
(Number)
摄像机右侧将在视图中的米数。
bottom
(Number)
将在视图中的相机下方的米数。
top
(Number)
摄像机上方将在视图中的米数。
near
(Number)
到近平面的距离,单位为米。
计算表示正交变换矩阵的Matrix4实例。
Parameters:
left
(Number)
摄像机左侧将在视图中的米数。
right
(Number)
摄像机右侧将在视图中的米数。
bottom
(Number)
将在视图中的相机下方的米数。
top
(Number)
摄像机上方将在视图中的米数。
near
(Number)
到近平面的距离,单位为米。
far
(Number)
到远平面的距离,单位为米。
计算表示透视转换矩阵的Matrix4实例。
Parameters:
fovY
(Number)
沿Y轴以弧度表示的视场。
aspectRatio
(Number)
纵横比。
near
(Number)
到近平面的距离,单位为米。
far
(Number)
到远平面的距离,单位为米。
Throws
-
DeveloperError : Fovy必须在(0,pi)中。
-
DeveloperError : aspectratio必须大于零。
-
DeveloperError : near必须大于零。
-
DeveloperError : far必须大于零。
计算表示偏心透视转换的Matrix4实例。
Parameters:
left
(Number)
摄像机左侧将在视图中的米数。
right
(Number)
摄像机右侧将在视图中的米数。
bottom
(Number)
将在视图中的相机下方的米数。
top
(Number)
摄像机上方将在视图中的米数。
near
(Number)
到近平面的距离,单位为米。
far
(Number)
到远平面的距离,单位为米。
计算从世界空间转换为视图空间的Matrix4实例。
Parameters:
计算从标准化设备坐标转换为窗口坐标的Matrix4实例。
Parameters:
viewport
(Object)
(default { x : 0.0, y : 0.0, width : 0.0, height : 0.0 })
如示例1所示的视区角。
nearDepthRange
(Number)
(default 0.0)
窗口坐标中的近平面距离。
farDepthRange
(Number)
(default 1.0)
窗口坐标中的远平面距离。
Example
// Create viewport transformation using an explicit viewport and depth range.
var m = bmgl.Matrix4.computeViewportTransformation({
x : 0.0,
y : 0.0,
width : 1024.0,
height : 768.0
}, 0.0, 1.0, new bmgl.Matrix4());
比较提供的矩阵组件,如果它们相等,则返回
true,否则返回false。
Parameters:
Example
//compares two Matrix4 instances
// a = [10.0, 14.0, 18.0, 22.0]
// [11.0, 15.0, 19.0, 23.0]
// [12.0, 16.0, 20.0, 24.0]
// [13.0, 17.0, 21.0, 25.0]
// b = [10.0, 14.0, 18.0, 22.0]
// [11.0, 15.0, 19.0, 23.0]
// [12.0, 16.0, 20.0, 24.0]
// [13.0, 17.0, 21.0, 25.0]
if(bmgl.Matrix4.equals(a,b)) {
console.log("Both matrices are equal");
} else {
console.log("They are not equal");
}
//Prints "Both matrices are equal" on the console
比较提供的矩阵组件,如果它们在提供的epsilon中,则返回
true,否则返回false。
Parameters:
Example
//compares two Matrix4 instances
// a = [10.5, 14.5, 18.5, 22.5]
// [11.5, 15.5, 19.5, 23.5]
// [12.5, 16.5, 20.5, 24.5]
// [13.5, 17.5, 21.5, 25.5]
// b = [10.0, 14.0, 18.0, 22.0]
// [11.0, 15.0, 19.0, 23.0]
// [12.0, 16.0, 20.0, 24.0]
// [13.0, 17.0, 21.0, 25.0]
if(bmgl.Matrix4.equalsEpsilon(a,b,0.1)){
console.log("Difference between both the matrices is less than 0.1");
} else {
console.log("Difference between both the matrices is not less than 0.1");
}
//Prints "Difference between both the matrices is not less than 0.1" on the console
从数组中的16个连续元素创建matrix4。
Parameters:
array
(Array.<Number>)
16个连续元素对应矩阵位置的数组。假定列主顺序。
startingIndex
(Number)
(default 0)
第一个元素数组中的偏移量,它对应于矩阵中第一列第一行的位置。
Example
// Create the Matrix4:
// [1.0, 2.0, 3.0, 4.0]
// [1.0, 2.0, 3.0, 4.0]
// [1.0, 2.0, 3.0, 4.0]
// [1.0, 2.0, 3.0, 4.0]
var v = [1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0];
var m = bmgl.Matrix4.fromArray(v);
// Create same Matrix4 with using an offset into an array
var v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0];
var m2 = bmgl.Matrix4.fromArray(v2, 2);
从相机计算Matrix4实例。
Parameters:
从列主顺序数组计算matrix4实例。
Parameters:
values
(Array.<Number>)
列主顺序数组。
从表示旋转的Matrix3和表示转换的Cartesian3计算Matrix4实例。
Parameters:
从行主顺序数组计算matrix4实例。生成的矩阵将按主列顺序排列。
Parameters:
values
(Array.<Number>)
行主顺序数组。
计算表示非均匀比例的Matrix4实例。
Parameters:
Example
// Creates
// [7.0, 0.0, 0.0, 0.0]
// [0.0, 8.0, 0.0, 0.0]
// [0.0, 0.0, 9.0, 0.0]
// [0.0, 0.0, 0.0, 1.0]
var m = bmgl.Matrix4.fromScale(new bmgl.Cartesian3(7.0, 8.0, 9.0));
从表示转换的cartesian3创建matrix4实例。
Parameters:
使用四元数表示的旋转,从平移、旋转和缩放(TRS)表示计算Matrix4实例。
Parameters:
Example
var result = bmgl.Matrix4.fromTranslationQuaternionRotationScale(
new bmgl.Cartesian3(1.0, 2.0, 3.0), // translation
bmgl.Quaternion.IDENTITY, // rotation
new bmgl.Cartesian3(7.0, 8.0, 9.0), // scale
result);
从
TranslationRotationScale实例创建matrix4实例。
Parameters:
计算表示统一比例的Matrix4实例。
Parameters:
scale
(Number)
均匀比例因子。
Example
// Creates
// [2.0, 0.0, 0.0, 0.0]
// [0.0, 2.0, 0.0, 0.0]
// [0.0, 0.0, 2.0, 0.0]
// [0.0, 0.0, 0.0, 1.0]
var m = bmgl.Matrix4.fromUniformScale(2.0);
以cartesian4实例的形式检索所提供索引处的矩阵列的副本。
Parameters:
Examples
//returns a Cartesian4 instance with values from the specified column
// m = [10.0, 11.0, 12.0, 13.0]
// [14.0, 15.0, 16.0, 17.0]
// [18.0, 19.0, 20.0, 21.0]
// [22.0, 23.0, 24.0, 25.0]
//Example 1: Creates an instance of Cartesian
var a = bmgl.Matrix4.getColumn(m, 2, new bmgl.Cartesian4());
//Example 2: Sets values for Cartesian instance
var a = new bmgl.Cartesian4();
bmgl.Matrix4.getColumn(m, 2, a);
// a.x = 12.0; a.y = 16.0; a.z = 20.0; a.w = 24.0;
Throws
-
DeveloperError : 索引必须是0、1、2或3。
在提供的行和列处计算元素的数组索引。
Parameters:
row
(Number)
行的从零开始的索引。
column
(Number)
列的从零开始的索引。
Example
var myMatrix = new bmgl.Matrix4();
var column1Row0Index = bmgl.Matrix4.getElementIndex(1, 0);
var column1Row0 = myMatrix[column1Row0Index];
myMatrix[column1Row0Index] = 10.0;
Throws
-
DeveloperError : 行必须是0、1、2或3。
-
DeveloperError : 列必须是0、1、2或3。
获取所提供矩阵的左上3x3旋转矩阵,假定该矩阵是仿射变换矩阵。
Parameters:
Example
// returns a Matrix3 instance from a Matrix4 instance
// m = [10.0, 14.0, 18.0, 22.0]
// [11.0, 15.0, 19.0, 23.0]
// [12.0, 16.0, 20.0, 24.0]
// [13.0, 17.0, 21.0, 25.0]
var b = new bmgl.Matrix3();
bmgl.Matrix4.getMatrix3(m,b);
// b = [10.0, 14.0, 18.0]
// [11.0, 15.0, 19.0]
// [12.0, 16.0, 20.0]
假设矩阵是仿射变换,则计算最大比例。最大比例是左上3x3矩阵中列向量的最大长度。
Parameters:
获取所提供矩阵的左上3x3旋转矩阵,假定该矩阵是仿射变换矩阵。
Parameters:
Deprecated: moved to Matrix4.getMatrix3
以cartesian4实例的形式检索所提供索引处的矩阵行的副本。
Parameters:
Examples
//returns a Cartesian4 instance with values from the specified column
// m = [10.0, 11.0, 12.0, 13.0]
// [14.0, 15.0, 16.0, 17.0]
// [18.0, 19.0, 20.0, 21.0]
// [22.0, 23.0, 24.0, 25.0]
//Example 1: Returns an instance of Cartesian
var a = bmgl.Matrix4.getRow(m, 2, new bmgl.Cartesian4());
//Example 2: Sets values for a Cartesian instance
var a = new bmgl.Cartesian4();
bmgl.Matrix4.getRow(m, 2, a);
// a.x = 18.0; a.y = 19.0; a.z = 20.0; a.w = 21.0;
Throws
-
DeveloperError : 索引必须是0、1、2或3。
假设矩阵是仿射变换,则提取不均匀尺度。
Parameters:
获取所提供矩阵的转换部分,假定该矩阵是仿射变换矩阵。
Parameters:
使用Cramers规则计算所提供矩阵的逆矩阵。如果行列式为零,则矩阵不能反转,并引发异常。如果矩阵是仿射变换矩阵,用
Matrix4.inverseTransformation倒转更有效。
Parameters:
Throws
-
RuntimeError : 矩阵不可逆,因为它的确定度为零。
假设所提供的矩阵是仿射变换矩阵,其中左上3x3元素是旋转矩阵,第四列中的上三个元素是平移,则计算所提供矩阵的逆矩阵。假定底行为[0,0,0,1]。未验证矩阵的形式是否正确。此方法比使用
Matrix4.inverse计算一般4x4矩阵的逆矩阵更快。
Parameters:
计算两个矩阵的乘积。
Parameters:
将转换矩阵(底行为
[0.0, 0.0, 0.0, 1.0])乘以3x3旋转矩阵。这是针对Matrix4.multiply(m, Matrix4.fromRotationTranslation(rotation), m);的优化,具有较少的分配和算术运算。
Parameters:
Example
// Instead of bmgl.Matrix4.multiply(m, bmgl.Matrix4.fromRotationTranslation(rotation), m);
bmgl.Matrix4.multiplyByMatrix3(m, rotation, m);
计算矩阵和a
Cartesian3的乘积。这相当于用一个Cartesian4调用Matrix4.multiplyByVector,组件w为1,但返回一个Cartesian3而不是一个Cartesian4。
Parameters:
Example
var p = new bmgl.Cartesian3(1.0, 2.0, 3.0);
var result = bmgl.Matrix4.multiplyByPoint(matrix, p, new bmgl.Cartesian3());
Parameters:
Example
var p = new bmgl.Cartesian3(1.0, 2.0, 3.0);
var result = bmgl.Matrix4.multiplyByPointAsVector(matrix, p, new bmgl.Cartesian3());
// A shortcut for
// Cartesian3 p = ...
// bmgl.Matrix4.multiplyByVector(matrix, new bmgl.Cartesian4(p.x, p.y, p.z, 0.0), result);
计算矩阵和标量的乘积。
Parameters:
Example
//create a Matrix4 instance which is a scaled version of the supplied Matrix4
// m = [10.0, 11.0, 12.0, 13.0]
// [14.0, 15.0, 16.0, 17.0]
// [18.0, 19.0, 20.0, 21.0]
// [22.0, 23.0, 24.0, 25.0]
var a = bmgl.Matrix4.multiplyByScalar(m, -2, new bmgl.Matrix4());
// m remains the same
// a = [-20.0, -22.0, -24.0, -26.0]
// [-28.0, -30.0, -32.0, -34.0]
// [-36.0, -38.0, -40.0, -42.0]
// [-44.0, -46.0, -48.0, -50.0]
将仿射变换矩阵(底行为
[0.0, 0.0, 0.0, 1.0])乘以隐式非均匀比例矩阵。这是对Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);的优化,其中m必须是仿射矩阵。此函数执行的分配和算术运算更少。
Parameters:
Example
// Instead of bmgl.Matrix4.multiply(m, bmgl.Matrix4.fromScale(scale), m);
bmgl.Matrix4.multiplyByScale(m, scale, m);
将转换矩阵(底行为
[0.0, 0.0, 0.0, 1.0])乘以由Cartesian3定义的隐式转换矩阵。这是针对Matrix4.multiply(m, Matrix4.fromTranslation(position), m);的优化,分配和算术运算更少。
Parameters:
Example
// Instead of bmgl.Matrix4.multiply(m, bmgl.Matrix4.fromTranslation(position), m);
bmgl.Matrix4.multiplyByTranslation(m, position, m);
将仿射变换矩阵(底行为
[0.0, 0.0, 0.0, 1.0])乘以隐式均匀比例矩阵。这是对Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);的优化,其中m必须是仿射矩阵。此函数执行的分配和算术运算更少。
Parameters:
Example
// Instead of bmgl.Matrix4.multiply(m, bmgl.Matrix4.fromUniformScale(scale), m);
bmgl.Matrix4.multiplyByUniformScale(m, scale, m);
计算矩阵和列向量的乘积。
Parameters:
假设两个矩阵是仿射变换矩阵,其中左上3x3元素是旋转矩阵,第四列中的上三个元素是平移,则计算两个矩阵的乘积。假定底行为[0,0,0,1]。未验证矩阵的形式是否正确。此方法比使用
Matrix4.multiply计算一般4x4矩阵的产品更快。
Parameters:
Example
var m1 = new bmgl.Matrix4(1.0, 6.0, 7.0, 0.0, 2.0, 5.0, 8.0, 0.0, 3.0, 4.0, 9.0, 0.0, 0.0, 0.0, 0.0, 1.0);
var m2 = bmgl.Transforms.eastNorthUpToFixedFrame(new bmgl.Cartesian3(1.0, 1.0, 1.0));
var m3 = bmgl.Matrix4.multiplyTransformation(m1, m2, new bmgl.Matrix4());
计算所提供矩阵的否定副本。
Parameters:
Example
//create a new Matrix4 instance which is a negation of a Matrix4
// m = [10.0, 11.0, 12.0, 13.0]
// [14.0, 15.0, 16.0, 17.0]
// [18.0, 19.0, 20.0, 21.0]
// [22.0, 23.0, 24.0, 25.0]
var a = bmgl.Matrix4.negate(m, new bmgl.Matrix4());
// m remains the same
// a = [-10.0, -11.0, -12.0, -13.0]
// [-14.0, -15.0, -16.0, -17.0]
// [-18.0, -19.0, -20.0, -21.0]
// [-22.0, -23.0, -24.0, -25.0]
将提供的实例存储到提供的数组中。
Parameters:
array
(Array.<Number>)
要打包的数组。
startingIndex
(Number)
(default 0)
数组中开始打包元素的索引。
计算用提供的cartesian4实例替换所提供矩阵中指定列的新矩阵。
Parameters:
index
(Number)
要设置的列的从零开始的索引。
Example
//creates a new Matrix4 instance with new column values from the Cartesian4 instance
// m = [10.0, 11.0, 12.0, 13.0]
// [14.0, 15.0, 16.0, 17.0]
// [18.0, 19.0, 20.0, 21.0]
// [22.0, 23.0, 24.0, 25.0]
var a = bmgl.Matrix4.setColumn(m, 2, new bmgl.Cartesian4(99.0, 98.0, 97.0, 96.0), new bmgl.Matrix4());
// m remains the same
// a = [10.0, 11.0, 99.0, 13.0]
// [14.0, 15.0, 98.0, 17.0]
// [18.0, 19.0, 97.0, 21.0]
// [22.0, 23.0, 96.0, 25.0]
Throws
-
DeveloperError : 索引必须是0、1、2或3。
计算用提供的cartesian4实例替换所提供矩阵中指定行的新矩阵。
Parameters:
index
(Number)
要设置的行的从零开始的索引。
Example
//create a new Matrix4 instance with new row values from the Cartesian4 instance
// m = [10.0, 11.0, 12.0, 13.0]
// [14.0, 15.0, 16.0, 17.0]
// [18.0, 19.0, 20.0, 21.0]
// [22.0, 23.0, 24.0, 25.0]
var a = bmgl.Matrix4.setRow(m, 2, new bmgl.Cartesian4(99.0, 98.0, 97.0, 96.0), new bmgl.Matrix4());
// m remains the same
// a = [10.0, 11.0, 12.0, 13.0]
// [14.0, 15.0, 16.0, 17.0]
// [99.0, 98.0, 97.0, 96.0]
// [22.0, 23.0, 24.0, 25.0]
Throws
-
DeveloperError : 索引必须是0、1、2或3。
计算用提供的比例替换比例的新矩阵。假设矩阵是仿射变换。
Parameters:
计算一个新的矩阵,用所提供的翻译替换所提供矩阵最右列中的翻译。假设矩阵是仿射变换。
Parameters:
计算两个矩阵的差。
Parameters:
从提供的Matrix4实例计算数组。数组将按列主顺序排列。
Parameters:
result
(Array.<Number>)
存储结果的数组。
Example
//create an array from an instance of Matrix4
// m = [10.0, 14.0, 18.0, 22.0]
// [11.0, 15.0, 19.0, 23.0]
// [12.0, 16.0, 20.0, 24.0]
// [13.0, 17.0, 21.0, 25.0]
var a = bmgl.Matrix4.toArray(m);
// m remains the same
//creates a = [10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0]
计算所提供矩阵的转置。
Parameters:
Example
//returns transpose of a Matrix4
// m = [10.0, 11.0, 12.0, 13.0]
// [14.0, 15.0, 16.0, 17.0]
// [18.0, 19.0, 20.0, 21.0]
// [22.0, 23.0, 24.0, 25.0]
var a = bmgl.Matrix4.transpose(m, new bmgl.Matrix4());
// m remains the same
// a = [10.0, 14.0, 18.0, 22.0]
// [11.0, 15.0, 19.0, 23.0]
// [12.0, 16.0, 20.0, 24.0]
// [13.0, 17.0, 21.0, 25.0]
从压缩数组中检索实例。
Parameters:
array
(Array.<Number>)
压缩数组。
startingIndex
(Number)
(default 0)
要解包的元素的起始索引。