5
votes

In my 3D application I store object's position in a vector and it's rotation around the origin in a quaternion. I need to rotate the object around a vector with an arbitrary origin. I tried converting the position - vectorOrigin and the rotation into a matrix, rotating the matrix and then extracting the position and rotation as a vector and a quaternion from the resulting matrix. The position comes up ok, but the rotation remains constant (the object rotates around the given vector but it always faces in the same direction).

Is my method wrong or do I have a bug?

2

2 Answers

9
votes

I'm not sure why do you expect the rotation to change. You have programmatic "creatures" representing the origin point, the destination point, and a rotation. Computing the destination point based on the other two "creatures" shouldn't affect them.

What about the usual approach? If you need to rotate the position (x, y, z) around the point (a, b, c), first translate the position so that the rotation will be around the origin: use (x-a, y-b, z-c) as the position, rotate around the origin as usual to get the new translated position (x'-a, y'-b, z'-c), and translate back and get your new position (x', y', z').

2
votes

I'm not familiar with quaternions, and maybe this is totally offtopic, but you can't rotate a 3d object around a point, the axis of rotation must be a line.