示例#1
0
    def __init__(self, root_nodepath, world):
        self.world = BulletWorld()
        self.world.setGravity((0, 0, -9.81))

        self._timestep = 1 / world.tick_rate

        # # Seems that this does not function
        # on_contact_added = PythonCallbackObject(self._on_contact_added)
        # self.world.set_contact_added_callback(on_contact_added)
        # on_filter = PythonCallbackObject(self._filter_collision)
        # self.world.set_filter_callback(on_filter)

        self.listener = DirectObject()
        self.listener.accept('bullet-contact-added', self._on_contact_added)
        self.listener.accept('bullet-contact-destroyed', self._on_contact_removed)

        self.tracked_contacts = defaultdict(int)
        self.existing_collisions = set()

        # Debugging info
        debug_node = BulletDebugNode('Debug')
        debug_node.showWireframe(True)
        debug_node.showConstraints(True)
        debug_node.showBoundingBoxes(False)
        debug_node.showNormals(False)

        # Add to world
        self.debug_nodepath = root_nodepath.attachNewNode(debug_node)
        self.world.set_debug_node(debug_node)
        self.debug_nodepath.show()
示例#2
0
 def __init__(self,
              camera,
              debug=False,
              audio3d=None,
              client=None,
              server=None):
     self.objects = {}
     self.incarnators = []
     self.collidables = set()
     self.updatables = set()
     self.updatables_to_add = set()
     self.garbage = set()
     self.render = NodePath('world')
     self.camera = camera
     self.audio3d = audio3d
     self.ambient = self._make_ambient()
     self.celestials = CompositeObject()
     self.sky = self.attach(Sky())
     # Set up the physics world. TODO: let maps set gravity.
     self.gravity = DEFAULT_GRAVITY
     self.physics = BulletWorld()
     self.physics.set_gravity(self.gravity)
     self.debug = debug
     self.client = client
     self.server = server
     if debug:
         debug_node = BulletDebugNode('Debug')
         debug_node.show_wireframe(True)
         debug_node.show_constraints(True)
         debug_node.show_bounding_boxes(False)
         debug_node.show_normals(False)
         np = self.render.attach_new_node(debug_node)
         np.show()
         self.physics.set_debug_node(debug_node)
示例#3
0
    def __init__(self, scene, suncgDatasetRoot=None, debug=False, objectMode='box',
                 agentRadius=0.1, agentHeight=1.6, agentMass=60.0, agentMode='capsule'):

        super(Panda3dBulletPhysics, self).__init__()

        self.__dict__.update(scene=scene, suncgDatasetRoot=suncgDatasetRoot, debug=debug, objectMode=objectMode,
                             agentRadius=agentRadius, agentHeight=agentHeight, agentMass=agentMass, agentMode=agentMode)

        if suncgDatasetRoot is not None:
            self.modelCatMapping = ModelCategoryMapping(os.path.join(
                suncgDatasetRoot, "metadata", "ModelCategoryMapping.csv"))
        else:
            self.modelCatMapping = None

        self.bulletWorld = BulletWorld()
        self.bulletWorld.setGravity(Vec3(0, 0, -9.81))

        if debug:
            debugNode = BulletDebugNode('physic-debug')
            debugNode.showWireframe(True)
            debugNode.showConstraints(False)
            debugNode.showBoundingBoxes(True)
            debugNode.showNormals(False)
            self.debugNodePath = self.scene.scene.attachNewNode(debugNode)
            self.debugNodePath.show()
            self.bulletWorld.setDebugNode(debugNode)
        else:
            self.debugNodePath = None

        self._initLayoutModels()
        self._initAgents()
        self._initObjects()

        self.scene.worlds['physics'] = self
示例#4
0
 def __init__(self):
     debugNode = BulletDebugNode('DebugNode')
     debugNode.showWireframe(True)
     debugNode.showConstraints(True)
     debugNode.showBoundingBoxes(True)
     debugNode.showNormals(True)
     self.debugNP = render.attachNewNode(debugNode)
示例#5
0
文件: dropblt.py 项目: xwavex/pyhiro
    def __init__(self, base, objpath, bdebug=False):
        self.base = base

        self.smiley = loader.loadModel(objpath)
        self.smileyCount = 0

        self.setupBullet()
        self.addGround()
        # self.addWalls()

        self.partlist = []

        taskMgr.doMethodLater(.1, self.addSmiley, "AddSmiley")
        taskMgr.add(self.updateBlt, "UpdateBlt")

        if bdebug:
            debugNode = BulletDebugNode('Debug')
            debugNode.showWireframe(True)
            debugNode.showConstraints(True)
            debugNode.showBoundingBoxes(False)
            debugNode.showNormals(False)
            bullcldrnp = self.base.render.attachNewNode("bulletcollider")
            debugNP = bullcldrnp.attachNewNode(debugNode)
            debugNP.show()
            self.bltWorld.setDebugNode(debugNP.node())
示例#6
0
    def __init__(self,
                 camera,
                 debug=False,
                 audio3d=None,
                 client=None,
                 server=None):
        self.objects = {}

        self.incarnators = []

        self.collidables = set()

        self.updatables = set()
        self.updatables_to_add = set()
        self.garbage = set()
        self.scene = NodePath('world')

        # Set up the physics world. TODO: let maps set gravity.
        self.gravity = DEFAULT_GRAVITY
        self.physics = BulletWorld()
        self.physics.set_gravity(self.gravity)

        self.debug = debug

        if debug:
            debug_node = BulletDebugNode('Debug')
            debug_node.show_wireframe(True)
            debug_node.show_constraints(True)
            debug_node.show_bounding_boxes(False)
            debug_node.show_normals(False)
            np = self.scene.attach_new_node(debug_node)
            np.show()
            self.physics.set_debug_node(debug_node)
示例#7
0
    def __init__(self):
        base.accept('f1', self.toggleDebug)

        self.debugNode = BulletDebugNode('Debug')
        self.debugNode.showWireframe(True)
        self.debugNode.showConstraints(True)
        self.debugNode.showBoundingBoxes(False)
        self.debugNode.showNormals(False)
        self.debugNP = base.render.attachNewNode(self.debugNode)
        # self.debugNP.show()

        # World
        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Terrain
        visNP = base.loader.loadModel('models/terrain.egg')

        mesh = BulletTriangleMesh()
        for x in visNP.findAllMatches('**/+GeomNode'):
            geom = x.node().getGeom(0)
            mesh.addGeom(geom)
        shape = BulletTriangleMeshShape(mesh, dynamic=True)

        body = BulletRigidBodyNode('Bowl')
        bodyNP = base.render.attachNewNode(body)
        bodyNP.node().addShape(shape)
        bodyNP.setPos(0, 0, 1)
        bodyNP.setCollideMask(BitMask32.allOn())
        self.world.attachRigidBody(bodyNP.node())

        visNP.reparentTo(bodyNP)

        shapex = BulletBoxShape(5)
        bodyx = BulletRigidBodyNode('Egg')
        bodyNPx = base.render.attachNewNode(bodyx)
        bodyNPx.setPos(0, 0, 3)
        bodyNPx.node().setMass(100.0)
        bodyNPx.node().addShape(shapex)
        self.world.attachRigidBody(bodyNPx.node())
        # visNP.reparentTo(bodyNPx)

        # Player
        self.players = []
        self.myId = -1
        self.speed = Vec3(0, 0, 0)
        self.walk_speed = 2.5

        # Camera
        base.disableMouse()
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)

        # SkySphere
        Sky()

        self.initCam()
示例#8
0
 def setup_debug(self):
     debug_node = BulletDebugNode('Debug')
     debug_node.showWireframe(True)
     debug_node.showConstraints(True)
     debug_node.showBoundingBoxes(True)
     debug_node.showNormals(True)
     self.world.setDebugNode(debug_node)
     return debug_node
    def setupDebug(self):
        node = BulletDebugNode("Debug")
        node.showWireframe(True)

        self.world.setDebugNode(node)

        np = self.render.attachNewNode(node)
        np.show()
示例#10
0
 def bullet_debug(self):
     debug_node = BulletDebugNode('Debug')
     debug_node.show_wireframe(True)
     debug_node.show_constraints(True)
     debug_node.show_bounding_boxes(False)
     debug_node.show_normals(False)
     self.debug_np = self.render.attach_new_node(debug_node)
     self.environment.physics_world.set_debug_node(debug_node)
示例#11
0
 def init(self):
     self.collision_objs = []
     self.__obj2coll = {}
     self.root = BulletWorld()
     self.root.setGravity((0, 0, -9.81))
     debug_node = BulletDebugNode('Debug')
     debug_node.show_bounding_boxes(True)
     self.__debug_np = render.attach_new_node(debug_node)
     self.root.set_debug_node(self.__debug_np.node())
示例#12
0
 def _debug_mode(self):
     debugNode = BulletDebugNode('Debug')
     debugNode.showWireframe(True)
     debugNode.showConstraints(True)
     debugNode.showBoundingBoxes(False)
     debugNode.showNormals(True)
     debugNP = self.render.attachNewNode(debugNode)
     self.physics_world.dynamic_world.setDebugNode(debugNP.node())
     self.debug_node = debugNP
示例#13
0
    def __init__(self, base, objpath, bdebug = False):
        self.base = base

        self.smiley = loader.loadModel(objpath)
        self.smileyCount = 0

        self.setupBullet()
        self.addGround()
        # self.addWalls()

        self.partlist = []

        taskMgr.doMethodLater(.1, self.addSmiley, "AddSmiley")
        taskMgr.add(self.updateBlt, "UpdateBlt")

        if bdebug:
            debugNode = BulletDebugNode('Debug')
            debugNode.showWireframe(True)
            debugNode.showConstraints(True)
            debugNode.showBoundingBoxes(False)
            debugNode.showNormals(False)
            bullcldrnp = self.base.render.attachNewNode("bulletcollider")
            debugNP = bullcldrnp.attachNewNode(debugNode)
            debugNP.show()
            self.bltWorld.setDebugNode(debugNP.node())
示例#14
0
    def __init__(self):
        self.register_signals()

        self.world = BulletWorld()
        self.world.setGravity((0, 0, -9.81))

        # # Seems that this does not function
        # on_contact_added = PythonCallbackObject(self._on_contact_added)
        # self.world.set_contact_added_callback(on_contact_added)

        # on_filter = PythonCallbackObject(self._filter_collision)
        # self.world.set_filter_callback(on_filter)

        self.listener = DirectObject()
        self.listener.accept('bullet-contact-added', self._on_contact_added)
        self.listener.accept('bullet-contact-destroyed', self._on_contact_removed)

        debug_node = BulletDebugNode('Debug')
        debug_node.showWireframe(True)
        debug_node.showConstraints(True)
        debug_node.showBoundingBoxes(False)
        debug_node.showNormals(False)

        self.debug_nodepath = render.attachNewNode(debug_node)
        self.world.set_debug_node(debug_node)

        self.debug_nodepath.show()
示例#15
0
文件: world.py 项目: airvoss/pavara
    def __init__(self, camera, debug=False, audio3d=None, client=None, server=None):
        self.objects = {}

        self.incarnators = []

        self.collidables = set()

        self.updatables = set()
        self.updatables_to_add = set()
        self.garbage = set()
        self.scene = NodePath('world')


        # Set up the physics world. TODO: let maps set gravity.
        self.gravity = DEFAULT_GRAVITY
        self.physics = BulletWorld()
        self.physics.set_gravity(self.gravity)

        self.debug = debug

        if debug:
            debug_node = BulletDebugNode('Debug')
            debug_node.show_wireframe(True)
            debug_node.show_constraints(True)
            debug_node.show_bounding_boxes(False)
            debug_node.show_normals(False)
            np = self.scene.attach_new_node(debug_node)
            np.show()
            self.physics.set_debug_node(debug_node)
示例#16
0
文件: world.py 项目: jorjuato/pavara
 def __init__(self, camera, debug=False, audio3d=None, client=None, server=None):
     self.objects = {}
     self.incarnators = []
     self.collidables = set()
     self.updatables = set()
     self.updatables_to_add = set()
     self.garbage = set()
     self.render = NodePath('world')
     self.camera = camera
     self.audio3d = audio3d
     self.ambient = self._make_ambient()
     self.celestials = CompositeObject()
     self.sky = self.attach(Sky())
     # Set up the physics world. TODO: let maps set gravity.
     self.gravity = DEFAULT_GRAVITY
     self.physics = BulletWorld()
     self.physics.set_gravity(self.gravity)
     self.debug = debug
     self.client = client
     self.server = server
     if debug:
         debug_node = BulletDebugNode('Debug')
         debug_node.show_wireframe(True)
         debug_node.show_constraints(True)
         debug_node.show_bounding_boxes(False)
         debug_node.show_normals(False)
         np = self.render.attach_new_node(debug_node)
         np.show()
         self.physics.set_debug_node(debug_node)
	def __init__(self):
		debugNode = BulletDebugNode('DebugNode')
		debugNode.showWireframe(True)
		debugNode.showConstraints(True)
		debugNode.showBoundingBoxes(True)
		debugNode.showNormals(True)
		self.debugNP = render.attachNewNode(debugNode)
示例#18
0
    def setup_debug(self):
        """Set up a debug node, which will render skeletons for all the
        physics objects in the physics world."""

        debug_node = BulletDebugNode('Debug')
        debug_node.show_wireframe(True)
        debug_node.show_constraints(True)
        debug_node.show_bounding_boxes(True)
        debug_node.show_normals(True)
        self.world.set_debug_node(debug_node)
        self.debug_np = self.render.attach_new_node(debug_node)
 def setupDebug(self):
     debug = BulletDebugNode()
     debug.showWireframe(
         False
     )  # Yeah, don't set this to true unless you want to emulate an 80's computer running Crysis on Ultra settings.
     debug.showConstraints(True)
     debug.showBoundingBoxes(True)  # This is the main use I have for it.
     debug.showNormals(True)
     debugNP = render.attachNewNode(debug)
     self.worldBullet.setDebugNode(debugNP.node())
     debugNP.hide()
     return debugNP
示例#20
0
    def showBulletDebug(self):
        """Show bullet Debug"""
        # Bullet DEBUG
        debugNode = BulletDebugNode('Debug')
        debugNode.showWireframe(True)
        debugNode.showConstraints(True)
        debugNode.showBoundingBoxes(False)
        debugNode.showNormals(False)
        debugNP = render.attachNewNode(debugNode)
        debugNP.show()

        self.bulletWorld.setDebugNode(debugNP.node())
示例#21
0
	def setupDebug(self):
		debug = BulletDebugNode()
		debug.showWireframe(False) # Yeah, don't set this to true unless you want to emulate an 80's computer running Crysis on Ultra settings.
		debug.showConstraints(True)
		debug.showBoundingBoxes(True) # This is the main use I have for it.
		debug.showNormals(True)
		debugNP = render.attachNewNode(debug)
		self.worldBullet.setDebugNode(debugNP.node())
		debugNP.hide()
		return debugNP
示例#22
0
    def __init__(self, base):
        self.__base = base
        self.__base.world = BulletWorld()
        bulletcolliderrender = self.__base.render.attachNewNode("bulletcollider")

        debugNode = BulletDebugNode('Debug')
        debugNode.showWireframe(True)
        debugNode.showConstraints(True)
        debugNode.showBoundingBoxes(False)
        debugNode.showNormals(False)
        self.__debugNP = bulletcolliderrender.attachNewNode(debugNode)
        self.__base.world.setDebugNode(self.__debugNP.node())

        self.worldrigidbodylist = []
示例#23
0
    def setupBulletPhysics(self):
        debugNode = BulletDebugNode('Debug')
        debugNode.showWireframe(True)
        debugNode.showConstraints(True)
        debugNode.showBoundingBoxes(False)
        debugNode.showNormals(False)
        self.debugNP = render.attachNewNode(debugNode)

        self.mondePhysique = BulletWorld()
        self.mondePhysique.setGravity(Vec3(0, 0, -9.81))
        self.mondePhysique.setDebugNode(self.debugNP.node())
        taskMgr.add(self.updatePhysics, "updatePhysics")

        taskMgr.add(self.updateCarte, "updateCarte")
示例#24
0
 def setPhysics(self):
     print "Setting physics"
     self.world = BulletWorld()
     self.world.setGravity(Vec3(0, 0, -10))
     self.Base.taskMgr.add(self.physicsUpdate, "physicsUpdate", priority=0)
     if self.debugDrawing:
         print "Debug drawing"
         self.debug = BulletDebugNode("debug")
         self.debug.showWireframe(True)
         self.debug.showBoundingBoxes(False)
         self.debug.showNormals(True)
         self.debugNP = self.Base.render.attachNewNode(self.debug)
         self.debugNP.show()
         self.world.setDebugNode(self.debug)
示例#25
0
    def __init__(self):

        #self.gui = loadGui()
        #init_pause_state(self.menu)
        init_pause_state()
        test = World()

        debugNode = BulletDebugNode('Debug')
        debugNode.showWireframe(True)
        debugNode.showConstraints(True)
        debugNode.showBoundingBoxes(False)
        debugNode.showNormals(False)
        debugNP = render.attachNewNode(debugNode)
        debugNP.show()

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9))

        self.world.setDebugNode(debugNP.node())

        #Add a gravity region
        self.add_gravity_region(
                (100, 100, 100),
                (100, -400, 0),
                (0, 0, 1000))

        taskMgr.add(self.update_bullet, 'update_bullet')

        self.bulletList = self.loadBulletList()

        base.disableMouse()

        self.loadLevel()
        self.initClasses()
        self.setCamera()
        self.addWinProps()

        #TODO: Fix the healthbars
        #self.gui.healthBar("Player1")
        #self.gui.healthBar("AI1")
        #self.gui.healthBar("AI2")
        #self.gui.healthBar("AI3")

        self.loadStation()

        self.addlight()

        self.createControls()

        taskMgr.add(self.updateMenus, 'MenuUpdater')
        print("Instance of game class running.")

        self.simmpoleXP()
        self.flipsXP()
示例#26
0
    def setup_debug(self):
        """Set up a debug node, which will render skeletons for all the
        physics objects in the physics world."""

        debug_node = BulletDebugNode('Debug')
        debug_node.show_wireframe(True)
        debug_node.show_constraints(True)
        debug_node.show_bounding_boxes(True)
        debug_node.show_normals(True)
        self.world.set_debug_node(debug_node)
        self.debug_np = self.render.attach_new_node(debug_node)
示例#27
0
    def setPhysicsDebug(self, _bool=False):
        debugNode = BulletDebugNode('Debug')
        self.debugNP = render.attachNewNode(debugNode)

        if _bool:
            debugNode = BulletDebugNode('Debug')
            debugNode.showWireframe(True)
            debugNode.showConstraints(True)
            debugNode.showBoundingBoxes(False)
            debugNode.showNormals(False)
            self.debugNP = render.attachNewNode(debugNode)
            self.physicsWorld.setDebugNode(self.debugNP.node())
            self.debugNP.show()
        else:
            self.debugNP.hide()
示例#28
0
    def showBulletDebug(self):
        """Show bullet Debug"""
        # Bullet DEBUG
        debugNode = BulletDebugNode('Debug')
        debugNode.showWireframe(True)
        debugNode.showConstraints(True)
        debugNode.showBoundingBoxes(False)
        debugNode.showNormals(False)
        debugNP = render.attachNewNode(debugNode)
        debugNP.show()

        self.bulletWorld.setDebugNode(debugNP.node())
示例#29
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Plane
        shape = BulletPlaneShape(Vec3(0, 0, 1), 0)

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        np.node().addShape(shape)
        np.setPos(0, 0, -1)
        np.setCollideMask(BitMask32.allOn())

        self.world.attachRigidBody(np.node())

        # initial vehicles
        self.vehicles = []
        #self.vehicles.append(basicVehicle(self,[13,2,0.5],18)) # [10,0.1,0.5] is vehicle start position
        self.vehicles.append(
            basicVehicle(self, [10, 0.1, 0.5],
                         18))  # [10,0.1,0.5] is vehicle start position
        sensor = basicSensor(self)  # initial sensor
        sensor.setVehicle(self.vehicles[0])
        self.vehicles[0].setSensor(sensor)
        self.vehicles[0].sensor.align()
        agent = basicAgent(50, 10.8, 15)  # initial agent
        agent.setVehicle(self.vehicles[0])
        self.vehicles[0].setAgent(agent)
示例#30
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Plane
        shape = BulletPlaneShape(Vec3(0, 0, 1), 0)

        # collision
        visNP = loader.loadModel('../models/coryf2.egg')
        visNP.clearModelNodes()
        visNP.reparentTo(render)
        pos = (7., 60.0, 3.8)
        visNP.setPos(pos[0], pos[1], pos[2])

        bodyNPs = BulletHelper.fromCollisionSolids(visNP, True)
        for bodyNP in bodyNPs:
            bodyNP.reparentTo(render)
            bodyNP.setPos(pos[0], pos[1], pos[2])

            if isinstance(bodyNP.node(), BulletRigidBodyNode):
                bodyNP.node().setMass(0.0)
                bodyNP.node().setKinematic(True)
                bodyNP.setCollideMask(BitMask32.allOn())
                self.world.attachRigidBody(bodyNP.node())
示例#31
0
    def setup(self):
        self.worldNP = self.render.attachNewNode('World')
        self.world = PGPhysicsWorld()
        self.physics_world = self.world

        # World
        if self.debug:
            self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
            self.debugNP.show()
            self.debugNP.node().showWireframe(True)
            self.debugNP.node().showConstraints(True)
            self.debugNP.node().showBoundingBoxes(True)
            self.debugNP.node().showNormals(True)

            self.debugNP.showTightBounds()
            self.debugNP.showBounds()
            self.world.dynamic_world.setDebugNode(self.debugNP.node())

        # Ground (static)
        shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        self.groundNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        self.groundNP.node().addShape(shape)
        self.groundNP.setPos(0, 0, 0)
        self.groundNP.setCollideMask(BitMask32.allOn())
        self.world.dynamic_world.attachRigidBody(self.groundNP.node())
示例#32
0
    def setup(self):

        # World
        self.worldNP = render.attachNewNode("World")
        self.GUI = self.worldNP.attachNewNode("GUI")
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode("Debug"))
        self.debugNP.show()
        self.debugNP.node().showWireframe(True)
        self.debugNP.node().showConstraints(True)
        self.debugNP.node().showBoundingBoxes(False)
        self.debugNP.node().showNormals(True)

        self.setDefaults()
        self.addGUI()
        self.createCurve()

        self.world = BulletWorld()
        # self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setGravity(Vec3(0, 0, 0))
        self.world.setDebugNode(self.debugNP.node())

        # Plane (static)
        shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        nodePath = self.worldNP.attachNewNode(BulletRigidBodyNode("Ground"))
        nodePath.node().addShape(shape)
        nodePath.setPos(0, 0, 0)
        nodePath.setCollideMask(BitMask32.allOn())
        self.world.attachRigidBody(nodePath.node())

        self.loadModel()
示例#33
0
  def setup(self):
    self.worldNP = render.attachNewNode('World')

    # World
    self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
    self.debugNP.show()

    self.world = BulletWorld()
    self.world.setGravity(Vec3(0, 0, -9.81))
    self.world.setDebugNode(self.debugNP.node())

    # Ground
    shape = BulletPlaneShape(Vec3(0, 0, 1), -1)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
    np.node().addShape(shape)
    np.setPos(0, 0, -1)
    np.setCollideMask(BitMask32.bit(0))

    self.world.attachRigidBody(np.node())

    # Boxes
    self.boxes = [None,]*6

    for i in range(6):
      shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

      np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-1'))
      np.node().setMass(1.0)
      np.node().addShape(shape)

      self.world.attachRigidBody(np.node())

      self.boxes[i] = np

      visualNP = loader.loadModel('models/box.egg')
      visualNP.reparentTo(np)

    self.boxes[0].setPos(-3, -3, 0)
    self.boxes[1].setPos( 0, -3, 0)
    self.boxes[2].setPos( 3, -3, 0)
    self.boxes[3].setPos(-3,  3, 0)
    self.boxes[4].setPos( 0,  3, 0)
    self.boxes[5].setPos( 3,  3, 0)

    self.boxes[0].setCollideMask(BitMask32.bit(1))
    self.boxes[1].setCollideMask(BitMask32.bit(2))
    self.boxes[2].setCollideMask(BitMask32.bit(3))
    self.boxes[3].setCollideMask(BitMask32.bit(1))
    self.boxes[4].setCollideMask(BitMask32.bit(2))
    self.boxes[5].setCollideMask(BitMask32.bit(3))

    self.boxNP = self.boxes[0]

    self.world.setGroupCollisionFlag(0, 1, True)
    self.world.setGroupCollisionFlag(0, 2, True)
    self.world.setGroupCollisionFlag(0, 3, True)

    self.world.setGroupCollisionFlag(1, 1, False)
    self.world.setGroupCollisionFlag(1, 2, True)
示例#34
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().show_wireframe(True)
        self.debugNP.node().show_constraints(True)
        self.debugNP.node().show_bounding_boxes(False)
        self.debugNP.node().show_normals(False)

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Box A
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyA = BulletRigidBodyNode('Box A')
        bodyNP = self.worldNP.attach_new_node(bodyA)
        bodyNP.node().add_shape(shape)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(-3, 0, 4)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyA)

        # Box B
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyB = BulletRigidBodyNode('Box B')
        bodyNP = self.worldNP.attach_new_node(bodyB)
        bodyNP.node().add_shape(shape)
        bodyNP.node().set_mass(1.0)
        bodyNP.node().set_deactivation_enabled(False)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(0, 0, 0)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyB)

        # Slider
        frameA = TransformState.make_pos_hpr(LPoint3(2, 0, 0),
                                             LVector3(0, 0, 45))
        frameB = TransformState.make_pos_hpr(LPoint3(0, -3, 0),
                                             LVector3(0, 0, 0))

        slider = BulletSliderConstraint(bodyA, bodyB, frameA, frameB, True)
        slider.set_debug_draw_size(2.0)
        slider.set_lower_linear_limit(0)
        slider.set_upper_linear_limit(6)
        slider.set_lower_angular_limit(-60)
        slider.set_upper_angular_limit(60)
        self.world.attach(slider)
示例#35
0
    def __init__(self, toggledebug=False):
        self.world = BulletWorld()
        self._toggledebug = toggledebug
        if self._toggledebug:
            bulletcolliderrender = base.render.attachNewNode(
                "bulletboxcollider")
            debugNode = BulletDebugNode('Debug')
            debugNode.showWireframe(True)
            debugNode.showConstraints(True)
            debugNode.showBoundingBoxes(False)
            debugNode.showNormals(False)
            self._debugNP = bulletcolliderrender.attachNewNode(debugNode)
            self.world.setDebugNode(self._debugNP.node())

        self.worldrigidbodylist = []
        self._isupdateworldadded = False
示例#36
0
	def drawDebugNode(self):
		debugNode = BulletDebugNode('Debug')
		debugNode.showWireframe(True)
		debugNode.showConstraints(True)
		debugNode.showBoundingBoxes(False)
		debugNode.showNormals(False)
		self.debugNP = render.attachNewNode(debugNode)

		#print "TankWorld.drawDebugNode: debug node activated" 
		self.accept('9', self.debugNP.show)
		self.accept('8', self.debugNP.hide)

		self.__bulletWorld.setDebugNode(debugNode)
示例#37
0
  def setup(self):
    self.worldNP = render.attachNewNode('World')

    # World
    self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
    self.debugNP.show()

    self.world = BulletWorld()
    self.world.setGravity(Vec3(0, 0, -9.81))
    self.world.setDebugNode(self.debugNP.node())

    # Ground
    shape = BulletPlaneShape(Vec3(0, 0, 1), 0)

    #img = PNMImage(Filename('models/elevation2.png'))
    #shape = BulletHeightfieldShape(img, 1.0, ZUp)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
    np.node().addShape(shape)
    np.setPos(0, 0, -1)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

    # Box
    shape = BulletBoxShape(Vec3(1.0, 3.0, 0.3))

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
    np.node().setMass(10.0)
    np.node().addShape(shape)
    np.setPos(3, 0, 4)
    np.setH(20.0)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

    # Character
    self.crouching = False

    h = 1.75
    w = 0.4
    shape = BulletCapsuleShape(w, h - 2 * w, ZUp)

    self.character = BulletCharacterControllerNode(shape, 0.4, 'Player')
    # self.character.setMass(1.0)
    self.characterNP = self.worldNP.attachNewNode(self.character)
    self.characterNP.setPos(-2, 0, 14)
    self.characterNP.setH(45)
    self.characterNP.setCollideMask(BitMask32.allOn())
    self.world.attachCharacter(self.character)

    self.actorNP = Actor('models/ralph/ralph.egg', {
                         'run' : 'models/ralph/ralph-run.egg',
                         'walk' : 'models/ralph/ralph-walk.egg',
                         'jump' : 'models/ralph/ralph-jump.egg'})
    self.actorNP.reparentTo(self.characterNP)
    self.actorNP.setScale(0.3048) # 1ft = 0.3048m
    self.actorNP.setH(180)
    self.actorNP.setPos(0, 0, -1)
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().showWireframe(True)
        self.debugNP.node().showConstraints(True)
        self.debugNP.node().showBoundingBoxes(False)
        self.debugNP.node().showNormals(False)

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Box A
        shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

        bodyA = BulletRigidBodyNode('Box A')
        bodyNP = self.worldNP.attachNewNode(bodyA)
        bodyNP.node().addShape(shape)
        bodyNP.setCollideMask(BitMask32.allOn())
        bodyNP.setPos(-3, 0, 4)

        visNP = loader.loadModel('models/box.egg')
        visNP.clearModelNodes()
        visNP.reparentTo(bodyNP)

        self.world.attachRigidBody(bodyA)

        # Box B
        shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

        bodyB = BulletRigidBodyNode('Box B')
        bodyNP = self.worldNP.attachNewNode(bodyB)
        bodyNP.node().addShape(shape)
        bodyNP.node().setMass(1.0)
        bodyNP.node().setDeactivationEnabled(False)
        bodyNP.setCollideMask(BitMask32.allOn())
        bodyNP.setPos(0, 0, 0)

        visNP = loader.loadModel('models/box.egg')
        visNP.clearModelNodes()
        visNP.reparentTo(bodyNP)

        self.world.attachRigidBody(bodyB)

        # Slider
        frameA = TransformState.makePosHpr(Point3(2, 0, 0), Vec3(0, 0, 45))
        frameB = TransformState.makePosHpr(Point3(0, -3, 0), Vec3(0, 0, 0))

        slider = BulletSliderConstraint(bodyA, bodyB, frameA, frameB, True)
        slider.setDebugDrawSize(2.0)
        slider.setLowerLinearLimit(0)
        slider.setUpperLinearLimit(6)
        slider.setLowerAngularLimit(-60)
        slider.setUpperAngularLimit(60)
        self.world.attachConstraint(slider)
示例#39
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().showWireframe(True)
        self.debugNP.node().showConstraints(True)
        self.debugNP.node().showBoundingBoxes(False)
        self.debugNP.node().showNormals(False)

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Box A
        shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

        bodyA = BulletRigidBodyNode('Box A')
        bodyNP = self.worldNP.attachNewNode(bodyA)
        bodyNP.node().addShape(shape)
        bodyNP.setCollideMask(BitMask32.allOn())
        bodyNP.setPos(-2, 0, 1)

        visNP = loader.loadModel('models/box.egg')
        visNP.clearModelNodes()
        visNP.reparentTo(bodyNP)

        self.world.attachRigidBody(bodyA)

        # Box B
        shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

        bodyB = BulletRigidBodyNode('Box B')
        bodyNP = self.worldNP.attachNewNode(bodyB)
        bodyNP.node().addShape(shape)
        bodyNP.node().setMass(1.0)
        bodyNP.node().setDeactivationEnabled(False)
        bodyNP.setCollideMask(BitMask32.allOn())
        bodyNP.setPos(2, 0, 1)

        visNP = loader.loadModel('models/box.egg')
        visNP.clearModelNodes()
        visNP.reparentTo(bodyNP)

        self.world.attachRigidBody(bodyB)

        # Hinge
        pivotA = Point3(2, 0, 0)
        pivotB = Point3(-4, 0, 0)
        axisA = Vec3(0, 0, 1)
        axisB = Vec3(0, 0, 1)

        hinge = BulletHingeConstraint(bodyA, bodyB, pivotA, pivotB, axisA,
                                      axisB, True)
        hinge.setDebugDrawSize(2.0)
        hinge.setLimit(-90, 120, softness=0.9, bias=0.3, relaxation=1.0)
        self.world.attachConstraint(hinge)
示例#40
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().show_wireframe(True)
        self.debugNP.node().show_constraints(True)
        self.debugNP.node().show_bounding_boxes(False)
        self.debugNP.node().show_normals(False)

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Box A
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyA = BulletRigidBodyNode('Box A')
        bodyNP = self.worldNP.attach_new_node(bodyA)
        bodyNP.node().add_shape(shape)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(-2, 0, 1)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyA)

        # Box B
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyB = BulletRigidBodyNode('Box B')
        bodyNP = self.worldNP.attach_new_node(bodyB)
        bodyNP.node().add_shape(shape)
        bodyNP.node().set_mass(1.0)
        bodyNP.node().set_deactivation_enabled(False)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(2, 0, 1)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyB)

        # Hinge
        pivotA = LPoint3(2, 0, 0)
        pivotB = LPoint3(-4, 0, 0)
        axisA = LVector3(0, 0, 1)
        axisB = LVector3(0, 0, 1)

        hinge = BulletHingeConstraint(bodyA, bodyB, pivotA, pivotB, axisA,
                                      axisB, True)
        hinge.set_debug_draw_size(2.0)
        hinge.set_limit(-90, 120, softness=0.9, bias=0.3, relaxation=1.0)
        self.world.attach(hinge)
示例#41
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Ground
        shape = BulletPlaneShape(LVector3(0, 0, 1), 0)

        #img = PNMImage(Filename('models/elevation.png'))
        #shape = BulletHeightfieldShape(img, 1.0, ZUp)

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Ground'))
        np.node().add_shape(shape)
        np.set_pos(0, 0, -1)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Box
        shape = BulletBoxShape(LVector3(1.0, 3.0, 0.3))

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Box'))
        np.node().set_mass(10.0)
        np.node().add_shape(shape)
        np.set_pos(3, 0, 4)
        np.setH(20.0)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Character
        self.crouching = False

        h = 1.75
        w = 0.4
        shape = BulletCapsuleShape(w, h - 2 * w, ZUp)
        self.character = BulletCharacterControllerNode(shape, 0.4, 'Player')
        self.characterNP = self.worldNP.attach_new_node(self.character)
        self.characterNP.set_pos(-2, 0, 14)
        self.characterNP.set_h(45)
        self.characterNP.set_collide_mask(BitMask32.all_on())
        self.world.attach(self.character)

        self.actorNP = Actor(
            'samples/roaming-ralph/models/ralph.egg.pz', {
                'run': 'samples/roaming-ralph/models/ralph-run.egg.pz',
                'walk': 'samples/roaming-ralph/models/ralph-walk.egg.pz'
            })
        self.actorNP.reparent_to(self.characterNP)
        self.actorNP.set_scale(0.3048)  # 1ft = 0.3048m
        self.actorNP.setH(180)
        self.actorNP.set_pos(0, 0, -1)
示例#42
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Ground
        shape = BulletPlaneShape(Vec3(0, 0, 1), 0)

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        np.node().addShape(shape)
        np.setPos(0, 0, 0)
        np.setCollideMask(BitMask32(0x0f))

        self.world.attachRigidBody(np.node())

        # Box
        shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
        np.node().setMass(1.0)
        np.node().addShape(shape)
        np.setPos(0, 0, 4)
        np.setCollideMask(BitMask32(0x0f))

        self.world.attachRigidBody(np.node())

        self.boxNP = np
        visualNP = loader.loadModel('models/box.egg')
        visualNP.reparentTo(self.boxNP)

        # Sphere
        shape = BulletSphereShape(0.6)

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Sphere'))
        np.node().setMass(1.0)
        np.node().addShape(shape)
        np.setPos(3, 0, 4)
        np.setCollideMask(BitMask32(0x0f))

        self.world.attachRigidBody(np.node())

        # Cone
        shape = BulletConeShape(0.6, 1.0)

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Cone'))
        np.node().setMass(1.0)
        np.node().addShape(shape)
        np.setPos(6, 0, 4)
        np.setCollideMask(BitMask32(0x0f))

        self.world.attachRigidBody(np.node())
示例#43
0
文件: mc.py 项目: fcostin/gravbot
    def __init__(self):
        ShowBase.__init__(self)
        utilities.setApp(self)

        loadPrcFileData('', 'bullet-enable-contact-events true')

        self.world = World(10)

        self.taskMgr.add(self.update, "update")

        self.accept("a", self.world.player.moveLeft, [True])
        self.accept("a-up", self.world.player.moveLeft, [False])

        self.accept("d", self.world.player.moveRight, [True])
        self.accept("d-up", self.world.player.moveRight, [False])

        self.accept("space", self.world.player.jump, [True])
        self.accept("space-up", self.world.player.jump, [False])

        self.accept("c", self.world.player.crouch, [True])
        self.accept("c-up", self.world.player.crouch, [False])

        self.accept("mouse1", self.world.player.activate, [])

        self.accept("escape", sys.exit, [])

        self.accept('bullet-contact-added', self.onContactAdded) 
        self.accept('bullet-contact-destroyed', self.onContactDestroyed) 

        self.accept("h", self.showDBG, [True])
        self.accept("h-up", self.showDBG, [False])

        self.prevTime = 0

        self.mousePos = Point2()
        base.disableMouse()

        self.rl = base.camLens.makeCopy()

        # bullet testing
        debugNode = BulletDebugNode('Debug')
        debugNode.showWireframe(True)
        debugNode.showConstraints(True)
        debugNode.showBoundingBoxes(False)
        debugNode.showNormals(False)
        self.debugNP = render.attachNewNode(debugNode)
        self.debugNP.show()

        self.world.bw.setDebugNode(self.debugNP.node())
示例#44
0
    def __init__(self, app):
        self.app = app

        utilities.setApp(self.app)

        self.world = World(10)

        self.app.taskMgr.add(self.update, "update")

        self.app.accept("a", self.world.player.moveLeft, [True])
        self.app.accept("a-up", self.world.player.moveLeft, [False])

        self.app.accept("d", self.world.player.moveRight, [True])
        self.app.accept("d-up", self.world.player.moveRight, [False])

        self.app.accept("w", self.world.player.jump, [True])
        self.app.accept("w-up", self.world.player.jump, [False])

        self.app.accept("s", self.world.player.crouch, [True])
        self.app.accept("s-up", self.world.player.crouch, [False])

        self.app.accept("mouse1", self.world.player.activate, [])

        self.app.accept("q", self.world.player.scrollItem, [1])
        self.app.accept("1", self.world.player.selectItem, [1])
        self.app.accept("2", self.world.player.selectItem, [2])

        self.app.accept("escape", sys.exit, [])

        self.app.mousePos = Point2()
        self.app.disableMouse()

        self.app.rl = base.camLens.makeCopy()

        if utilities.debug:
          self.app.accept("h", self.showDBG, [True])
          self.app.accept("h-up", self.showDBG, [False])

          #bullet debug rendering 
          debugNode = BulletDebugNode('Debug')
          debugNode.showWireframe(True)
          debugNode.showConstraints(True)
          debugNode.showBoundingBoxes(False)
          debugNode.showNormals(False)
          self.debugNP = render.attachNewNode(debugNode)
          self.debugNP.show()
          self.world.bw.setDebugNode(self.debugNP.node())
示例#45
0
    def initBullet(self):
        self.world.setGravity(Vec3(0, 0, -9.81))

        self.debugNode = BulletDebugNode('Debug')
        self.debugNode.showWireframe(True)
        self.debugNode.showConstraints(True)
        self.debugNode.showBoundingBoxes(False)
        self.debugNode.showNormals(False)

        self.debugNP = render.attachNewNode(self.debugNode)
        self.world.setDebugNode(self.debugNP.node())
示例#46
0
文件: world.py 项目: dcwatson/pavara
 def setup(self):
     self.node = NodePath('world')
     self.node.set_transparency(TransparencyAttrib.MAlpha)
     if self.debug:
         d = BulletDebugNode('Debug')
         d.show_wireframe(True)
         d.show_normals(True)
         self.node.attach_new_node(d).show()
         self.physics.set_debug_node(d)
     if self.camera:
         self.camera.node().get_lens().set_fov(80.0, 50.0)
         self.camera.node().get_lens().set_near(0.1)
     # Default ambient light
     alight = AmbientLight('ambient')
     alight.set_color(DEFAULT_AMBIENT_COLOR)
     self.ambient = self.node.attach_new_node(alight)
     self.node.set_light(self.ambient)
     # Default directional lights
     self.add_celestial(math.radians(20), math.radians(45), (1, 1, 1, 1), 0.4, 30.0)
     self.add_celestial(math.radians(200), math.radians(20), (1, 1, 1, 1), 0.3, 30.0)
示例#47
0
    def showDebug(self):

        # To enable debug
        self.debugNode = BulletDebugNode("Debug")
        self.debugNode.showBoundingBoxes(True)
        self.debugNode.showNormals(False)
        self.debugNode.showWireframe(True)
        self.debugNode.showConstraints(True)
        self.debugNP = render.attachNewNode(self.debugNode)
        self.debugNP.show()

        # Add the debug node to the physics world
        self.world.setDebugNode(self.debugNP.node())
示例#48
0
    def __init__(self, xml):
        globalClock.setMaxDt(0.1)
        #init pre and post callbacks
        self.prePhysics = {}
        self.postPhysics = {}

        #bullet debug node
        debugNode = BulletDebugNode('Debug')
        debugNode.showWireframe(True)
        debugNode.showConstraints(True)
        debugNode.showBoundingBoxes(False)
        debugNode.showNormals(True)
        debugNP = render.attachNewNode(debugNode)
        debugNP.show()

        #create bullet world
        self.bulletworld = BulletWorld()
        self.bulletworld.setDebugNode(debugNP.node())
        self.bulletworld.setGravity(Vec3(0, 0, 0))

        #start doing physics
        self.physicsTask = taskMgr.add(self.simulationTask, 'Physics Loop', sort=100)
示例#49
0
文件: gameBase.py 项目: arikel/PPARPG
	def __init__(self, KEY_LIST):
		ShowBase.__init__(self)
		
		#---------------------------------------------------------------
		# clock
		self.globalClock = ClockObject()
		
		#---------------------------------------------------------------
		# KeyHandler
		self.kh = KeyHandler(KEY_LIST)
		
		#---------------------------------------------------------------
		# Bullet
		self.world = BulletWorld()
		self.world.setGravity(Vec3(0, 0, -12.81))
		self.gravityUp = False
		
		self.debugNode = BulletDebugNode('Debug')
		self.debugNode.showWireframe(True)
		self.debugNode.showConstraints(True)
		self.debugNode.showBoundingBoxes(True)
		self.debugNode.showNormals(True)
		self.debugNP = self.render.attachNewNode(self.debugNode)
		#self.debugNP.show()
		self.world.setDebugNode(self.debugNode)
		self._debug = False
		
		#---------------------------------------------------------------
		# Player
		#---------------------------------------------------------------
		# CharacterController
		self.player = CharacterController(self)
		self.player.setActor('models/characters/female', {
				'walk' : 'models/characters/female-walk.egg'
			},
			flip = True,
			pos = (0,0,-1),
			scale = 1.0)
		self.player.setPos(0, -5, 3)
		self.player.playerModel.loop("walk")
		self.playerNp = self.player.np
		
		#---------------------------------------------------------------
		# Camera
		self.camHandler = CamHandler(self)
示例#50
0
    def __init__(self):
        ShowBase.__init__(self)
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
        self.plight = PointLight('plight')
        self.pnlp = self.camera.attachNewNode(self.plight)
        render.setLight(self.pnlp)


        self.debugNode = BulletDebugNode('Debug')
        self.debugNode.showWireframe(True)
        self.debugNode.showConstraints(True)
        self.debugNode.showBoundingBoxes(False)
        self.debugNode.showNormals(False)
        self.debugNP = render.attachNewNode(self.debugNode)
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.setDebugNode(self.debugNode)

        self.planet = Planet()
        self.planet.perlin_terrain(5, 0.5)
        self.planet.build_node_path(render, self.world)

        shape = BulletCapsuleShape(0.25, 0.5)
        node = BulletRigidBodyNode('Capsule')
        node.addShape(shape)
        np = render.attachNewNode(node)
        np.setPos(Vec3(0, 0.8, 0.8)*self.planet.get_radius())
        new_up_vector = Vec3(
            np.getPos() - self.planet.get_node_path().getPos())
        old_up_vector = Vec3(0, 0, 1)
        q = self.__quatFromTo(old_up_vector, new_up_vector)
        np.setQuat(q)
    
        self.np01 = np
        self.world.attachRigidBody(node)

        #node.applyCentralImpulse(Vec3(0.4, 0.6, 1.0))

        self.taskMgr.add(self.physicsUpdateTask, "PhysicsUpdateTask")

        self.accept('arrow_up', self.test01, ["shalala"])
示例#51
0
class Mecha01Client(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
        self.plight = PointLight('plight')
        self.pnlp = self.camera.attachNewNode(self.plight)
        render.setLight(self.pnlp)


        self.debugNode = BulletDebugNode('Debug')
        self.debugNode.showWireframe(True)
        self.debugNode.showConstraints(True)
        self.debugNode.showBoundingBoxes(False)
        self.debugNode.showNormals(False)
        self.debugNP = render.attachNewNode(self.debugNode)
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.setDebugNode(self.debugNode)

        self.planet = Planet()
        self.planet.perlin_terrain(5, 0.5)
        self.planet.build_node_path(render, self.world)

        shape = BulletCapsuleShape(0.25, 0.5)
        node = BulletRigidBodyNode('Capsule')
        node.addShape(shape)
        np = render.attachNewNode(node)
        np.setPos(Vec3(0, 0.8, 0.8)*self.planet.get_radius())
        new_up_vector = Vec3(
            np.getPos() - self.planet.get_node_path().getPos())
        old_up_vector = Vec3(0, 0, 1)
        q = self.__quatFromTo(old_up_vector, new_up_vector)
        np.setQuat(q)
    
        self.np01 = np
        self.world.attachRigidBody(node)

        #node.applyCentralImpulse(Vec3(0.4, 0.6, 1.0))

        self.taskMgr.add(self.physicsUpdateTask, "PhysicsUpdateTask")

        self.accept('arrow_up', self.test01, ["shalala"])

    def test01(self, x):
        print x

    def gravity(self, position):
        down_vector = Vec3(0, 0, 0) - position
        down_vector.normalize()
        gravity = LVector3f(down_vector*9.81)
        
    def physicsUpdateTask(self, task):
        dt = globalClock.getDt()

        # simulating spherical gravity
        node = self.np01.getNode(0)
        pos = self.np01.getPos()
        gravity = self.gravity(pos)
        #self.np01.setQuat(Quat(0, 1.1, 1.1, 0))

        self.world.doPhysics(dt)

        return Task.cont

    def spinCameraTask(self, task):
        # angleDegrees = task.time * 6.0
        # angleRadians = angleDegrees * (pi / 180.0)
        # self.camera.setPos(
        #     100.0 * sin(angleRadians),
        #     -100.0 * cos(angleRadians), 0.0)
        # self.camera.setHpr(angleDegrees, 0, 0)
        self.camera.setPos(self.np01.getPos()*5.0)
        self.camera.lookAt(self.np01)
        return Task.cont

    def __quatFromTo(self, v0, v1):
        print (v0, v1)
        q = Quat(
            sqrt(v0.length()**2 * v1.length()**2) + v0.dot(v1),
            v0.cross(v1))
        q.normalize()
        return q
示例#52
0
class initGame():

    def __init__(self, windowProps, user, connection):
        self.user = user
        self.connection = connection
        render.setShaderAuto()

        self.wp = windowProps
        # keeps the game running the same on all systems (kinda sorta barely)#
        FPS = 60
        globalClock = ClockObject.getGlobalClock()
        globalClock.setMode(ClockObject.MLimited)
        globalClock.setFrameRate(FPS)
        globalClock.setMaxDt(1)

        self.world = BulletWorld()
        self.fakeNode = render.attachNewNode("fakeNode")

        self.initFakeGui()
        self.playIntroLevelMusic()
        self.initBullet()
        self.initScore()
        self.initCollisions()
        self.loadPlayer()
        self.createCamera(self.player.np)
        self.parseLevelFile("Home")
        self.getLevelBounds()
        self.startTime()
        self.createLight()
        self.loadSkyBox()
        self.loadControls()
        #self.parseStory()

        colour = (0.5,0.8,0.8)
        expfog = Fog("Scene-wide exponential Fog object")
        expfog.setColor(*colour)
        expfog.setExpDensity(0.0005)
        render.setFog(expfog)
        base.setBackgroundColor(*colour)

        base.camLens.setFar(1000)

    def playIntroLevelMusic(self):
        self.music = Music("play","./sounds/batfeet.mp3", .1, True)

    def getLevelBounds(self):
        self.levelNodeBounds = render.find("renderDummy").getBounds()

    def parseStory(self):
        self.story = StoryParser("./stories/Story.txt")

    def searchDirectories(self):
        for root, dirs, files in os.walk("./"):
            for name in files:
                if name.endswith((".txt")):
                    print(name)
            for name in dirs:
                if name == "textures":
                    for root, dirs, files in os.walk(name):
                        for name in files:
                            if name.endswith(".jpg"):
                                print(name)
    def initFakeGui(self):
        self.menuBar = OnscreenImage(image = './graphics/MenuBar.png', pos = (0,0,-.94))
        self.userText = OnscreenText(text = self.user, pos = (-1.05, -.9625), scale = 0.1)
        self.menuBar.setScale(1.625, 1, .0625)

    def initScore(self):
        self.scoreHandler = ScoreHandler()

    def initCollisions(self):
        self.collisions = pCollisions(self.scoreHandler, self.music)

    def parseLevelFile(self, arg):
        if arg == "Home":
            self.parsedLevel = LevelParser("./levels/HomeLevel.txt", self.collisions, self.player.np, self.world, self.scoreHandler)

    def startTime(self):
        self.time = KeepTime()

    def initBullet(self):
        self.world.setGravity(Vec3(0, 0, -9.81))

        self.debugNode = BulletDebugNode('Debug')
        self.debugNode.showWireframe(True)
        self.debugNode.showConstraints(True)
        self.debugNode.showBoundingBoxes(False)
        self.debugNode.showNormals(False)

        self.debugNP = render.attachNewNode(self.debugNode)
        self.world.setDebugNode(self.debugNP.node())

    def loadSkyBox(self):
        self.skyBox = SkyBox("Box")

    def createCamera(self, nodePath):
        self.camera = gameCamera(nodePath, self.world, self.collisions)

    def loadControls(self):
        #args order = bullet update loop, bullet debug node, camera, windowProps, player class, spotLightNode, windowProps, timerTask, bulletWorld, collisions#
        self.controlHandler = ControlHandler(self.update, self.debugNP, self.camera, self.wp, self.player, self.time.timerTask, self.world, self.collisions, self.music)

    def loadPlayer(self):
        self.player = Player(self.collisions, "sphere", self.world, self.music, self.scoreHandler)
        #self.player = Player("sphere", self.world, 0, 0, 16)

    def createLight(self):
        self.lightSource = GameLight(self.player.np)

    def update(self, task):
        ##############################################
        #              #BULLET UPDATE#               #
        ##############################################
        dt = globalClock.getDt()
        #self.dtTimer()
        self.world.doPhysics(dt*2, 7)

        #############################################
        #            #CAMERA UPDATE#                #
        #############################################
        self.camera.cn.setPos(self.player.np.getPos())
        #self.fakeNode.setPos(self.player.np.getPos())
        self.camera.hNode.setPos(self.player.np.getPos())
        self.camera.pNode.setPos(self.player.np.getPos())

        self.camera.cn.setP(self.camera.pNode.getP())
        self.camera.cn.setH(self.camera.hNode.getH())

        pointer = base.win.getPointer(0)
        pointerX = pointer.getX()
        pointerY = pointer.getY()

        if base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize ()/2):
            if self.camera.inverted == "yes":
                Pitch = -((pointerY - base.win.getYSize()/2)*.1)
            else:
                Pitch = ((pointerY - base.win.getYSize()/2)*.1)
            Heading = -((pointerX - base.win.getXSize()/2)*.1)

            #endValue = 0
            #endValue += Pitch

            self.camera.pNode.setP(self.camera.pNode, Pitch)
            self.camera.hNode.setH(self.camera.hNode, Heading)

            #self.fakeNode.setH(self.fakeNode, Heading)

        #############################################
        #             #PLAYER UPDATE#               #
        #############################################
        force = Vec3(0, 0, 0)

        if inputState.isSet('up'):
            force.setY(10.0)
        if inputState.isSet('down'):
            force.setY(-10.0)
        if inputState.isSet('left'):
            force.setX(-10.0)
        if inputState.isSet('right'):
            force.setX(10.0)

        #force *= 10
        force = render.getRelativeVector(self.camera.cn, force)

        self.player.np.node().setActive(True)
        self.player.np.node().applyCentralForce(force)
        #self.player.np.setColor(random.random(), random.random(), random.random(), random.random())

        if self.player.np.getZ() < 0 - (self.levelNodeBounds.getRadius() * 6):
            self.player.np.setPos(self.collisions.level.spawn)
            self.player.np.node().setLinearVelocity(Vec3(0,0,0))

        return task.cont
示例#53
0
    # robotplot = nxtplot

    # robot.goinitpose()
    # robot.movearmfk([0.0,-20.0,-60.0,-70.0,-100.0,-30.0,0.0,0.0,0.0])
    # robot.movearmfk([0.0,-20.0,60.0,70.0,-100.0,30.0,0.0,0.0,0.0], armid = 'lft')
    # robotmnp = robotmesh.genmnp(robot)
    # robotmnp.reparentTo(base.render)

    # ur5dualmnp = ur5dualplot.genUr5dualmnp(robot, handpkg)
    # ur5dualmnp.reparentTo(base.render)
    pg.plotAxisSelf(base.render, Vec3(0,0,0))

    cdchecker = CollisionChecker(robotmesh)
    print cdchecker.isSelfCollided(robot)

    bullcldrnp = base.render.attachNewNode("bulletcollider")
    debugNode = BulletDebugNode('Debug')
    debugNode.showWireframe(True)
    debugNode.showConstraints(True)
    debugNode.showBoundingBoxes(False)
    debugNode.showNormals(False)
    debugNP = bullcldrnp.attachNewNode(debugNode)
    debugNP.show()

    cdchecker.bulletworld.setDebugNode(debugNP.node())

    def updateworld(world, task):
        world.doPhysics(globalClock.getDt())
        return task.cont
    base.taskMgr.add(updateworld, "updateworld", extraArgs=[cdchecker.bulletworld], appendTask=True)
    base.run()
示例#54
0
文件: main.py 项目: arikel/PPARPG
	def __init__(self):
		GameBase.__init__(self, KEY_LIST)
		
		FSM.__init__(self, 'Game')
		self.setBackgroundColor(0,0,0)
		
		self.accept("space", self.toggleFPS)
		self.accept("escape", self.taskMgr.stop)
		
		
		'''
		self.shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
 
		self.node = BulletRigidBodyNode('Ground')
		self.node.addShape(self.shape)
		 
		self.np = self.render.attachNewNode(self.node)
		self.np.setPos(0, 0, 0)
		
		self.world.attachRigidBody(self.node)
		'''
		
		self.debugNode = BulletDebugNode('Debug')
		self.debugNode.showWireframe(True)
		self.debugNode.showConstraints(True)
		self.debugNode.showBoundingBoxes(True)
		self.debugNode.showNormals(True)
		self.debugNP = self.render.attachNewNode(self.debugNode)
		self.debugNP.show()
		
		
		self.bulletbox = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

		self.bulletboxnode = BulletRigidBodyNode('Box')
		self.bulletboxnode.setMass(1.0)
		self.bulletboxnode.addShape(self.bulletbox)
		 
		self.bulletboxnp = self.render.attachNewNode(self.bulletboxnode)
		#self.bulletboxnp = NodePath(self.bulletboxnode)
		#self.bulletboxnp.reparentTo(self.render)
		self.bulletboxnp.setPos(0, 0, 15)
		self.bulletboxnp.setScale(5,3,0.5)
		self.world.attachRigidBody(self.bulletboxnode)
		self.model = self.loader.loadModel("models/props/crate.egg")
		self.model.reparentTo(self.bulletboxnp)
		
		
		#---------------------------------------------------------------
		# Ground (StaticTerrain)
		self.ground = StaticTerrain(self, 'models/terrain.jpg', 50)
		self.ground.setTexture(self.loader.loadTexture("models/ground.jpg"))
		
		self.sky = SkyBox(self)
		self.sky.set("teal1")
		
		self.cursor = MouseCursor(self)
		self.cursor.addCursor("cursor2")
		
		self.hideCursor()
		self.lightManager = LightManager(self)
		self.lightManager.addAmbientLight(Vec4(.5,.5,.5,1))
		self.lightManager.addPointLight(Vec4(1.0,1.0,1.0,1.0), Point3(2,-4,5))
		self.taskMgr.add(self.update, "update")
		
		print self.getAspectRatio()
		
		self.camHandler = CamHandler(self)
		self.accept(K_DRAG, self.camHandler.startDrag)
		self.accept(K_DRAG+"-up", self.camHandler.stopDrag)
示例#55
0
class Physics(DirectObject):

    """
    Physics Class:
    
    Handles the all Physics
    """

    def __init__(self):

        ## Setup a bullet world.

        # World Node (MAIN)
        self.worldNP = render.attachNewNode("World")

        # World
        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, worldGravity))
        PHYSICS["WORLD"] = self.world

        # Add the simulation method to the taskmgr
        taskMgr.add(self.update, "update bullet world")

        # Setup test World
        self.box = ""
        self.hinge = ""
        self.pickTest = False
        self.sensor = ""

        # test the class test
        self.test = MakeObject(self, "Box1", "b", 20.0)
        self.test.bodyNP.setPos(0, 1, 1)

        pos = 1

        # for x in range(5):
        # x = MakeObject(self, 'box', 'b', 5.0)
        # pos += 1
        # x.bodyNP.setPos(0, 0, pos)

        self.accept("e", self.playerPickup)
        self.accept("f1", self.showDebug)
        self.setup_world()
        # taskMgr.add(self.checkGhost, 'checkGhost')

    def setup_world(self):

        #############################################
        ##
        ##  GROUND FOR TESTING
        #############################################
        pass
        # Ground
        # shape = BulletPlaneShape(Vec3(0, 0, 1), 0)

        # np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        # np.node().addShape(shape)
        # np.setPos(0, 0, 0)
        # np.setCollideMask(BitMask32.allOn())

        # self.world.attachRigidBody(np.node())

        ##############################################
        ##############################################

        ########################
        # FIXED :D  - Still simple atm.
        ########################

    def playerPickup(self):

        # Write a class for pick able objects so that we instance the object in the world and if picked up we change that instance or del it then create new one, then same again when dropped

        bodyA = base.camera

        # Will have to make a pick up mask so that it collides with walls and floors and w/e else.. except with the player
        if self.pickTest == False:
            self.test.bodyNP.wrtReparentTo(PLAYER["CLASS"].picker)
            # self.test.bodyNP.copyTo(bodyA)
            # self.test.worldNP
            # bodyB.setPos(0, 2, 0)
            self.test.bodyNP.node().setMass(1.0)
            # self.test.bodyNP.setScale(1)
            # self.test.bodyNP.setCollideMask(BitMask32.allOn())
            self.pickTest = True

        elif self.pickTest == True:
            self.test.bodyNP.wrtReparentTo(GAMEPLAY_NODES["ITEM"])
            self.test.bodyNP.node().setMass(1.0)
            # self.test.bodyNP.setCollideMask(BitMask32.allOn())
            # bodyB.setPos(bodyPos)
            self.pickTest = False

        # Simulate Physics

    def update(self, task):

        dt = globalClock.getDt()
        self.world.doPhysics(dt, 4, 1.0 / 270.0)

        return task.cont

        # Enable/Disable debug

    def showDebug(self):

        # To enable debug
        self.debugNode = BulletDebugNode("Debug")
        self.debugNode.showBoundingBoxes(True)
        self.debugNode.showNormals(False)
        self.debugNode.showWireframe(True)
        self.debugNode.showConstraints(True)
        self.debugNP = render.attachNewNode(self.debugNode)
        self.debugNP.show()

        # Add the debug node to the physics world
        self.world.setDebugNode(self.debugNP.node())
示例#56
0
文件: gameBase.py 项目: arikel/PPARPG
class GameBase(ShowBase):
	def __init__(self, KEY_LIST):
		ShowBase.__init__(self)
		
		#---------------------------------------------------------------
		# clock
		self.globalClock = ClockObject()
		
		#---------------------------------------------------------------
		# KeyHandler
		self.kh = KeyHandler(KEY_LIST)
		
		#---------------------------------------------------------------
		# Bullet
		self.world = BulletWorld()
		self.world.setGravity(Vec3(0, 0, -12.81))
		self.gravityUp = False
		
		self.debugNode = BulletDebugNode('Debug')
		self.debugNode.showWireframe(True)
		self.debugNode.showConstraints(True)
		self.debugNode.showBoundingBoxes(True)
		self.debugNode.showNormals(True)
		self.debugNP = self.render.attachNewNode(self.debugNode)
		#self.debugNP.show()
		self.world.setDebugNode(self.debugNode)
		self._debug = False
		
		#---------------------------------------------------------------
		# Player
		#---------------------------------------------------------------
		# CharacterController
		self.player = CharacterController(self)
		self.player.setActor('models/characters/female', {
				'walk' : 'models/characters/female-walk.egg'
			},
			flip = True,
			pos = (0,0,-1),
			scale = 1.0)
		self.player.setPos(0, -5, 3)
		self.player.playerModel.loop("walk")
		self.playerNp = self.player.np
		
		#---------------------------------------------------------------
		# Camera
		self.camHandler = CamHandler(self)
		
		#---------------------------------------------------------------
		# task
		#self.taskMgr.add(self.update, "update")
	
	#---------------------------------------------------------------
	# FPS
	def toggleFPS(self):
		if self.frameRateMeter:
			self.setFrameRateMeter(False)
		else:
			self.setFrameRateMeter(True)
	
	#---------------------------------------------------------------
	# Mouse cursor
	def hideCursor(self):
		props = WindowProperties()
		props.setCursorHidden(True) 
		self.win.requestProperties(props)
	def showCursor(self):
		props = WindowProperties()
		props.setCursorHidden(False)
		self.win.requestProperties(props)
	
	def getObjectHoverName(self):
		if not self.mouseWatcherNode.hasMouse():
			return None
		pMouse = self.mouseWatcherNode.getMouse()
		pFrom = Point3()
		pTo = Point3()
		self.camLens.extrude(pMouse, pFrom, pTo)
		# Transform to global coordinates
		pFrom = self.render.getRelativePoint(self.cam, pFrom)
		pTo = self.render.getRelativePoint(self.cam, pTo)
		result = self.world.rayTestClosest(pFrom, pTo)
		if result.hasHit():
			pos = result.getHitPos()
			name = result.getNode().getName()
			return name
		else:
			return None
		
	def getObjectCenterScreen(self):
		pFrom = Point3()
		pTo = Point3()
		self.camLens.extrude((0,0), pFrom, pTo)
		# Transform to global coordinates
		pFrom = self.render.getRelativePoint(self.cam, pFrom)
		pTo = self.render.getRelativePoint(self.cam, pTo)
		result = self.world.rayTestClosest(pFrom, pTo)
		if result.hasHit():
			pos = result.getHitPos()
			name = result.getNode().getName()
			return name
		else:
			return None
	
	#---------------------------------------------------------------
	# Fog
	def setFog(self):
		myFog = Fog("Fog")
		myFog.setColor((0,0,0,1))
		myFog.setExpDensity(0.025)
		self.render.setFog(myFog)
		self.fog = True
		
	def clearFog(self):
		self.render.clearFog()
		self.fog = False
		
	def toggleFog(self):
		if self.fog:
			self.clearFog()
		else:
			self.setFog()
	
	
	#---------------------------------------------------------------
	# Camera	
	def setFov(self, x):
		self.camLens.setFov(x)
	
	def getFov(self):
		return self.camLens.getFov()[0]
	
	def setNear(self, n):
		self.camLens.setNear(n)
		
	def setFar(self, n):
		self.camLens.setFar(n)
	
	#---------------------------------------------------------------	
	# Physics
	
	def toggleGravity(self):
		if self.gravityUp:
			self.gravityUp = False
			self.world.setGravity(Vec3(0,0,-9.8))
		else:
			self.gravityUp = True
			self.world.setGravity(Vec3(0,0,9.8))
		
	def toggleDebug(self):
		#print "Toggle debug, extraArgs = %s" % (extraArgs)
		if self._debug:
			self._debug = False
			self.debugNP.hide()
		else:
			self._debug = True
			self.debugNP.show()

	def updatePhysics(self, dt):
		#self.world.doPhysics(dt, 20, 1.0/180)
		self.world.doPhysics(dt)
		#cnt = self.world.contactTest(self.ground.node)
		#for boxName in self.objects:
		#	self.objects[boxName].update(dt)
		'''
			cntTest = self.world.contactTest(self.objects[boxName].node)
			cnt = cntTest.getContacts()
			for c in cnt:
				node0 = c.getNode0().getName()
				node1 = c.getNode1().getName()
				#print node0, " in contact with ", node1
		'''
		
	def update(self, task):
		self.globalClock.tick()
		t = self.globalClock.getFrameTime()
		dt = self.globalClock.getDt()
		self.updatePhysics(dt)
		self.player.update(dt)
		return task.cont
	
	def quit(self):
		self.taskMgr.stop()
	
	def stop(self):
		self.taskMgr.stop()
		
	def start(self):
		self.taskMgr.run()