4 hdaps-gl - draw a laptop based on the hdaps position
7 # Copyright: 2008-2009 Evgeni Golov <sargentd@die-welt.net>
10 # The model of the simple laptop is created by
11 # Patrick Kilian <petschge@petschge.de>
12 # and licensed under GPL-2
15 OpenGL
.ERROR_CHECKING
= False
16 from OpenGL
.GL
import *
17 from OpenGL
.GLU
import *
18 from OpenGL
.GLUT
import *
19 from time
import sleep
30 def drawLaptop( posX
=0, posY
=0, laptop
=(0, 0, 0), screen
=(0, 0, 1), trackpoint
=(1, 0, 0), N
=5 ):
31 glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT
);
34 glRotated (posX
/ 2.0, 0.0, 0.0, -1.0);
35 glRotated (posY
/ 2.0, 1.0, 0.0, 0.0);
37 glBegin (GL_QUADS
); # start drawing the laptop.
41 glVertex3d (N
*1.0, N
*0.0, N
*1.6);
42 glVertex3d (N
*(-1.0), N
*0.0, N
*1.6);
43 glVertex3d (N
*(-1.0), N
*0.0, N
*0.0);
44 glVertex3d (N
*1.0, N
*0.0, N
*0.0);
47 glColor3fv (trackpoint
);
48 glVertex3d (N
*0.01, N
*0.01, N
*0.78);
49 glVertex3d (N
*0.01, N
*0.01, N
*0.82);
50 glVertex3d (N
*(-0.01), N
*0.01, N
*0.82);
51 glVertex3d (N
*(-0.01), N
*0.01, N
*0.78);
54 glVertex3d (N
*1.0, N
*(-0.1), N
*(-0.1));
55 glVertex3d (N
*-1.0, N
*-0.1, N
*(-0.1));
56 glVertex3d (N
*-1.0, N
*-0.1, N
*1.6);
57 glVertex3d (N
*1.0, N
*-0.1, N
*1.6);
61 glVertex3d (N
*1.0, N
*0.0, N
*1.6);
62 glVertex3d (N
*-1.0, N
*0.0, N
*1.6);
63 glVertex3d (N
*-1.0, N
*-0.1, N
*1.6);
64 glVertex3d (N
*1.0, N
*-0.1, N
*1.6);
68 glVertex3d (N
*-1.0, N
*0.0, N
*1.6);
69 glVertex3d (N
*-1.0, N
*0.0, N
*0.0);
70 glVertex3d (N
*-1.0, N
*-0.1, N
*0.0);
71 glVertex3d (N
*-1.0, N
*-0.1, N
*1.6);
75 glVertex3d (N
*1.0, N
*0.0, N
*0.0);
76 glVertex3d (N
*1.0, N
*0.0, N
*1.6);
77 glVertex3d (N
*1.0, N
*-0.1, N
*1.6);
78 glVertex3d (N
*1.0, N
*-0.1, N
*0.0);
82 glVertex3d (N
*1.0, N
*1.6, N
*-0.1);
83 glVertex3d (N
*-1.0, N
*1.6, N
*-0.1);
84 glVertex3d (N
*-1.0, N
*1.6, N
*0.0);
85 glVertex3d (N
*1.0, N
*1.6, N
*0.0);
89 glVertex3d (N
*1.0, N
*1.6, N
*0.0);
90 glVertex3d (N
*-1.0, N
*1.6, N
*0.0);
91 glVertex3d (N
*-1.0, N
*0.0, N
*0.0);
92 glVertex3d (N
*1.0, N
*0.0, N
*0.0);
96 glVertex3d (N
*0.9, N
*1.5, N
*0.01);
97 glVertex3d (N
*-0.9, N
*1.5, N
*0.01);
98 glVertex3d (N
*-0.9, N
*0.1, N
*0.01);
99 glVertex3d (N
*0.9, N
*0.1, N
*0.01);
103 glVertex3d (N
*1.0, N
*-0.1, N
*-0.1);
104 glVertex3d (N
*-1.0, N
*-0.1, N
*-0.1);
105 glVertex3d (N
*-1.0, N
*1.6, N
*-0.1);
106 glVertex3d (N
*1.0, N
*1.6, N
*-0.1);
110 glVertex3d (N
*-1.0, N
*1.6, N
*0.0);
111 glVertex3d (N
*-1.0, N
*1.6, N
*-0.1);
112 glVertex3d (N
*-1.0, N
*-0.1, N
*-0.1);
113 glVertex3d (N
*-1.0, N
*-0.1, N
*0.0);
117 glVertex3d (N
*1.0, N
*1.6, N
*-0.1);
118 glVertex3d (N
*1.0, N
*1.6, N
*0.0);
119 glVertex3d (N
*1.0, N
*-0.1, N
*0.0);
120 glVertex3d (N
*1.0, N
*-0.1, N
*-0.1);
126 def forceUpdateWindow(arg
):
129 def updateWindow(update
=False):
131 posX
,posY
= readPosition()
132 if (abs(posX
- oldX
) > 5 or abs(posY
- oldY
) > 5):
134 if (abs(posX
) < 5 or abs(posY
) < 5):
139 drawLaptop(posX
-calibX
, posY
-calibY
)
146 calibX
,calibY
=readPosition(True)
148 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH
)
149 glutInitWindowSize (WIDTH
, HEIGHT
);
150 glutInitWindowPosition (0, 0);
151 glutCreateWindow('HDAPS-GL')
152 glutDisplayFunc(updateWindow
)
153 glutIdleFunc(updateWindow
)
154 glutVisibilityFunc(forceUpdateWindow
)
155 glClearColor (0.5, 0.5, 0.5, 0.0);
156 glClearDepth (1.0); # Enables Clearing Of The Depth Buffer
157 glDepthFunc (GL_LESS
); # The Type Of Depth Test To Do
158 glEnable (GL_DEPTH_TEST
); # Enables Depth Testing
159 glShadeModel (GL_SMOOTH
); # Enables Smooth Color Shading
161 glMatrixMode (GL_PROJECTION
);
163 gluPerspective (45.0, float(WIDTH
) / float(HEIGHT
), 0.25, 100.0);
165 glMatrixMode (GL_MODELVIEW
);
169 0,0,0, # center-of-view
172 #glTranslated (10.0, -0.5, -1.0);
177 if __name__
== "__main__":