Can't get relative rotation to work (using quaternions)

I’ve been trying for days, but can’t understand what statements to use to get the rotation I want.
A rotation (around the x and y axes) in world space by deltaQuat does exactly what I want.



	deltaQuat = FQuat::Identity;
	deltaQuat = deltaQuat * rotateCM(DeltaTime);
	deltaQuat = deltaQuat * barrelRollRotate(DeltaTime);

	LocalToWorld = OurVisibleComponent->GetComponentQuat();
	LocalToWorld = (deltaQuat * LocalToWorld); //will change rotation in **world space** by deltaQuat.
	OurVisibleComponent->Set**World**Rotation(LocalToWorld);


But this doesn’t produce the result I want when I also have a world rotation around the z axis. I want it to rotate around itself, and not around the fixed axes of the world. So I should use relative rotation, right?

I thought this would do the trick:



	LocalToWorld = OurVisibleComponent->GetComponentQuat();
	LocalToWorld = LocalToWorld * deltaQuat; //will change rotation in **local space** by deltaQuat.
	OurVisibleComponent->Set**Relative**Rotation(LocalToWorld);


But whenever I use SetRelativeRotation(…) my pawn just keeps spinning. Now I suspect it is because GetComponentQuat() returns the rotation in world space, not in relative space. But there doesn’t seem to a relative space equivalent of GetComponentQuat.

So I’m stuck, and out of options :frowning:

Did I post this under the right sub-forum? If not where should I post this?

hey there,

a rotation is always applied on an objects origin (0.0.0). Consider each object to have its own modelmatrix with an own x,y,z coordinate origin.

So placing an object in the world means, create a new object where the objects origin is relative to the world. But apply any rotation on this object only affects the objects origin and change it.

Here an example:

consider our solar system. The “World” origin is the Sun and every planet is transformed relative to the sun. But there are also object which are more relative to a planet than to the sun, f.e. the moon from the earth. He is relative to the earth and SetRelativeMoonRoation affects
the moon’s rotation towards the rotation of its “root” component (the earth).

so to be precise:

this is always the case whether its world or root relative.

I havnt quite get what you want to achieve but afaics your calc seems to be a bit too complicated if you just want to rotate an object around itself.

For simple stuff i would use FRotators instead of quaternions but this shouldnt matter.

lets say you wanna rotate a sphere around itself.

Set up a float value fSpeed defining the angle amount which should be applied each tick.

inside Tick:




/* Untested, since im not at my windows pc right now to test it */
FRotator rot = Component->GetComponentRotation();

rot.Pitch += fSpeed * DeltaTime;

Component->SetRelativeRotation(rot);

/* you could do it with SetWorldRotation too, but the results are different */



this will result in an eternal pitch rotation ( just be sure to stay inside 360°)

kind regards

Thanks for your help Walhalla, I managed to fix the problem.
Apparently there is a useful function called addRelativeRotation(). And I needed to apply my X and Y rotations to the mesh component, and the Z rotation to the root component.
Still don’t feel like I properly understand relative rotation vs world rotation though.