#Rotating around an axis

10 messages · Page 1 of 1 (latest)

tame prairie
#

I'm making a marble platforming game and I'm having a lot of trouble getting the marble to rotate correctly. In the video, the white line is the rotation axis and the gold line is the movement. Here's the code:

transform.rotation *= Quat::from_axis_angle(rotation_axis, angle);
sinful quail
#

I'm struggling to understand what exactly is going on from the video, and what exactly is wrong. I know in the second half I see it turning 45 degrees from where the white line is, which seems to be wrong. I'm also wondering if the center of the ball is actually moving or if it's just rotating in place

#

One thought here is maybe if you try to do the multiplication in the opposite order it might work - but I'm not good enough with quaternions to actually know if that's right or you have that part right already

tame prairie
#

yeah, at 7 seconds you can see the problem. I want the ball to rotate around the white line but it's rotating at a weird angle. the ball is moving but that shouldn't affect this. I can't change the order because I am assigning to the rotation

sinful quail
#

transform.rotation = Quat::from_axis_angle(rotation_axis, angle) * transform.rotation;

tame prairie
#

oh, I can try it

#

that worked!

sinful quail
#

Awesome!

tame prairie
#

I don't know enough about quaternions to know why this is the correct order

sinful quail
#

The idea is that the order of the multiplication determines the order of the rotations - so when combining the last frames rotation with the current rotation, one of them will be considered as the "parent" rotation. From this link https://math.stackexchange.com/questions/2124361/quaternions-multiplication-order-to-rotate-unrotate it says q_w = q_p * q_c, where p is parent and c is child. So the one on the right is the child, it happens first, and the one on the left is the parent, it'll happen second.