MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / FindBetween

Method FindBetween

Source/Engine/Core/Math/Quaternion.cpp:456–478  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

454}
455
456void Quaternion::FindBetween(const Float3& from, const Float3& to, Quaternion& result)
457{
458 // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
459 const float normFromNormTo = Math::Sqrt(from.LengthSquared() * to.LengthSquared());
460 if (normFromNormTo < ZeroTolerance)
461 {
462 result = Identity;
463 return;
464 }
465 const float w = normFromNormTo + Float3::Dot(from, to);
466 if (w < 1.e-6f * normFromNormTo)
467 {
468 result = Math::Abs(from.X) > Math::Abs(from.Z)
469 ? Quaternion(-from.Y, from.X, 0.0f, 0.0f)
470 : Quaternion(0.0f, -from.Z, from.Y, 0.0f);
471 }
472 else
473 {
474 const Float3 cross = Float3::Cross(from, to);
475 result = Quaternion(cross.X, cross.Y, cross.Z, w);
476 }
477 result.Normalize();
478}
479
480void Quaternion::Slerp(const Quaternion& start, const Quaternion& end, float amount, Quaternion& result)
481{

Callers

nothing calls this directly

Calls 6

DotFunction · 0.85
SqrtFunction · 0.70
AbsFunction · 0.70
QuaternionFunction · 0.70
LengthSquaredMethod · 0.45
NormalizeMethod · 0.45

Tested by

no test coverage detected