- To construct a quaternion, the best constructor to use is as follows:
FQuat( FVector Axis, float AngleRad );
Quaternions have quaternion addition, quaternion subtraction, multiplication by a scalar, and division by a scalar defined for them, among other functions. They are extremely useful to rotate things at arbitrary angles, and point objects at one another.
- For example, if you wanted to use an FQuat inside of the RotateActorComponent.cpp file, it would look similar to this:
void URotateActorComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// 11-04 - Rotation using FQuat
FQuat quat = FQuat(FVector(0, 1, 0), GetWorld()->TimeSeconds * PI / 4.f);
GetOwner()->SetActorRotation(quat);
}
Upon compiling your code and returning to the game, you should notice the cube moving at a constant rate: