* Applies the given Quaternion to this vector. * * @param {Quaternion} q - The Quaternion. * @return {Vector3} A reference to this vector.
( q )
| 469 | * @return {Vector3} A reference to this vector. |
| 470 | */ |
| 471 | applyQuaternion( q ) { |
| 472 | |
| 473 | // quaternion q is assumed to have unit length |
| 474 | |
| 475 | const vx = this.x, vy = this.y, vz = this.z; |
| 476 | const qx = q.x, qy = q.y, qz = q.z, qw = q.w; |
| 477 | |
| 478 | // t = 2 * cross( q.xyz, v ); |
| 479 | const tx = 2 * ( qy * vz - qz * vy ); |
| 480 | const ty = 2 * ( qz * vx - qx * vz ); |
| 481 | const tz = 2 * ( qx * vy - qy * vx ); |
| 482 | |
| 483 | // v + q.w * t + cross( q.xyz, t ); |
| 484 | this.x = vx + qw * tx + qy * tz - qz * ty; |
| 485 | this.y = vy + qw * ty + qz * tx - qx * tz; |
| 486 | this.z = vz + qw * tz + qx * ty - qy * tx; |
| 487 | |
| 488 | return this; |
| 489 | |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Projects this vector from world space into the camera's normalized |
no outgoing calls
no test coverage detected