-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSelect.py
More file actions
69 lines (62 loc) · 1.91 KB
/
Select.py
File metadata and controls
69 lines (62 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Class for handling selection
from OpenGL.GL import *
from OpenGL.GLU import *
selectables = []
class Selectable:
ID = 0
def __init__( self ):
self.id = Selectable.ID
self.selected = False
Selectable.ID += 1
selectables.append( self )
def setSelected( self ):
self.selected = True
def clearSelected( self ):
self.selected = False
def closestHit( buffer ):
closest = -1
if ( len(buffer) == 1):
closest = buffer[0][2][0]
elif ( len( buffer ) > 1 ):
closestDist = buffer[0][0]
closest = buffer[0][2][0]
for hit in buffer[1:]:
testDist = hit[0]
if ( testDist < closestDist ):
closest = hit[2][0]
if ( closest > -1 ):
return selectables[ closest ]
else:
return None
# todo
# the camera should have the following knowledge
# 1. viewpoint location
# 2. target location
# 3. up vector (right now implied as <0 1 0>
# 4. Screen size
# 5. Near and Far planes
##def select( scene, x, y, camera ):
## # Given a screen (x, y) coordinate, a scene to select from and a camera
## # returns a scene-defined id of the selected node
## global selected, update
## glMatrixMode( GL_PROJECTION )
## glPushMatrix()
## glLoadIdentity()
## viewport = glGetIntegerv(GL_VIEWPORT )
## gluPickMatrix( x, camera.viewport[3] - y, 3, 3, camera.viewport )
## gluPerspective(45, 1.0*camera.screenWidth/camera.screenHeight, camera.near, camera.far)
## glMatrixMode( GL_MODELVIEW )
## glLoadIdentity()
## camera.setGLView()
##
## glSelectBuffer( 512L )
## glRenderMode( GL_SELECT )
##
## glInitNames()
## glPushName( 0 )
## scene.drawGL( True )
## hits = list(glRenderMode( GL_RENDER ) )
## glMatrixMode( GL_PROJECTION )
## glPopMatrix()
## glMatrixMode( GL_MODELVIEW )
## return closestHit( hits )