Has anyone implemented OpenGL Sweep Selection?? If so, can you give me any
pointers? I'm relatively new to Python, but am already very comfortable
with it. I'm very new to OpenGL, and have looked at tutorials, but to no
avail, I still don't have sweep selection implemented properly. Selection
of one object works beautifully. Here's the code that I implemented to do
single object selection:
def pick3d( self, event ):
# 1. initialization
x = event.pos().x()
y = event.pos().y()
pixels = 5
buffer_size = 512
viewport = glGetIntegerv(GL_VIEWPORT)
# 2. selection logic
previousviewmatrix = glGetDoublev(GL_PROJECTION_MATRIX)
gluPickMatrix( x, viewport-y, pixels, pixels, viewport )
self.drawScene( self )
self.buffer = glRenderMode(GL_RENDER)
# 3. update graphics
# 4. process selction buffer if control is pressed
where processBuffer is:
print "--------- pick3d ----------"
print " - nhits =", len( self.buffer )
if( len(self.buffer) == 0 ): print "hit nothing"
min = self.buffer
for record in self.buffer:
minDepth, maxDepth, names = record
# add all hit objects to selectedObjects
for i in range(len(names)):
if(self.selected.count(names[i]) == 1):
print " - unselected: ", names[i]
print " - selectedObjects: ", self.selected
The reason processBuffer is defined in this way is b/c I'm only working in
2D right now. I know that to use this for 3D, I'd have to check the depth.
Currently, for multiple object selection, I'm requiring the user to do
ctrl+leftMouse. As long as ctrl+leftMouse is done, I call pick3d which in
turn will add the selectedObject to my list variable.
I know this is not the best way to do this, but it works for my purposes.
Can someone please tell me how I could 'edit' this to make it work for a