Multiple selection
Download
1 / 20

Multiple Selection - PowerPoint PPT Presentation


  • 99 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Multiple Selection' - purity


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Multiple selection

Multiple Selection

By JerryDean Smith

Chad Adams

Karl Mullner


Creating rectangle class
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


Selection rectangle methods
Selection Rectangle Methods

  • Methods inside of Selection Rectangle Class

  • def __init__(self,name):

  • defdrawBox(self, left, top, right, bottom):


Initialization
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)


Drawbox
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


Drawbox continued
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()


Drawbox continued1
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


Planequerylistener class
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


Planequerylistener methods
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 = []


Selection manager class
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


Initialization1
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())


Initialization continued
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()


Boxselect
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()


Boxselect continued
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))


Boxselect continued1
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


Boxselect continued2
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"


  • 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


  • 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"


  • 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()


  • 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)


ad