Back to class index
Quat[Class Summary]
x
y
z
w
identity[static][const]
nan[static][const]
ctor (+7 overloads)
WorldX()[const]
WorldY()[const]
WorldZ()[const]
Axis()[const]
Angle()[const]
Dot(rhs)[const]
LengthSq()[const]
Length()[const]
Normalize()
Normalized()[const]
IsNormalized(epsilon)[const]
IsInvertible(epsilon)[const]
IsFinite()[const]
Equals(rhs,epsilon)[const]
BitEquals(other)[const]
ptr() (+1 overload)
Inverse()
Inverted()[const]
InverseAndNormalize()
Conjugate()
Conjugated()[const]
Transform(x,y,z)[const] (+2 overloads)
Lerp(target,t)[const]
Slerp(target,t)[const]
AngleBetween(target)[const]
AxisFromTo(target)[const]
ToAxisAngle(...)[const] (+1 overload)
SetFromAxisAngle(...) (+1 overload)
Set(matrix) (+3 overloads)
ToEulerXYX()[const]
ToFloat3x3()[const]
ToFloat3x4()[const]
ToFloat4x4()[const] (+2 overloads)
ToString()[const]
ToString2()[const]
SerializeToString()[const]
SerializeToCodeString()[const]
operator*(rhs)[const] (+2 overloads)
operator/(rhs)[const]
operator+()[const]
Mul(rhs)[const] (+3 overloads)
Neg()[const]
Lerp(source,target,t)[static]
Slerp(source,target,t)[static]
SlerpVector(from,to,t)[static]
SlerpVectorAbs(...)[static]
LookAt(...)[static]
RotateX(angleRadians)[static]
RotateY(angleRadians)[static]
RotateZ(angleRadians)[static]
RotateAxisAngle(...)[static]
RotateFromTo(...)[static] (+2 overloads)
FromEuler***(x2,y,x)[static]
RandomRotation(lcg)[static]
FromString(str,outEndStr)[static] (+1 overload)

Quat::LookAt

Syntax

MUST_USE_RESULT Quat Quat::LookAt(const float3 &localForward, const float3 &targetDirection, const float3 &localUp, const float3 &worldUp); [4 lines of code]

Creates a LookAt quaternion.

A LookAt quaternion is a quaternion that orients an object to face towards a specified target direction.

Parameters

const float3 &localForwardSpecifies the forward direction in the local space of the object. This is the direction the model is facing at in its own local/object space, often +X (1,0,0), +Y (0,1,0) or +Z (0,0,1). The vector to pass in here depends on the conventions you or your modeling software is using, and it is best pick one convention for all your objects, and be consistent. This input parameter must be a normalized vector. const float3 &targetDirectionSpecifies the desired world space direction the object should look at. This function will compute a quaternion which will rotate the localForward vector to orient towards this targetDirection vector. This input parameter must be a normalized vector. const float3 &localUpSpecifies the up direction in the local space of the object. This is the up direction the model was authored in, often +Y (0,1,0) or +Z (0,0,1). The vector to pass in here depends on the conventions you or your modeling software is using, and it is best to pick one convention for all your objects, and be consistent. This input parameter must be a normalized vector. This vector must be perpendicular to the vector localForward, i.e. localForward.Dot(localUp) == 0. const float3 &worldUpSpecifies the global up direction of the scene in world space. Simply rotating one vector to coincide with another (localForward->targetDirection) would cause the up direction of the resulting orientation to drift (e.g. the model could be looking at its target its head slanted sideways). To keep the up direction straight, this function orients the localUp direction of the model to point towards the specified worldUp direction (as closely as possible). The worldUp and targetDirection vectors cannot be collinear, but they do not need to be perpendicular either.

Return Value

A quaternion that maps the given local space forward direction vector to point towards the given target direction, and the given local up direction towards the given target world up direction. For the returned quaternion Q it holds that M * localForward = targetDirection, and M * localUp lies in the plane spanned by the vectors targetDirection and worldUp.

See Also

RotateFromTo().