Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!

# Untitled

By: a guest on Jun 9th, 2011  |  syntax: Python  |  size: 1.37 KB  |  views: 66  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. # OpenGL approach:
2.         # cx, cy are the X and Y centers of the image.
3.         # dx, dy are the X and Y translation factors.
4.         # angle is the rotation about the Z axis.
5.         GL.glPushMatrix()
7.
8.         # So we rotate about the center.
9.         GL.glTranslated(cx, cy, 0)
10.
11.         GL.glRotated(-angle, 0, 0, 1)
12.         GL.glTranslated(dx - cx, dy - cy, 0)
13. # With an X translate of 10 and angle of 45 degrees, printing out glGetDoublev(GL_MODELVIEW_MATRIX) gives:
14. # [[   0.70710677   -0.70710677    0.            0.        ]
15. #  [   0.70710677    0.70710677    0.            0.        ]
16. #  [   0.            0.            1.            0.        ]
17. #  [ -98.96759033  248.92893982    0.            1.        ]]
18.
19.
20. # Numpy approach:
21.             cosTheta = numpy.cos(angle)
22.             sinTheta = numpy.sin(angle)
23.             transform = numpy.array(
24.                     [[cosTheta, sinTheta, 0, dx],
25.                      [-sinTheta, cosTheta, 0, dy],
26.                      [0, 0, 1, dz],
27.                      [0, 0, 0, 1]])
28. # With those same transformation parameters, printing out transform gives:
29. # [[  0.70710678   0.70710678   0.          10.        ]
30. #  [ -0.70710678   0.70710678   0.           0.        ]
31. #  [  0.           0.           1.           0.        ]
32. #  [  0.           0.           0.           1.        ]]
clone this paste RAW Paste Data
Top