To main page | 3dengine.org

Rotate around Arbitrary axis (vector)


PyOpenGL math to do rotation manually:
from numpy import matrix
from math import cos,sin
def rot_arb(an, x,y,z):
    c=cos(an)
    s=sin(an)
    t=1-c
    modelview = (modelview * np.mat([
        t*x*x+c,    t*x*y-s*z,  t*x*z+s*y,  0,
        t*x*y+s*z,  t*y*y+c,    t*y*z-s*x,  0,
        t*x*z-s*y,  t*y*z+s*x,  t*z*z+c,    0,
        0,  0,  0,  1,
    ]).reshape(4,4))
modelview = Modelview matrix (upper 3x3 of modelview matrix is rotation matrix)


Deg/Rad

Remember that math.cos/sin take radians, while OpenGL (and people generally) think(s) in degrees, see:

Degrees-to-radians
Radians-to-degrees


See also

Right, up, back vectors in modelview matrix