Hi all!
I came across this awesome tutorial about collisions: Panda3d Collisions made simple
I added a CollisionHandlerEvent like in step5/step6 of the tutorial.
self.colHandler = CollisionHandlerEvent()
id = randrange(1000)
self.pickerNode = CollisionNode('mouseray')
self.pickerNP = self.camera.attachNewNode(self.pickerNode)
self.pickerRay = CollisionRay()
self.pickerNode.addSolid(self.pickerRay)
self.pickerNode.setFromCollideMask(BitMask32.bit(0))
base.cTrav.addCollider(self.pickerNP, self.colHandler)
self.colHandler.addInPattern('%fn-into-%in')
self.colHandler.addOutPattern('%fn-out-%in')
self.accept('mouseray-into-collider' ,self.collideEventIn)
self.accept('mouseray-out-collider', self.collideEventOut)
###### collider code
self.collider = self.model.attachNewNode(CollisionNode('collider'))
self.collider.node().addSolid(CollisionSphere(0, 0, 0, 1))
######
def updateMouseRay(self):
if self.mouseWatcher.hasMouse():
mpos = self.mouseWatcher.getMouse()
self.pickerRay.setFromLens(self.camera.node(), mpos.getX(), mpos.getY())
self.pickerNode.addSolid(self.pickerRay)
It works well if I only use one camera in the scene. But my program supports multiple viewports into the same world (splitscreen). So basically, updateMouseRay is called for each step for each viewport but only if the mouse is within the viewportās display region.
If I do not change the collision nodeās name for each new viewport, it works for one part of the splitscreen but as one would expect, not for the other one (depending on which one you move the mouse first). As soon as the mouse comes across the other viewport it infinitely throws the following error and finally crashes. What does this error message tell me?
:mathutil(warning): BoundingLine::contains_geometric() called with BoundingLine
Assuming that it would surely be a problem to have multiple collision nodes with the same name, the next idea was to try to uniquely name those by adding an id in the end for each camera (e.g. self.pickerNode = CollisionNode(āmouseray%dā%id) and accordingly for the accept methods). But this throws the following error as soon as I move the mouse into the window:
:collide(error): Invalid attempt to detect collision from CollisionRay into CollisionRay!
This means that a CollisionRay object attempted to test for an
intersection into a CollisionRay object. This intersection
test has not yet been defined; it is possible the CollisionRay
object is not intended to be collidable. Consider calling
set_into_collide_mask(0) on the CollisionRay object, or
set_from_collide_mask(0) on the CollisionRay object.
Does that mean that if I have multiple collision rays for the mouse, they interfere with each other? Is there a way to prevent that?
Does anyone have a hint how I could make this work?