Friday, 26 July 2013

OpenGL ES: How to rotate around a specific point instead of origin?

If you want to rotate around a point (x0, y0, z0), assuming

matrix-vector multiplication order is vector * matrix,

your current modelview matrix is M1,

the rotation matrix is MR,

translation matrix from (0, 0, 0) to (x0, y0, z0) is T(x0, y0, z0),

After rotation, the modelview matrix should be

M1*T(-x0, -y0, -z0) * MR * T(x0, y0, z0)

Note if (x0, y0, z0) is in world coordinates, it needs to be first transformed to eye coordinates by

(x0, y0, z0) * M1


No comments:

Post a Comment