Download presentation
Presentation is loading. Please wait.
Published byKelley Lambert Modified over 9 years ago
1
By JerryDean Smith Chad Adams Karl Mullner
2
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
Methods inside of Selection Rectangle Class def __init__(self,name): def drawBox(self, left, top, right, bottom):
4
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.RenderQueue GroupID.RENDER_QUEUE_OVERLAY) self.setUseIdentityProjection(True) self.setUseIdentityView(True) self.setQueryFlags(0)
5
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
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
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
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
def __init__ ( self): ogre.SceneQueryListener.__init__ ( self ) self.selectObjects = [] def queryResult ( self, firstMovable): firstMovable.getParentSceneNode().showBoundingBox(True) self.selectObjects.append(firstMovable) return True def deselectObjects(self): for movableObject in self.selectObjects: movableObject.getParentSceneNode().showBoundingBox(False) self.selectObjects = []
10
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
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.createPlaneBounded VolumeQuery(ogre.PlaneBoundedVolumeList())
12
#don’t have to do this but we wanted to attach the mouse to self so that we could access the mouse coordinates anywhere 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
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
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
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
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.bott om) 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)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.