How to use te method in wpt

Best JavaScript code snippet using wpt

Matrix4.js

Source:Matrix4.js Github

copy

Full Screen

1import { Vector3 } from './Vector3';2function Matrix4(){3 this.elements = [4 1, 0, 0, 0,5 0, 1, 0, 0,6 0, 0, 1, 0,7 0, 0, 0, 18 ];9}10Object.assign( Matrix4.prototype, {11 isMatrix4: true,12 set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {13 var te = this.elements;14 te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;15 te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;16 te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;17 te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;18 return this;19 },20 identity: function () {21 this.set(22 1, 0, 0, 0,23 0, 1, 0, 0,24 0, 0, 1, 0,25 0, 0, 0, 126 );27 return this;28 },29 clone: function () {30 return new this.constructor().fromArray( this.elements );31 },32 copy: function ( m ) {33 var te = this.elements;34 var me = m.elements;35 for ( var i = 0; i < 16; i ++ ) te[ i ] = me[ i ];36 return this;37 },38 //复制矩阵平移信息,就是仿射矩阵的第四列数据39 copyPosition: function ( m ) {40 var te = this.elements, me = m.elements;41 te[ 12 ] = me[ 12 ];42 te[ 13 ] = me[ 13 ];43 te[ 14 ] = me[ 14 ];44 return this;45 },46 //提取矩阵中的三个基向量,分别就是矩阵的第一二三列,这里需要理解矩阵与基向量的概念。47 extractBasis: function ( xAxis, yAxis, zAxis ) {48 xAxis.setFromMatrixColumn( this, 0 );49 yAxis.setFromMatrixColumn( this, 1 );50 zAxis.setFromMatrixColumn( this, 2 );51 return this;52 },53 //直接给定三个基向量来定义矩阵54 makeBasis: function ( xAxis, yAxis, zAxis ) {55 this.set(56 xAxis.x, yAxis.x, zAxis.x, 0,57 xAxis.y, yAxis.y, zAxis.y, 0,58 xAxis.z, yAxis.z, zAxis.z, 0,59 0, 0, 0, 160 );61 return this;62 },63 //提取三维旋转向量到本矩阵,将目标矩阵的三个基向量标准化(除以向量长度)后赋值到本矩阵中。64 extractRotation: function () {65 var v1 = new Vector3();66 return function extractRotation( m ) {67 var te = this.elements;68 var me = m.elements;69 var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();70 var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();71 var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();72 te[ 0 ] = me[ 0 ] * scaleX;73 te[ 1 ] = me[ 1 ] * scaleX;74 te[ 2 ] = me[ 2 ] * scaleX;75 te[ 4 ] = me[ 4 ] * scaleY;76 te[ 5 ] = me[ 5 ] * scaleY;77 te[ 6 ] = me[ 6 ] * scaleY;78 te[ 8 ] = me[ 8 ] * scaleZ;79 te[ 9 ] = me[ 9 ] * scaleZ;80 te[ 10 ] = me[ 10 ] * scaleZ;81 return this;82 };83 }(),84 //通过欧拉角获得旋转矩阵85 makeRotationFromEuler: function ( euler ) {86 if ( ( euler && euler.isEuler ) === false ) {87 console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );88 }89 var te = this.elements;90 var x = euler.x, y = euler.y, z = euler.z;91 var a = Math.cos( x ), b = Math.sin( x );92 var c = Math.cos( y ), d = Math.sin( y );93 var e = Math.cos( z ), f = Math.sin( z );94 if ( euler.order === 'XYZ' ) {95 var ae = a * e, af = a * f, be = b * e, bf = b * f;96 te[ 0 ] = c * e;97 te[ 4 ] = - c * f;98 te[ 8 ] = d;99 te[ 1 ] = af + be * d;100 te[ 5 ] = ae - bf * d;101 te[ 9 ] = - b * c;102 te[ 2 ] = bf - ae * d;103 te[ 6 ] = be + af * d;104 te[ 10 ] = a * c;105 } else if ( euler.order === 'YXZ' ) {106 var ce = c * e, cf = c * f, de = d * e, df = d * f;107 te[ 0 ] = ce + df * b;108 te[ 4 ] = de * b - cf;109 te[ 8 ] = a * d;110 te[ 1 ] = a * f;111 te[ 5 ] = a * e;112 te[ 9 ] = - b;113 te[ 2 ] = cf * b - de;114 te[ 6 ] = df + ce * b;115 te[ 10 ] = a * c;116 } else if ( euler.order === 'ZXY' ) {117 var ce = c * e, cf = c * f, de = d * e, df = d * f;118 te[ 0 ] = ce - df * b;119 te[ 4 ] = - a * f;120 te[ 8 ] = de + cf * b;121 te[ 1 ] = cf + de * b;122 te[ 5 ] = a * e;123 te[ 9 ] = df - ce * b;124 te[ 2 ] = - a * d;125 te[ 6 ] = b;126 te[ 10 ] = a * c;127 } else if ( euler.order === 'ZYX' ) {128 var ae = a * e, af = a * f, be = b * e, bf = b * f;129 te[ 0 ] = c * e;130 te[ 4 ] = be * d - af;131 te[ 8 ] = ae * d + bf;132 te[ 1 ] = c * f;133 te[ 5 ] = bf * d + ae;134 te[ 9 ] = af * d - be;135 te[ 2 ] = - d;136 te[ 6 ] = b * c;137 te[ 10 ] = a * c;138 } else if ( euler.order === 'YZX' ) {139 var ac = a * c, ad = a * d, bc = b * c, bd = b * d;140 te[ 0 ] = c * e;141 te[ 4 ] = bd - ac * f;142 te[ 8 ] = bc * f + ad;143 te[ 1 ] = f;144 te[ 5 ] = a * e;145 te[ 9 ] = - b * e;146 te[ 2 ] = - d * e;147 te[ 6 ] = ad * f + bc;148 te[ 10 ] = ac - bd * f;149 } else if ( euler.order === 'XZY' ) {150 var ac = a * c, ad = a * d, bc = b * c, bd = b * d;151 te[ 0 ] = c * e;152 te[ 4 ] = - f;153 te[ 8 ] = d * e;154 te[ 1 ] = ac * f + bd;155 te[ 5 ] = a * e;156 te[ 9 ] = ad * f - bc;157 te[ 2 ] = bc * f - ad;158 te[ 6 ] = b * e;159 te[ 10 ] = bd * f + ac;160 }161 // last column162 te[ 3 ] = 0;163 te[ 7 ] = 0;164 te[ 11 ] = 0;165 // bottom row166 te[ 12 ] = 0;167 te[ 13 ] = 0;168 te[ 14 ] = 0;169 te[ 15 ] = 1;170 return this;171 },172 //通过四元数获得旋转矩阵,推导过程可以baidu173 makeRotationFromQuaternion: function ( q ) {174 var te = this.elements;175 var x = q.x, y = q.y, z = q.z, w = q.w;176 var x2 = x + x, y2 = y + y, z2 = z + z;177 var xx = x * x2, xy = x * y2, xz = x * z2;178 var yy = y * y2, yz = y * z2, zz = z * z2;179 var wx = w * x2, wy = w * y2, wz = w * z2;180 te[ 0 ] = 1 - ( yy + zz );181 te[ 4 ] = xy - wz;182 te[ 8 ] = xz + wy;183 te[ 1 ] = xy + wz;184 te[ 5 ] = 1 - ( xx + zz );185 te[ 9 ] = yz - wx;186 te[ 2 ] = xz - wy;187 te[ 6 ] = yz + wx;188 te[ 10 ] = 1 - ( xx + yy );189 // last column190 te[ 3 ] = 0;191 te[ 7 ] = 0;192 te[ 11 ] = 0;193 // bottom row194 te[ 12 ] = 0;195 te[ 13 ] = 0;196 te[ 14 ] = 0;197 te[ 15 ] = 1;198 return this;199 },200 //这里是一个可以比较清晰看到基向量和旋转矩阵关系的地方,先算出z轴基向量,再算出x轴基向量,最后是y轴,然后基向量组合成旋转矩阵201 lookAt: function () {202 var x = new Vector3();203 var y = new Vector3();204 var z = new Vector3();205 return function lookAt( eye, target, up ) {206 var te = this.elements;207 z.subVectors( eye, target ).normalize();208 if ( z.lengthSq() === 0 ) {209 z.z = 1;210 }211 x.crossVectors( up, z ).normalize();212 if ( x.lengthSq() === 0 ) {213 z.z += 0.0001;214 x.crossVectors( up, z ).normalize();215 }216 y.crossVectors( z, x );217 te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;218 te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;219 te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;220 return this;221 };222 }(),223 //矩阵乘法224 multiply: function ( m ) {225 return this.multiplyMatrices( this, m );226 },227 //矩阵左乘228 premultiply: function ( m ) {229 return this.multiplyMatrices( m, this );230 },231 //矩阵相乘232 multiplyMatrices: function ( a, b ) {233 var ae = a.elements;234 var be = b.elements;235 var te = this.elements;236 var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];237 var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];238 var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];239 var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];240 var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];241 var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];242 var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];243 var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];244 te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;245 te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;246 te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;247 te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;248 te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;249 te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;250 te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;251 te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;252 te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;253 te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;254 te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;255 te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;256 te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;257 te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;258 te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;259 te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;260 return this;261 },262 //矩阵乘以标量263 multiplyScalar: function ( s ) {264 var te = this.elements;265 te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;266 te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;267 te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;268 te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;269 return this;270 },271 //四维矩阵行列式计算272 determinant: function () {273 var te = this.elements;274 var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];275 var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];276 var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];277 var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];278 return (279 n41 * (280 + n14 * n23 * n32281 - n13 * n24 * n32282 - n14 * n22 * n33283 + n12 * n24 * n33284 + n13 * n22 * n34285 - n12 * n23 * n34286 ) +287 n42 * (288 + n11 * n23 * n34289 - n11 * n24 * n33290 + n14 * n21 * n33291 - n13 * n21 * n34292 + n13 * n24 * n31293 - n14 * n23 * n31294 ) +295 n43 * (296 + n11 * n24 * n32297 - n11 * n22 * n34298 - n14 * n21 * n32299 + n12 * n21 * n34300 + n14 * n22 * n31301 - n12 * n24 * n31302 ) +303 n44 * (304 - n13 * n22 * n31305 - n11 * n23 * n32306 + n11 * n22 * n33307 + n13 * n21 * n32308 - n12 * n21 * n33309 + n12 * n23 * n31310 )311 );312 },313 //矩阵转置314 transpose: function () {315 var te = this.elements;316 var tmp;317 tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;318 tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;319 tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;320 tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;321 tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;322 tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;323 return this;324 },325 //设置位移326 setPosition: function ( v ) {327 var te = this.elements;328 te[ 12 ] = v.x;329 te[ 13 ] = v.y;330 te[ 14 ] = v.z;331 return this;332 },333 //计算逆矩阵334 getInverse: function ( m ) {335 var te = this.elements,336 me = m.elements,337 n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],338 n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],339 n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],340 n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],341 t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,342 t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,343 t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,344 t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;345 var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;346 if ( det === 0 ) return this.identity();347 var detInv = 1 / det;348 te[ 0 ] = t11 * detInv;349 te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;350 te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;351 te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;352 te[ 4 ] = t12 * detInv;353 te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;354 te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;355 te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;356 te[ 8 ] = t13 * detInv;357 te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;358 te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;359 te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;360 te[ 12 ] = t14 * detInv;361 te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;362 te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;363 te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;364 return this;365 },366 //矩阵乘以标量367 scale: function ( v ) {368 var te = this.elements;369 var x = v.x, y = v.y, z = v.z;370 te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;371 te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;372 te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;373 te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;374 return this;375 },376 //获得三维基坐标缩放比例最大值377 getMaxScaleOnAxis: function () {378 var te = this.elements;379 var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];380 var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];381 var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];382 return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );383 },384 //设置位移矩阵385 makeTranslation: function ( x, y, z ) {386 this.set(387 1, 0, 0, x,388 0, 1, 0, y,389 0, 0, 1, z,390 0, 0, 0, 1391 );392 return this;393 },394 //设置x轴旋转矩阵395 makeRotationX: function ( theta ) {396 var c = Math.cos( theta ), s = Math.sin( theta );397 this.set(398 1, 0, 0, 0,399 0, c, - s, 0,400 0, s, c, 0,401 0, 0, 0, 1402 );403 return this;404 },405 //设置y轴旋转矩阵406 makeRotationY: function ( theta ) {407 var c = Math.cos( theta ), s = Math.sin( theta );408 this.set(409 c, 0, s, 0,410 0, 1, 0, 0,411 - s, 0, c, 0,412 0, 0, 0, 1413 );414 return this;415 },416 //设置z轴旋转矩阵417 makeRotationZ: function ( theta ) {418 var c = Math.cos( theta ), s = Math.sin( theta );419 this.set(420 c, - s, 0, 0,421 s, c, 0, 0,422 0, 0, 1, 0,423 0, 0, 0, 1424 );425 return this;426 },427 //通过轴角设置旋转矩阵428 makeRotationAxis: function ( axis, angle ) {429 var c = Math.cos( angle );430 var s = Math.sin( angle );431 var t = 1 - c;432 var x = axis.x, y = axis.y, z = axis.z;433 var tx = t * x, ty = t * y;434 this.set(435 tx * x + c, tx * y - s * z, tx * z + s * y, 0,436 tx * y + s * z, ty * y + c, ty * z - s * x, 0,437 tx * z - s * y, ty * z + s * x, t * z * z + c, 0,438 0, 0, 0, 1439 );440 return this;441 },442 //设施缩放变换矩阵443 makeScale: function ( x, y, z ) {444 this.set(445 x, 0, 0, 0,446 0, y, 0, 0,447 0, 0, z, 0,448 0, 0, 0, 1449 );450 return this;451 },452 //设置剪切变换矩阵453 makeShear: function ( x, y, z ) {454 this.set(455 1, y, z, 0,456 x, 1, z, 0,457 x, y, 1, 0,458 0, 0, 0, 1459 );460 return this;461 },462 //通过位置向量,旋转四元数,缩放向量合并定义仿射矩阵463 compose: function ( position, quaternion, scale ) {464 this.makeRotationFromQuaternion( quaternion );465 this.scale( scale );466 this.setPosition( position );467 return this;468 },469 //将放射矩阵分解成位置向量,旋转四元数,缩放向量470 decompose: function () {471 var vector = new Vector3();472 var matrix = new Matrix4();473 return function decompose( position, quaternion, scale ) {474 var te = this.elements;475 var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();476 var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();477 var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();478 // if determine is negative, we need to invert one scale479 var det = this.determinant();480 if ( det < 0 ) {481 sx = - sx;482 }483 position.x = te[ 12 ];484 position.y = te[ 13 ];485 position.z = te[ 14 ];486 // scale the rotation part487 for ( var i = 0; i < 16; i ++ ) matrix.elements[ i ] = this.elements[ i ]; // at this point matrix is incomplete so we can't use .copy()488 var invSX = 1 / sx;489 var invSY = 1 / sy;490 var invSZ = 1 / sz;491 matrix.elements[ 0 ] *= invSX;492 matrix.elements[ 1 ] *= invSX;493 matrix.elements[ 2 ] *= invSX;494 matrix.elements[ 4 ] *= invSY;495 matrix.elements[ 5 ] *= invSY;496 matrix.elements[ 6 ] *= invSY;497 matrix.elements[ 8 ] *= invSZ;498 matrix.elements[ 9 ] *= invSZ;499 matrix.elements[ 10 ] *= invSZ;500 quaternion.setFromRotationMatrix( matrix );501 scale.x = sx;502 scale.y = sy;503 scale.z = sz;504 return this;505 };506 }(),507 //计算透视矩阵,就是最常用变换三人组MVP中的P508 makePerspective: function ( left, right, top, bottom, near, far ) {509 var te = this.elements;510 var x = 2 * near / ( right - left );511 var y = 2 * near / ( top - bottom );512 var a = ( right + left ) / ( right - left );513 var b = ( top + bottom ) / ( top - bottom );514 var c = - ( far + near ) / ( far - near );515 var d = - 2 * far * near / ( far - near );516 te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;517 te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;518 te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;519 te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;520 return this;521 },522 //计算正交矩阵523 makeOrthographic: function ( left, right, top, bottom, near, far ) {524 var te = this.elements;525 var w = 1.0 / ( right - left );526 var h = 1.0 / ( top - bottom );527 var p = 1.0 / ( far - near );528 var x = ( right + left ) * w;529 var y = ( top + bottom ) * h;530 var z = ( far + near ) * p;531 te[ 0 ] = 2 * w;te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;532 te[ 1 ] = 0; te[ 5 ] = 2 * h;te[ 9 ] = 0; te[ 13 ] = - y;533 te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;534 te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;535 return this;536 },537 equals: function ( matrix ) {538 var te = this.elements;539 var me = matrix.elements;540 for ( var i = 0; i < 16; i ++ ) {541 if ( te[ i ] !== me[ i ] ) return false;542 }543 return true;544 },545 fromArray: function ( array, offset ) {546 if ( offset === undefined ) offset = 0;547 for( var i = 0; i < 16; i ++ ) {548 this.elements[ i ] = array[ i + offset ];549 }550 return this;551 },552 toArray: function ( array, offset ) {553 if ( array === undefined ) array = [];554 if ( offset === undefined ) offset = 0;555 var te = this.elements;556 array[ offset ] = te[ 0 ];557 array[ offset + 1 ] = te[ 1 ];558 array[ offset + 2 ] = te[ 2 ];559 array[ offset + 3 ] = te[ 3 ];560 array[ offset + 4 ] = te[ 4 ];561 array[ offset + 5 ] = te[ 5 ];562 array[ offset + 6 ] = te[ 6 ];563 array[ offset + 7 ] = te[ 7 ];564 array[ offset + 8 ] = te[ 8 ];565 array[ offset + 9 ] = te[ 9 ];566 array[ offset + 10 ] = te[ 10 ];567 array[ offset + 11 ] = te[ 11 ];568 array[ offset + 12 ] = te[ 12 ];569 array[ offset + 13 ] = te[ 13 ];570 array[ offset + 14 ] = te[ 14 ];571 array[ offset + 15 ] = te[ 15 ];572 return array;573 }574});...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2wpt.get(url, function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var http = require('http');10var get = function(url, callback) {11 http.get(url, function(res) {12 var body = '';13 res.on('data', function(chunk) {14 body += chunk;15 });16 res.on('end', function() {17 callback(null, body);18 });19 }).on('error', function(e) {20 callback(e);21 });22};23module.exports.get = get;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = new WebPageTest('www.webpagetest.org', 'A.0b6f1d1f0e8d3a6c7b6f3a9a3b6f1d1f');2var wpt = new WebPageTest('www.webpagetest.org', 'A.0b6f1d1f0e8d3a6c7b6f3a9a3b6f1d1f');3var options = {4};5wpt.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test status:', data.statusText);8 console.log('View your test at:', data.data.userUrl);9});10var wpt = new WebPageTest('www.webpagetest.org', 'A.0b6f1d1f0e8d3a6c7b6f3a9a3b6f1d1f');11var wpt = new WebPageTest('www.webpagetest.org', 'A.0b6f1d1f0e8d3a6c7b6

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8var request = require('request');9module.exports.getWptData = function (url, callback) {10 var options = {11 headers: {12 }13 };14 request(options, function (err, res, body) {15 if (err) {16 callback(err);17 } else {18 callback(null, body);19 }20 });21};22{ [Error: getaddrinfo ENOTFOUND www.webpagetest.org www.webpagetest.org:80]23 port: 80 }24var wpt = require('./wpt.js');25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31var request = require('request');32module.exports.getWptData = function (url, callback) {33 var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt').create('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');2var options = {3};4wpt.runTest(url, options, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7});8var wpt = require('wpt');9wpt.create('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef')10 }, function(err, data) {11 if (err) return console.error(err);12 console.log(data);13 });14var wpt = require('wpt');15wpt.create('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef')16 }, function(err, data) {17 if (err) return console.error(err);18 console.log(data);19 });20var wpt = require('wpt');21wpt.create('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef')

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2wpt.getTestResults('testId', function(err, data) {3 console.log(data);4});5exports.getTestResults = function(testId, callback) {6 callback(err, body);7 });8};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful