• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
21%
SHARE
TWEET

# Untitled

a guest Jun 9th, 2011 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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.        ]]
RAW Paste Data
Top