Sage_Interactive_3D_Viewer

434 days ago by PatrickHammer

####################################################################### #INTERACTIVE 3D viewer for Sage by Patrick Hammer #based on pyprocessing(which is based on pyglet) #define draw_func(clicked,ViewerDirection,ViewerPos,ViewerRotation) #below and call "run()" once. At first set your correct paths: pth1='/usr/local/pyglet-1.1.4' pth2='/usr/local/pyprocessing-0.1.2.3' ####################################################################### import sys if not pth1 in sys.path: sys.path.append(pth1) from pyglet import * if not pth2 in sys.path: sys.path.append(pth2) from pyprocessing import * def setup(): size(640,480) rotY=0; rotX=0; pX=0; pY=0; pZ=0; clicked=false; def draw(): global rotY,rotX,pX,pY,pZ,clicked,draw_func; speed=10; scroll=-0.0002 noStroke(); background(233,233,233); translate(width/2,height*3/5,(height/2)/math.tan(pi/6)) rotX+=scroll*(height/2-mouse.y); rotY-=scroll*(width/2-mouse.x); rotateX(-rotX); rotateY(-rotY) if key.pressed: pX+=speed*math.sin(rotY); pY+=speed*math.cos(rotY); pZ+=speed*math.sin(rotX) if not mouse.pressed: clicked=false ViewerDirection=[math.sin(rotY),math.cos(rotY),math.sin(rotX)] #useful for world interaction if clicked==false and mouse.pressed: clicked=true translate(pX,-pZ,pY); directionalLight(255,255,255,-0.5,1,0); ambientLight(51,102,126) pushMatrix(); draw_func(clicked,ViewerDirection,[pX,pY,pZ],[rotX,rotY]); popMatrix() ####################################################################### 
       
def draw_func(clicked,ViewerDirection,ViewerPos,ViewerRotation): box(10000,0,10000) run()