20
MULTIPLE SELECTION By JerryDean Smith Chad Adams Karl Mullner

By JerryDean Smith Chad Adams Karl Mullner. The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

Embed Size (px)

DESCRIPTION

 Methods inside of Selection Rectangle Class  def __init__(self,name):  def drawBox(self, left, top, right, bottom):

Citation preview

Page 1: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

MULTIPLE SELECTION

By JerryDean SmithChad AdamsKarl Mullner

Page 2: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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

Page 3: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

Selection Rectangle Methods

Methods inside of Selection Rectangle Class

def __init__(self,name): def drawBox(self, left, top, right, bottom):

Page 4: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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)

Page 5: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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

Page 6: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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

Page 7: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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

Page 8: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

PlaneQueryListener Class

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

Page 9: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

PlaneQueryListener Methods:

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

Page 10: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

Selection Manager ClassThis 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

Page 11: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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

Page 12: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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

Page 13: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

boxSelecttopLeft = 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 planesvol = ogre.PlaneBoundedVolume()

Page 14: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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

Page 15: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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

Page 16: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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"

Page 17: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

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

Page 18: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

Selection manager contiued

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"

Page 19: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

Selection manager contiued

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

Page 20: By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special

Selection manager contiued

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)