Combine Rotators in CPP

How can I get the same effect as this function in c++?

Thanks,
Sammy

You can just use the + or += operators.

RotatorA + RotatorB = RotatorC; // A + B, the new result is stored in C.

RotatorA += RotatorB; // A + B, the new result is stored in A.
2 Likes

Nice and easy, thank you very much.

The function is actually implemented with quaternions so you might get different results to simply adding together rotators in some cases.

Actual code:

FRotator UKismetMathLibrary::ComposeRotators(FRotator A, FRotator B)
{
	FQuat AQuat = FQuat(A);
	FQuat BQuat = FQuat(B);

	return FRotator(BQuat*AQuat);
}
3 Likes

thanks.
also possible to write it in one line if somebody needs to:

return FRotator(FQuat(A)*FQuat(B));

3 Likes

Just for the records and in case someone finds this suggestion and gets strange results, the product (composition) of quaternions is non-commutative, so it should be:

return FRotator(FQuat(B)*FQuat(A))

as order matters.