Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # OpenGL approach:
- # cx, cy are the X and Y centers of the image.
- # dx, dy are the X and Y translation factors.
- # angle is the rotation about the Z axis.
- GL.glPushMatrix()
- GL.glLoadIdentity()
- # So we rotate about the center.
- GL.glTranslated(cx, cy, 0)
- GL.glRotated(-angle, 0, 0, 1)
- GL.glTranslated(dx - cx, dy - cy, 0)
- # With an X translate of 10 and angle of 45 degrees, printing out glGetDoublev(GL_MODELVIEW_MATRIX) gives:
- # [[ 0.70710677 -0.70710677 0. 0. ]
- # [ 0.70710677 0.70710677 0. 0. ]
- # [ 0. 0. 1. 0. ]
- # [ -98.96759033 248.92893982 0. 1. ]]
- # Numpy approach:
- cosTheta = numpy.cos(angle)
- sinTheta = numpy.sin(angle)
- transform = numpy.array(
- [[cosTheta, sinTheta, 0, dx],
- [-sinTheta, cosTheta, 0, dy],
- [0, 0, 1, dz],
- [0, 0, 0, 1]])
- # With those same transformation parameters, printing out transform gives:
- # [[ 0.70710678 0.70710678 0. 10. ]
- # [ -0.70710678 0.70710678 0. 0. ]
- # [ 0. 0. 1. 0. ]
- # [ 0. 0. 0. 1. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement