How to use the panda3d.core.CollisionNode function in Panda3D

To help you get started, we’ve selected a few Panda3D examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github panda3d / panda3d / tests / collide / collisions.py View on Github external
def make_collision(solid_from, solid_into):
    node_from = CollisionNode("from")
    node_from.add_solid(solid_from)
    node_into = CollisionNode("into")
    node_into.add_solid(solid_into)

    root = NodePath("root")
    trav = CollisionTraverser()
    queue = CollisionHandlerQueue()

    np_from = root.attach_new_node(node_from)
    np_into = root.attach_new_node(node_into)

    trav.add_collider(np_from, queue)
    trav.traverse(root)

    entry = None
    for e in queue.get_entries():
        if e.get_into() == solid_into:
            entry = e
github panda3d / panda3d / samples / roaming-ralph / main.py View on Github external
# Note that we need to add ralph both to the pusher and to the
        # traverser; the pusher needs to know which node to push back when a
        # collision occurs!
        self.ralphPusher.addCollider(self.ralphColNp, self.ralph)
        self.cTrav.addCollider(self.ralphColNp, self.ralphPusher)

        # We will detect the height of the terrain by creating a collision
        # ray and casting it downward toward the terrain.  One ray will
        # start above ralph's head, and the other will start above the camera.
        # A ray may hit the terrain, or it may hit a rock or a tree.  If it
        # hits the terrain, we can detect the height.
        self.ralphGroundRay = CollisionRay()
        self.ralphGroundRay.setOrigin(0, 0, 9)
        self.ralphGroundRay.setDirection(0, 0, -1)
        self.ralphGroundCol = CollisionNode('ralphRay')
        self.ralphGroundCol.addSolid(self.ralphGroundRay)
        self.ralphGroundCol.setFromCollideMask(CollideMask.bit(0))
        self.ralphGroundCol.setIntoCollideMask(CollideMask.allOff())
        self.ralphGroundColNp = self.ralph.attachNewNode(self.ralphGroundCol)
        self.ralphGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)

        self.camGroundRay = CollisionRay()
        self.camGroundRay.setOrigin(0, 0, 9)
        self.camGroundRay.setDirection(0, 0, -1)
        self.camGroundCol = CollisionNode('camRay')
        self.camGroundCol.addSolid(self.camGroundRay)
        self.camGroundCol.setFromCollideMask(CollideMask.bit(0))
        self.camGroundCol.setIntoCollideMask(CollideMask.allOff())
        self.camGroundColNp = self.camera.attachNewNode(self.camGroundCol)
        self.camGroundHandler = CollisionHandlerQueue()
github panda3d / panda3d / direct / src / wxwidgets / ViewPort.py View on Github external
v.lens.setFilmSize(30)
    v.camPos = campos
    v.camLookAt = Point3(0, 0, 0)
    v.grid = DirectGrid(parent=render)
    if name == 'left':
      v.grid.setHpr(0, 0, 90)
      collPlane = CollisionNode('LeftGridCol')
      collPlane.addSolid(CollisionPlane(Plane(1, 0, 0, 0)))
      collPlane.setIntoCollideMask(BitMask32.bit(21))
      v.collPlane = NodePath(collPlane)
      v.collPlane.wrtReparentTo(v.grid)
      #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_leftViewGridBack")
      LE_showInOneCam(v.grid, name)
    elif name == 'front':
      v.grid.setHpr(90, 0, 90)
      collPlane = CollisionNode('FrontGridCol')
      collPlane.addSolid(CollisionPlane(Plane(0, -1, 0, 0)))
      collPlane.setIntoCollideMask(BitMask32.bit(21))
      v.collPlane = NodePath(collPlane)      
      v.collPlane.wrtReparentTo(v.grid)
      #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_frontViewGridBack")
      LE_showInOneCam(v.grid, name)
    else:
      collPlane = CollisionNode('TopGridCol')
      collPlane.addSolid(CollisionPlane(Plane(0, 0, 1, 0)))
      collPlane.setIntoCollideMask(BitMask32.bit(21))
      v.collPlane = NodePath(collPlane)
      v.collPlane.reparentTo(v.grid)
      #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_topViewGridBack")
      LE_showInOneCam(v.grid, name)
    return v
github panda3d / panda3d / direct / src / wxwidgets / ViewPort.py View on Github external
  @staticmethod
  def makePerspective(parent):
    v = Viewport('persp', parent)
    v.camPos = Point3(-19, -19, 19)
    v.camLookAt = Point3(0, 0, 0)

    v.grid = DirectGrid(parent=render)
    collPlane = CollisionNode('PerspGridCol')
    collPlane.addSolid(CollisionPlane(Plane(0, 0, 1, 0)))
    #oldBitmask = collPlane.getIntoCollideMask()
    #collPlane.setIntoCollideMask(BitMask32.bit(21)|oldBitmask)
    collPlane.setIntoCollideMask(BitMask32.bit(21))
    v.collPlane = NodePath(collPlane)
    v.collPlane.reparentTo(v.grid)

    collPlane2 = CollisionNode('PerspGridCol2')
    collPlane2.addSolid(CollisionPlane(Plane(0, 0, -1, 0)))
    #oldBitmask = collPlane2.getIntoCollideMask()
    #collPlane2.setIntoCollideMask(BitMask32.bit(21)|oldBitmask)
    collPlane2.setIntoCollideMask(BitMask32.bit(21))
    v.collPlane2 = NodePath(collPlane2)
    v.collPlane2.reparentTo(v.grid)

    #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_perspViewGridBack")
    LE_showInOneCam(v.grid, 'persp')
    return v
github panda3d / panda3d / direct / src / wxwidgets / ViewPort.py View on Github external
  @staticmethod
  def makeOrthographic(parent, name, campos):
    v = Viewport(name, parent)
    v.lens = OrthographicLens()
    v.lens.setFilmSize(30)
    v.camPos = campos
    v.camLookAt = Point3(0, 0, 0)
    v.grid = DirectGrid(parent=render)
    if name == 'left':
      v.grid.setHpr(0, 0, 90)
      collPlane = CollisionNode('LeftGridCol')
      collPlane.addSolid(CollisionPlane(Plane(1, 0, 0, 0)))
      collPlane.setIntoCollideMask(BitMask32.bit(21))
      v.collPlane = NodePath(collPlane)
      v.collPlane.wrtReparentTo(v.grid)
      #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_leftViewGridBack")
      LE_showInOneCam(v.grid, name)
    elif name == 'front':
      v.grid.setHpr(90, 0, 90)
      collPlane = CollisionNode('FrontGridCol')
      collPlane.addSolid(CollisionPlane(Plane(0, -1, 0, 0)))
      collPlane.setIntoCollideMask(BitMask32.bit(21))
      v.collPlane = NodePath(collPlane)      
      v.collPlane.wrtReparentTo(v.grid)
      #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_frontViewGridBack")
      LE_showInOneCam(v.grid, name)
    else:
github cosmonium / cosmonium / cosmonium / ui / mouse.py View on Github external
def __init__(self, base):
        self.base = base
        if settings.mouse_over:
            taskMgr.add(self.mouse_task, 'mouse-task')
        self.picker = CollisionTraverser()
        self.pq = CollisionHandlerQueue()
        self.pickerNode = CollisionNode('mouseRay')
        self.pickerNP = self.base.cam.attachNewNode(self.pickerNode)
        self.pickerNode.setFromCollideMask(CollisionNode.getDefaultCollideMask() | GeomNode.getDefaultCollideMask())
        self.pickerRay = CollisionRay()
        self.pickerNode.addSolid(self.pickerRay)
        self.picker.addCollider(self.pickerNP, self.pq)
        #self.picker.showCollisions(render)
        self.over = None
github Toontown-School-House / Toontown-School-House / toontown / suit / DistributedBossbotBoss.py View on Github external
def getGolfBall(self):
        golfRoot = NodePath('golfRoot')
        golfBall = loader.loadModel('phase_6/models/golf/golf_ball')
        golfBall.setColorScale(0.75, 0.75, 0.75, 0.5)
        golfBall.setTransparency(1)
        ballScale = 5
        golfBall.setScale(ballScale)
        golfBall.reparentTo(golfRoot)
        cs = CollisionSphere(0, 0, 0, ballScale * 0.25)
        cs.setTangible(0)
        cn = CollisionNode('BossZap')
        cn.addSolid(cs)
        cn.setIntoCollideMask(ToontownGlobals.WallBitmask)
        cnp = golfRoot.attachNewNode(cn)
        return golfRoot
github tobspr / RenderPipeline / Code / FirstPersonController.py View on Github external
self.accept("f-up", setattr, [self, "down", False])
        self.accept("q", setattr, [self, "rollLeft", True])
        self.accept("q-up", setattr, [self, "rollLeft", False])
        self.accept("e", setattr, [self, "rollRight", True])
        self.accept("e-up", setattr, [self, "rollRight", False])
        self.accept("shift", setattr, [self, "fast", 10.0])
        self.accept("shift-up", setattr, [self, "fast", 1.0])
        # setup collisions
        # setup collisions
        if self.collisionHandler != None:
            # setup collisions
            nearDist = self.camera.node().getLens().getNear()
            # Create a collision node for this camera.
            # and attach it to the camera.
            self.collisionNP = self.camera.attachNewNode(
                CollisionNode("firstPersonCamera"))
            # Attach a collision sphere solid to the collision node.
            self.collisionNP.node().addSolid(
                CollisionSphere(0, 0, 0, nearDist * 1.1))
#            self.collisionNP.show()
            # setup camera "from" bit-mask
            self.collisionNP.node().setFromCollideMask(self.collideMask)
            # add to collisionHandler (Pusher)
            self.collisionHandler.addCollider(self.collisionNP, self.camera)
            # add camera to collision system
            self.gameApp.cTrav.addCollider(
                self.collisionNP, self.collisionHandler)