import math from OpenGL.GL import * from OpenGL.GLUT import * from Vector import * def drawStrokeString(text, position=None, font=GLUT_STROKE_ROMAN): if position: glTranslatef(position[0], position[1], position[2]) for c in text: glutStrokeCharacter(font, ord(c)) def drawBitmapString(text, position=None, font=GLUT_BITMAP_TIMES_ROMAN_24): if position: if len(position) > 2: glRasterPos3fv(position) else: glRasterPos2fv(position) for c in text: glutBitmapCharacter(font, ord(c)) def drawAxes(): X_Axis.drawLine(); drawBitmapString("X",X_Axis,GLUT_BITMAP_TIMES_ROMAN_24); Y_Axis.drawLine(); drawBitmapString("Y",Y_Axis,GLUT_BITMAP_TIMES_ROMAN_24); Z_Axis.drawLine(); drawBitmapString("Z",Z_Axis,GLUT_BITMAP_TIMES_ROMAN_24); def degreesToRadians(angle): return angle * math.pi / 180.0 def radiansToDegrees(angle): return angle * 180.0 / math.pi def computeNormal(v0, v1, v2): A = [ v2[0] - v1[0], v2[1] - v1[1], v2[2] - v1[2] ] B = [ v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2] ] product = [ A[1] * B[2] - A[2] * B[1], A[2] * B[0] - A[0] * B[2], A[0] * B[1] - A[1] * B[0] ] length = math.sqrt(product[0]*product[0] + product[1]*product[1] + product[2]*product[2]) if (length == 0): # If there's a problem, return Y_Axis # return an arbitrary result else: return Vector([ product[0]/length, product[1]/length, product[2]/length ])