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
self.recordMouse(event)
x = event.pos().x()
y = event.pos().y()
pixels = 5
buffer_size = 512
viewport = glGetIntegerv(GL_VIEWPORT)
# 2. selection logic
glSelectBuffer(buffer_size)
glRenderMode(GL_SELECT)
glInitNames()
glMatrixMode(GL_PROJECTION)
previousviewmatrix = glGetDoublev(GL_PROJECTION_MATRIX)
glLoadIdentity()
gluPickMatrix( x, viewport[3]-y, pixels, pixels, viewport )
glMultMatrixd(previousviewmatrix)
glMatrixMode(GL_MODELVIEW)
self.drawScene( self )
glFlush()
glMatrixMode(GL_PROJECTION)
glLoadMatrixd(previousviewmatrix)
self.buffer = glRenderMode(GL_RENDER)
# 3. update graphics
self.updateGL()
# 4. process selction buffer if control is pressed
return self.processBuffer()
where processBuffer is:
def processBuffer(self):
print "--------- pick3d ----------"
print " - nhits =", len( self.buffer )
if( len(self.buffer) == 0 ): print "hit nothing"
else:
min = self.buffer[0][0]
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]
self.selected.remove(names[i])
else:
self.selected.append(names[i])
print " - selectedObjects: ", self.selected
return 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
sweep selection?
Thanks,
Amy
|