1 #! /usr/local/bin/python
3 # zrgb (Requires Z buffer.)
5 # This program demostrates zbuffering 3 intersecting RGB polygons while
6 # in doublebuffer mode where, movement of the mouse with the LEFTMOUSE
7 # button depressed will, rotate the 3 polygons. This is done by compound
8 # rotations allowing continuous screen-oriented rotations.
10 # Press the "Esc" key to exit.
17 idmat
=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
21 # old and new mouse position
30 objmat
=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
43 # exit when key is going up, not down
44 # this avoids the scenario where a window
45 # underneath this program's window
46 # would otherwise "eat up" the up-
47 # event of the Esc key being released
54 elif dev
== LEFTMOUSE
:
65 objmat
= update_scene(objmat
,mx
,my
,omx
,omy
,mode
)
71 objmat
= update_scene(objmat
,mx
,my
,omx
,omy
,mode
)
79 w
= winopen('Zbuffered RGB')
85 lsetdepth(0x0, 0x7FFFFF)
92 def update_scene (mat
, mx
, my
, omx
, omy
, mode
) :
95 mat
= orient(mat
, mx
, my
, omx
, omy
)
99 def orient (mat
, mx
, my
, omx
, omy
) :
105 if mx
- omx
: rot (float (mx
- omx
), 'y')
106 if omy
- my
: rot (float (omy
- my
), 'x')
115 def draw_scene (mat
) :
116 RGBcolor(40, 100, 200)
120 perspective(400, 1.25, 30.0, 60.0)
121 translate(0.0, 0.0, -40.0)
124 # skews original view to show all polygons
131 polygon1
= [(-10.0,-10.0,0.0),(10.0,-10.0,0.0),(-10.0,10.0,0.0)]
133 polygon2
= [(0.0,-10.0,-10.0),(0.0,-10.0,10.0),(0.0,5.0,-10.0)]
135 polygon3
= [(-10.0,6.0,4.0),(-10.0,3.0,4.0),(4.0,-9.0,-10.0),(4.0,-6.0,-10.0)]