Commit 4e40b06b authored by lode_leroy's avatar lode_leroy

added Simulation mode



git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@57 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 3b367f98
...@@ -13,7 +13,7 @@ from OpenGL.GL import * ...@@ -13,7 +13,7 @@ from OpenGL.GL import *
model = TestModel() model = TestModel()
zbuffer = ZBuffer(-5,+5,30, -5,+5,30, 1,5) zbuffer = ZBuffer(-5,+5,150, -5,+5,150, 1,5)
#zbuffer.add_wave() #zbuffer.add_wave()
...@@ -21,7 +21,7 @@ zbuffer = ZBuffer(-5,+5,30, -5,+5,30, 1,5) ...@@ -21,7 +21,7 @@ zbuffer = ZBuffer(-5,+5,30, -5,+5,30, 1,5)
c = SphericalCutter(0.25) c = SphericalCutter(0.25)
p = Point(-5,-5,1) p = Point(-5,-5,2)
c.moveto(p) c.moveto(p)
zbuffer.add_triangles(model.triangles()) zbuffer.add_triangles(model.triangles())
......
...@@ -113,6 +113,9 @@ class CylindricalCutter(BaseCutter): ...@@ -113,6 +113,9 @@ class CylindricalCutter(BaseCutter):
return (None,INFINITE) return (None,INFINITE)
return (cl,l) return (cl,l)
def intersect_plane(self, direction, triangle):
return self.intersect_circle_plane(direction, triangle)
def intersect(self, direction, triangle): def intersect(self, direction, triangle):
(cl_t,d_t) = self.intersect_circle_triangle(direction, triangle) (cl_t,d_t) = self.intersect_circle_triangle(direction, triangle)
d = INFINITE d = INFINITE
......
...@@ -115,6 +115,9 @@ class SphericalCutter(BaseCutter): ...@@ -115,6 +115,9 @@ class SphericalCutter(BaseCutter):
return (None,INFINITE) return (None,INFINITE)
return (cl,l) return (cl,l)
def intersect_point(self, direction, point):
return self.intersect_sphere_point(direction, point)
def intersect(self, direction, triangle): def intersect(self, direction, triangle):
(cl_t,d_t) = self.intersect_sphere_triangle(direction, triangle) (cl_t,d_t) = self.intersect_sphere_triangle(direction, triangle)
d = INFINITE d = INFINITE
......
...@@ -12,6 +12,7 @@ GLUT_WHEEL_DOWN=Constant('GLUT_WHEEL_DOWN',4) ...@@ -12,6 +12,7 @@ GLUT_WHEEL_DOWN=Constant('GLUT_WHEEL_DOWN',4)
from pycam.Geometry.utils import * from pycam.Geometry.utils import *
_DrawCurrentSceneFunc = None _DrawCurrentSceneFunc = None
_KeyHandlerFunc = None
# Some api in the chain is translating the keystrokes to this octal string # Some api in the chain is translating the keystrokes to this octal string
# so instead of saying: ESCAPE = 27, we use the following. # so instead of saying: ESCAPE = 27, we use the following.
...@@ -31,7 +32,8 @@ zdist = -8.0 ...@@ -31,7 +32,8 @@ zdist = -8.0
texture_num = 2 texture_num = 2
object = 0 object = 0
light = 0 light = 1
shade_model = GL_FLAT
polygon_mode = GL_FILL polygon_mode = GL_FILL
width = 320 width = 320
height = 200 height = 200
...@@ -47,7 +49,8 @@ def InitGL(Width, Height): # We call this right after our OpenGL window is cr ...@@ -47,7 +49,8 @@ def InitGL(Width, Height): # We call this right after our OpenGL window is cr
glDepthFunc(GL_LESS) # The Type Of Depth Test To Do glDepthFunc(GL_LESS) # The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST) # Enables Depth Testing glEnable(GL_DEPTH_TEST) # Enables Depth Testing
# glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading # glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading
glShadeModel(GL_FLAT) # Enables Flat Color Shading # glShadeModel(GL_FLAT) # Enables Flat Color Shading
glShadeModel(shade_model)
glMatrixMode(GL_PROJECTION) glMatrixMode(GL_PROJECTION)
glLoadIdentity() # Reset The Projection Matrix glLoadIdentity() # Reset The Projection Matrix
...@@ -104,8 +107,10 @@ def DrawGLScene(): ...@@ -104,8 +107,10 @@ def DrawGLScene():
# The function called whenever a key is pressed # The function called whenever a key is pressed
def keyPressed(key, x, y): def keyPressed(key, x, y):
global light, polygon_mode global light, polygon_mode, shade_model
global xrot, yrot, zrot global xrot, yrot, zrot
global _KeyHandlerFunc
key = string.upper(key) key = string.upper(key)
if key == ESCAPE or key=='Q': if key == ESCAPE or key=='Q':
# If escape is pressed, kill everything. # If escape is pressed, kill everything.
...@@ -114,6 +119,10 @@ def keyPressed(key, x, y): ...@@ -114,6 +119,10 @@ def keyPressed(key, x, y):
light = not light light = not light
elif key == '=': elif key == '=':
print "rot=<%g,%g,%g>" % (xrot,yrot,zrot) print "rot=<%g,%g,%g>" % (xrot,yrot,zrot)
elif key == 'I':
xrot = 110
yrot = 180
zrot = 250
elif key == 'T': # top elif key == 'T': # top
xrot=0 xrot=0
yrot=0 yrot=0
...@@ -131,11 +140,19 @@ def keyPressed(key, x, y): ...@@ -131,11 +140,19 @@ def keyPressed(key, x, y):
yrot=0 yrot=0
zrot=+90 zrot=+90
elif key == 'M': elif key == 'M':
if shade_model == GL_SMOOTH:
shade_model = GL_FLAT
else:
shade_model = GL_SMOOTH
glShadeModel(shade_model)
elif key == 'P':
if polygon_mode == GL_FILL: if polygon_mode == GL_FILL:
polygon_mode = GL_LINE polygon_mode = GL_LINE
else: else:
polygon_mode = GL_FILL polygon_mode = GL_FILL
glPolygonMode(GL_FRONT_AND_BACK, polygon_mode) glPolygonMode(GL_FRONT_AND_BACK, polygon_mode)
elif _KeyHandlerFunc:
_KeyHandlerFunc(key, x, y)
class mouseState: class mouseState:
button = None button = None
...@@ -188,11 +205,15 @@ def mouseMoved(x, y): ...@@ -188,11 +205,15 @@ def mouseMoved(x, y):
mouseState.x=x mouseState.x=x
mouseState.y=y mouseState.y=y
def Visualization(title, drawScene=DrawGLScene, width=320, height=200): def Visualization(title, drawScene=DrawGLScene, width=320, height=200, handleKey=None):
global window, _DrawCurrentSceneFunc global window, _DrawCurrentSceneFunc, _KeyHandlerFunc
glutInit(sys.argv) glutInit(sys.argv)
_DrawCurrentSceneFunc = drawScene _DrawCurrentSceneFunc = drawScene
if handleKey:
_KeyHandlerFunc = handleKey
# Select type of Display mode: # Select type of Display mode:
# Double buffer # Double buffer
# RGBA color # RGBA color
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment