Advertisement
Guest User

Untitled

a guest
Jun 9th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  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()
  6.         GL.glLoadIdentity()
  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.        ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement