* Performs a spherical linear interpolation between two quat * * @param {quat} out the receiving quaternion * @param {ReadonlyQuat} a the first operand * @param {ReadonlyQuat} b the second operand * @param {Number} t interpolation amount, in the range [0-1], between the two inputs * @ret
(out, a, b, t)
| 4202 | */ |
| 4203 | |
| 4204 | function slerp(out, a, b, t) { |
| 4205 | // benchmarks: |
| 4206 | // http://jsperf.com/quaternion-slerp-implementations |
| 4207 | var ax = a[0], |
| 4208 | ay = a[1], |
| 4209 | az = a[2], |
| 4210 | aw = a[3]; |
| 4211 | var bx = b[0], |
| 4212 | by = b[1], |
| 4213 | bz = b[2], |
| 4214 | bw = b[3]; |
| 4215 | var omega, cosom, sinom, scale0, scale1; // calc cosine |
| 4216 | |
| 4217 | cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary) |
| 4218 | |
| 4219 | if (cosom < 0.0) { |
| 4220 | cosom = -cosom; |
| 4221 | bx = -bx; |
| 4222 | by = -by; |
| 4223 | bz = -bz; |
| 4224 | bw = -bw; |
| 4225 | } // calculate coefficients |
| 4226 | |
| 4227 | |
| 4228 | if (1.0 - cosom > _common_js__WEBPACK_IMPORTED_MODULE_0__["EPSILON"]) { |
| 4229 | // standard case (slerp) |
| 4230 | omega = Math.acos(cosom); |
| 4231 | sinom = Math.sin(omega); |
| 4232 | scale0 = Math.sin((1.0 - t) * omega) / sinom; |
| 4233 | scale1 = Math.sin(t * omega) / sinom; |
| 4234 | } else { |
| 4235 | // "from" and "to" quaternions are very close |
| 4236 | // ... so we can do a linear interpolation |
| 4237 | scale0 = 1.0 - t; |
| 4238 | scale1 = t; |
| 4239 | } // calculate final values |
| 4240 | |
| 4241 | |
| 4242 | out[0] = scale0 * ax + scale1 * bx; |
| 4243 | out[1] = scale0 * ay + scale1 * by; |
| 4244 | out[2] = scale0 * az + scale1 * bz; |
| 4245 | out[3] = scale0 * aw + scale1 * bw; |
| 4246 | return out; |
| 4247 | } |
| 4248 | /** |
| 4249 | * Generates a random unit quaternion |
| 4250 | * |