Commits

Richard Jones committed 68c817c

more useful shape

Comments (0)

Files changed (1)

     m = math.sqrt(x ** 2 + y ** 2 + z ** 2)
     return [x/m, y/m, z/m]
 
-def render_cube():
+def render_cube(w=1, h=1, d=1):
+    hw = w/2.
+    hh = h/2.
+    hd = d/2.
     glBegin(GL_TRIANGLES)
     glNormal3f(+1.0, 0.0, 0.0)
-    glVertex3f(+1.0, +1.0, +1.0); glVertex3f(+1.0, -1.0, +1.0); glVertex3f(+1.0, -1.0, -1.0)
-    glVertex3f(+1.0, +1.0, +1.0); glVertex3f(+1.0, -1.0, -1.0); glVertex3f(+1.0, +1.0, -1.0); 
+    glVertex3f(+hw, +hh, +hd)
+    glVertex3f(+hw, -hh, +hd)
+    glVertex3f(+hw, -hh, -hd)
+    glVertex3f(+hw, +hh, +hd)
+    glVertex3f(+hw, -hh, -hd)
+    glVertex3f(+hw, +hh, -hd)
+    
 
     glNormal3f(0.0, +1.0, 0.0)
-    glVertex3f(+1.0, +1.0, +1.0); glVertex3f(-1.0, +1.0, +1.0); glVertex3f(-1.0, +1.0, -1.0)
-    glVertex3f(+1.0, +1.0, +1.0); glVertex3f(-1.0, +1.0, -1.0); glVertex3f(+1.0, +1.0, -1.0); 
+    glVertex3f(+hw, +hh, +hd)
+    glVertex3f(-hw, +hh, +hd)
+    glVertex3f(-hw, +hh, -hd)
+    glVertex3f(+hw, +hh, +hd)
+    glVertex3f(-hw, +hh, -hd)
+    glVertex3f(+hw, +hh, -hd)
+    
 
     glNormal3f(0.0, 0.0, +1.0)
-    glVertex3f(+1.0, +1.0, +1.0); glVertex3f(-1.0, +1.0, +1.0); glVertex3f(-1.0, -1.0, +1.0)
-    glVertex3f(+1.0, +1.0, +1.0); glVertex3f(-1.0, -1.0, +1.0); glVertex3f(+1.0, -1.0, +1.0); 
+    glVertex3f(+hw, +hh, +hd)
+    glVertex3f(-hw, +hh, +hd)
+    glVertex3f(-hw, -hh, +hd)
+    glVertex3f(+hw, +hh, +hd)
+    glVertex3f(-hw, -hh, +hd)
+    glVertex3f(+hw, -hh, +hd)
+    
 
     glNormal3f(-1.0, 0.0, 0.0)
-    glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, +1.0); glVertex3f(-1.0, +1.0, +1.0); 
-    glVertex3f(-1.0, +1.0, -1.0); glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, +1.0, +1.0);  
+    glVertex3f(-hw, -hh, -hd)
+    glVertex3f(-hw, -hh, +hd)
+    glVertex3f(-hw, +hh, +hd)
+    glVertex3f(-hw, +hh, -hd)
+    glVertex3f(-hw, -hh, -hd)
+    glVertex3f(-hw, +hh, +hd)
+     
 
     glNormal3f(0.0, -1.0, 0.0)
-    glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, +1.0); glVertex3f(+1.0, -1.0, +1.0);
-    glVertex3f(+1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, -1.0); glVertex3f(+1.0, -1.0, +1.0);
+    glVertex3f(-hw, -hh, -hd)
+    glVertex3f(-hw, -hh, +hd)
+    glVertex3f(+hw, -hh, +hd);
+    glVertex3f(+hw, -hh, -hd)
+    glVertex3f(-hw, -hh, -hd)
+    glVertex3f(+hw, -hh, +hd);
 
     glNormal3f(0.0, 0.0, -1.0)
-    glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, +1.0, -1.0); glVertex3f(+1.0, +1.0, -1.0);
-    glVertex3f(+1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, -1.0); glVertex3f(+1.0, +1.0, -1.0);
+    glVertex3f(-hw, -hh, -hd)
+    glVertex3f(-hw, +hh, -hd)
+    glVertex3f(+hw, +hh, -hd);
+    glVertex3f(+hw, -hh, -hd)
+    glVertex3f(-hw, -hh, -hd)
+    glVertex3f(+hw, +hh, -hd);
     glEnd()