Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 852 vs 853 for /trunk/Source Code/Core/Math/Headers/Quaternion.inl

Diff revisions: vs.
  @@ -297,6 +297,34 @@
297 297 // normalize(); this method does produce a normalized quaternion
298 298 }
299 299
300 + //ref: https://www.gamedev.net/topic/613595-quaternion-lookrotationlookat-up/
301 + template <typename T>
302 + void Quaternion<T>::fromLookAt(const vec3<F32>& fwdDirection, const vec3<F32>& upDirection) {
303 + vec3<F32> forward(fwdDirection);
304 + vec3<F32> up(upDirection);
305 +
306 + OrthoNormalize(forward, up);
307 + vec3<F32> right(Cross(up, forward));
308 +
309 + const F32& m00 = right.x;
310 + const F32& m01 = up.x;
311 + const F32& m02 = forward.x;
312 + const F32& m10 = right.y;
313 + const F32& m11 = up.y;
314 + const F32& m12 = forward.y;
315 + const F32& m20 = right.z;
316 + const F32& m21 = up.z;
317 + const F32& m22 = forward.z;
318 +
319 + F32 w = sqrtf(1.0f + m00 + m11 + m22) * 0.5f;
320 + F32 w4_recip = 1.0f / (4.0f * w);
321 + F32 x = (m21 - m12) * w4_recip;
322 + F32 y = (m02 - m20) * w4_recip;
323 + F32 z = (m10 - m01) * w4_recip;
324 +
325 + set(x, y, z, w);
326 + }
327 +
300 328 template <typename T>
301 329 void Quaternion<T>::fromMatrix(const mat3<T>& rotationMatrix) {
302 330 // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes