1 / 20

Multiple Selection

Multiple Selection. By JerryDean Smith Chad Adams Karl Mullner. Creating Rectangle Class. The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special functions that will be used later for the selection of the entities

purity
Download Presentation

Multiple Selection

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Multiple Selection By JerryDean Smith Chad Adams Karl Mullner

  2. Creating Rectangle Class • The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special functions that will be used later for the selection of the entities • NOTE: The selection rectangle is always on top of all other objects in the render window

  3. Selection Rectangle Methods • Methods inside of Selection Rectangle Class • def __init__(self,name): • defdrawBox(self, left, top, right, bottom):

  4. initialization • The selection rectangle initialization method has to setup the Render Queue Group and how the rectangle will be viewed • ogre.ManualObject.__init__(self,name) • self.setRenderQueueGroup(ogre.RenderQueueGroupID.RENDER_QUEUE_OVERLAY) • self.setUseIdentityProjection(True) • self.setUseIdentityView(True) • self.setQueryFlags(0)

  5. DrawBox • The drawBox does a little more than what it says it has to convert the mouse position to be able to hand the center of screen being 0,0 where normally it would be .5,.5 • left = left * 2 - 1 • right = right * 2 - 1 • top = 1 - top * 2 • bottom = 1 - bottom * 2

  6. DrawBox continued.. • Then it clears the old rectangle and shows the box. To do this simply type self.clear() • Begin sets up the material and type of shape drawn self.begin("", ogre.RenderOperation.OT_LINE_STRIP) It is important to remember that you need five points when drawing a box you must connect the box back to the beginning • self.position(left, top, -1) • self.position(right, top, -1) • self.position(right, bottom, -1) • self.position(left, bottom, -1) • self.position(left, top, -1) • self.end()

  7. DrawBox continued.. • In the intermediate tutorial we were told to put this into the the end of our drawBox • ## set the bounding box of the object to be infinite, so that the camera will • ## always be inside of it • box = ogre.AxisAlignedBox() • box.setInfinite() • self.setBoundingBox(box) • pass

  8. PlaneQueryListenerClass This is a listener for after the drawBox has completed. This is what puts the selected entities into a list and shows the bounding box of the boats

  9. PlaneQueryListenerMethods: • def__init__ ( self): • ogre.SceneQueryListener.__init__ ( self ) • self.selectObjects = [] • defqueryResult ( self, firstMovable): • firstMovable.getParentSceneNode().showBoundingBox(True) • self.selectObjects.append(firstMovable) • return True • defdeselectObjects(self): • for movableObject in self.selectObjects: • movableObject.getParentSceneNode().showBoundingBox(False) • self.selectObjects = []

  10. Selection Manager Class • This class has the most code crammed into it so be careful when implementing the class basically you will be adding a method called boxSelect and modifying the tick method and some variables in the initialization of the class

  11. initialization • We added these variables to make our lives a lot easier • self.box= SelectionRectangle("Box") #creates the box • self.engine.gfx.sceneManager.getRootSceneNode().createChildSceneNode().attachObject(self.box) #this to get the positions of all the points inside of the rectangle • self.mVolQuery = self.engine.gfx.sceneManager.createPlaneBoundedVolumeQuery(ogre.PlaneBoundedVolumeList())

  12. Initialization continued.. #don’t have to do this but it makes it a lot easier to access the mouse coordinates • self.left = 0.0 • self.right = 0.0 • self.top = 0.0 • self.bottom = 0.0 #toggle for the mouse selection • self.mouseDown = None #gives access to the listener • self.querylistener = PlaneQueryListener()

  13. boxSelect topLeft = self.engine.gfx.camera.getCameraToViewportRay(self.left, self.top) do this for all the topRight, bottomLeft and bottomRight # this is to get the volume of the planes vol = ogre.PlaneBoundedVolume()

  14. boxSelect continued.. • Do this function for all five points it will be projected into the water plane to the boat selection • p = ogre.Plane( topLeft.getPoint(3), • topRight.getPoint(3), • bottomRight.getPoint(3))

  15. boxSelect continued.. • vol.planes.append(p) ## front plane • vol.planes.append(p2) ## left plane • vol.planes.append(p3) ## bottom plane • vol.planes.append(p4) ## top plane • vol.planes.append(p5) ## right plane • volList = ogre.PlaneBoundedVolumeList() • volList.append(vol) • self.mVolQuery.setVolumes(volList) • self.mVolQuery.execute(self.querylistener) • resultObjects = self.querylistener.selectObjects

  16. boxSelect continued.. • if resultObjects: • for name, ent in self.state.entities.iteritems(): • for queryResult in resultObjects: • if queryResult.name == ent.gfxNode.name: • self.state.selectedEntities.append(ent) • print "Appended"

  17. if currMouse.buttonDown(OIS.MB_Left) and not self.mouseDown: • self.bb(isOn = False) • self.state.selectedEntities = [] • self.left = float(currMouse.X.abs)/currMouse.width • self.top = float(currMouse.Y.abs)/currMouse.height • self.right = float(currMouse.X.abs)/currMouse.width • self.bottom = float(currMouse.Y.abs)/currMouse.height

  18. if currMouse.buttonDown(OIS.MB_Left) and self.mouseDown: • self.right = float(currMouse.X.abs)/currMouse.width • self.bottom = float(currMouse.Y.abs)/currMouse.height • self.box.drawBox(self.left,self.top,self.right,self.bottom) • self.box.setVisible(True) • print self.left,self.right,self.top,self.bottom • print "box drawn"

  19. if self.mouseDown and not currMouse.buttonDown(OIS.MB_Left): • if (self.left > self.right): • self.left, self.right = self.right, self.left • if (self.top > self.bottom): • self.top, self.bottom = self.bottom, self.top • self.box.setVisible(False) • if ((self.right - self.left) * (self.bottom - self.top) < 0.0001): • self.castRay(currMouse) • else: • self.boxSelect()

  20. if ((currMouse.buttonDown(OIS.MB_Right)) and • (self.toggleSpawn) and not (self.mouseRdown)): • self.spawnRay(currMouse) • self.mouseDown = currMouse.buttonDown(OIS.MB_Left) • self.mouseRdown = currMouse.buttonDown(OIS.MB_Right)

More Related