Example #1
0
    def __init__(self, app):
        ElementPlat.__init__(self, app, "terrain", "modeles/floor/floor.png")

        # Modification de la rotation du terrain
        self.set_rotation(180, 270, 0)

        # Modification de la taille du terrain
        self.set_taille(28 / 2.0, 14.5, 15)

        # Creation d'un element geometrique plat
        self.geom = OdePlaneGeom(self.app.monde.espace, Vec4(0, 0, 1, 0))

        # Defini les parametres de collision
        self.geom.setCollideBits(BitMask32(0x00000001))
        self.geom.setCategoryBits(BitMask32(0x00000002))
Example #2
0
 def add_ground(self):
     cm = CardMaker("ground")
     cm.setFrame(-1, 1, -1, 1)
     ground = render.attachNewNode(cm.generate())
     ground.setColor(0.5, 0.7, 0.8)
     ground.lookAt(0, 0, -1)
     groundGeom = OdePlaneGeom(self.space, Vec4(0, 0, 1, 0))
Example #3
0
    def __init__(self):
        #init the world
        self.world = OdeWorld()
        self.world.setGravity(0, 0, -9.81)
        #init the friction 
        self.world.initSurfaceTable(1)
        
        surfaceId1 = 0
        surfaceId2 = 0
        mu = 500
        bounce = 0. # 2
        bounce_vel = 0.1
        soft_erp = 0.9
        soft_cfm = 0.00001
        slip = 0.0
        dampen = 0.002

        
        self.world.setSurfaceEntry(
                surfaceId1,
                surfaceId2,
                mu,
                bounce,
                bounce_vel,
                soft_erp,
                soft_cfm,
                slip,
                dampen)
        
        #init the collision space
        self.space = OdeSimpleSpace()
        self.space.setAutoCollideWorld(self.world)
        self.contactgroup = OdeJointGroup()
        self.space.setAutoCollideJointGroup(self.contactgroup)
     
        self.servogroup = OdeJointGroup()
        #cm = CardMaker("ground")
        #cm.setFrame(-20, 20, -20, 20)
        #ground = render.attachNewNode(cm.generate())
        #ground.setPos(0, 0, 0); ground.lookAt(0, 0, -1)
        # Ground definition
        self.groundGeom = OdePlaneGeom(self.space, Vec4(0, 0, 1, 0))
        self.groundGeom.setCollideBits(BitMask32(0x00000001))
        self.groundGeom.setCategoryBits(BitMask32(0x00000002))

        self.deltaTimeAccumulator = 0.0 
        self.stepSize = 0.01
M2 = OdeMass()
M2.setBox(150, 0.1, 0.1, 2)
boxBody2.setMass(M2)

smileyJoint = OdeBallJoint(world)
smileyJoint.attach(boxBody2, boxBody) # Attach it to the environment
smileyJoint.setAnchor(0, 0, 2)


 
# Add a plane to collide with
cm = CardMaker("ground")
cm.setFrame(-20, 20, -20, 20)
ground = render.attachNewNode(cm.generate())
ground.setPos(0, 0, 0); ground.lookAt(0, 0, -1)
groundGeom = OdePlaneGeom(space, Vec4(0, 0, 1, 0))
groundGeom.setCollideBits(BitMask32(0x00000001))
groundGeom.setCategoryBits(BitMask32(0x00000002))
 
# Set the camera position
base.disableMouse()
base.camera.setPos(40, 40, 20)
base.camera.lookAt(0, 0, 0)
 
# The task for our simulation
def simulationTask(task):
  space.autoCollide() # Setup the contact joints
  # Step the simulation and set the new positions
  world.quickStep(globalClock.getDt())
  for np, body in boxes:
    np.setPosQuat(render, body.getPosition(), Quat(body.getQuaternion()))
Example #5
0
    boxBody.setQuaternion(boxNP.getQuat(render))
    # Create a BoxGeom
    boxGeom = OdeBoxGeom(space, 1, 1, 1)
    # boxGeom = OdeTriMeshGeom(space, OdeTriMeshData(boxNP, True))
    boxGeom.setCollideBits(BitMask32(0x00000002))
    boxGeom.setCategoryBits(BitMask32(0x00000001))
    boxGeom.setBody(boxBody)
    boxes.append((boxNP, boxBody))

# Add a plane to collide with
cm = CardMaker("ground")
cm.setFrame(-20, 20, -20, 20)
ground = render.attachNewNode(cm.generate())
ground.setPos(0, 0, 0)
ground.lookAt(0, 0, -1)
groundGeom = OdePlaneGeom(space, Vec4(0, 0, 1, 0))
# groundGeom = OdeTriMeshGeom(space, OdeTriMeshData(ground, True))
groundGeom.setCollideBits(BitMask32(0x00000001))
groundGeom.setCategoryBits(BitMask32(0x00000002))

# Set the camera position
base.disableMouse()
base.camera.setPos(40, 40, 20)
base.camera.lookAt(0, 0, 0)


# The task for our simulation
def simulationTask(task):
    space.autoCollide()  # Setup the contact joints
    # Step the simulation and set the new positions
    world.quickStep(globalClock.getDt())
Example #6
0
class DistributedIceWorld(DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld):
    notify = DirectNotifyGlobal.directNotify.newCategory('DistributedMinigamePhysicsWorld')
    floorCollideId = 1
    floorMask = BitMask32(floorCollideId)
    wallCollideId = 1 << 1
    wallMask = BitMask32(wallCollideId)
    obstacleCollideId = 1 << 2
    obstacleMask = BitMask32(obstacleCollideId)
    tireCollideIds = [1 << 8,
     1 << 9,
     1 << 10,
     1 << 11]
    tire0Mask = BitMask32(tireCollideIds[0])
    tire1Mask = BitMask32(tireCollideIds[1])
    tire2Mask = BitMask32(tireCollideIds[2])
    tire3Mask = BitMask32(tireCollideIds[3])
    allTiresMask = tire0Mask | tire1Mask | tire2Mask | tire3Mask
    tireMasks = (tire0Mask,
     tire1Mask,
     tire2Mask,
     tire3Mask)
    tireDensity = 1
    tireSurfaceType = 0
    iceSurfaceType = 1
    fenceSurfaceType = 2

    def __init__(self, cr):
        DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.__init__(self, cr)

    def delete(self):
        DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.delete(self)
        if hasattr(self, 'floor'):
            self.floor = None
        return

    def setupSimulation(self):
        DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.setupSimulation(self)
        self.world.setGravity(0, 0, -32.174)
        self.world.setAutoDisableFlag(1)
        self.world.setAutoDisableLinearThreshold(0.5 * MetersToFeet)
        self.world.setAutoDisableAngularThreshold(OdeUtil.getInfinity())
        self.world.setAutoDisableSteps(10)
        self.world.setCfm(1e-05 * MetersToFeet)
        self.world.initSurfaceTable(3)
        self.world.setSurfaceEntry(0, 1, 0.2, 0, 0, 0, 0, 0, 0.1)
        self.world.setSurfaceEntry(0, 0, 0.1, 0.9, 0.1, 0, 0, 0, 0)
        self.world.setSurfaceEntry(0, 2, 0.9, 0.9, 0.1, 0, 0, 0, 0)
        self.floor = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, -20.0))
        self.floor.setCollideBits(self.allTiresMask)
        self.floor.setCategoryBits(self.floorMask)
        self.westWall = OdePlaneGeom(self.space, Vec4(1.0, 0.0, 0.0, IceGameGlobals.MinWall[0]))
        self.westWall.setCollideBits(self.allTiresMask)
        self.westWall.setCategoryBits(self.wallMask)
        self.space.setSurfaceType(self.westWall, self.fenceSurfaceType)
        self.space.setCollideId(self.westWall, self.wallCollideId)
        self.eastWall = OdePlaneGeom(self.space, Vec4(-1.0, 0.0, 0.0, -IceGameGlobals.MaxWall[0]))
        self.eastWall.setCollideBits(self.allTiresMask)
        self.eastWall.setCategoryBits(self.wallMask)
        self.space.setSurfaceType(self.eastWall, self.fenceSurfaceType)
        self.space.setCollideId(self.eastWall, self.wallCollideId)
        self.southWall = OdePlaneGeom(self.space, Vec4(0.0, 1.0, 0.0, IceGameGlobals.MinWall[1]))
        self.southWall.setCollideBits(self.allTiresMask)
        self.southWall.setCategoryBits(self.wallMask)
        self.space.setSurfaceType(self.southWall, self.fenceSurfaceType)
        self.space.setCollideId(self.southWall, self.wallCollideId)
        self.northWall = OdePlaneGeom(self.space, Vec4(0.0, -1.0, 0.0, -IceGameGlobals.MaxWall[1]))
        self.northWall.setCollideBits(self.allTiresMask)
        self.northWall.setCategoryBits(self.wallMask)
        self.space.setSurfaceType(self.northWall, self.fenceSurfaceType)
        self.space.setCollideId(self.northWall, self.wallCollideId)
        self.floorTemp = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, 0.0))
        self.floorTemp.setCollideBits(self.allTiresMask)
        self.floorTemp.setCategoryBits(self.floorMask)
        self.space.setSurfaceType(self.floorTemp, self.iceSurfaceType)
        self.space.setCollideId(self.floorTemp, self.floorCollideId)
        self.space.setAutoCollideWorld(self.world)
        self.space.setAutoCollideJointGroup(self.contactgroup)
        self.totalPhysicsSteps = 0

    def createTire(self, tireIndex):
        if tireIndex < 0 or tireIndex >= len(self.tireMasks):
            self.notify.error('invalid tireIndex %s' % tireIndex)
        self.notify.debug('create tireindex %s' % tireIndex)
        zOffset = 0
        body = OdeBody(self.world)
        mass = OdeMass()
        mass.setSphere(self.tireDensity, IceGameGlobals.TireRadius)
        body.setMass(mass)
        body.setPosition(IceGameGlobals.StartingPositions[tireIndex][0], IceGameGlobals.StartingPositions[tireIndex][1], IceGameGlobals.StartingPositions[tireIndex][2])
        body.setAutoDisableDefaults()
        geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius)
        self.space.setSurfaceType(geom, self.tireSurfaceType)
        self.space.setCollideId(geom, self.tireCollideIds[tireIndex])
        self.massList.append(mass)
        self.geomList.append(geom)
        geom.setCollideBits(self.allTiresMask | self.wallMask | self.floorMask | self.obstacleMask)
        geom.setCategoryBits(self.tireMasks[tireIndex])
        geom.setBody(body)
        if self.notify.getDebug():
            self.notify.debug('tire geom id')
            geom.write()
            self.notify.debug(' -')
        if self.canRender:
            testTire = render.attachNewNode('tire holder %d' % tireIndex)
            smileyModel = NodePath()
            if not smileyModel.isEmpty():
                smileyModel.setScale(IceGameGlobals.TireRadius)
                smileyModel.reparentTo(testTire)
                smileyModel.setAlphaScale(0.5)
                smileyModel.setTransparency(1)
            testTire.setPos(IceGameGlobals.StartingPositions[tireIndex])
            tireModel = loader.loadModel('phase_4/models/minigames/ice_game_tire')
            tireHeight = 1
            tireModel.setZ(-IceGameGlobals.TireRadius + 0.01)
            tireModel.reparentTo(testTire)
            self.odePandaRelationList.append((testTire, body))
        else:
            testTire = None
            self.bodyList.append((None, body))
        return (testTire, body, geom)

    def placeBodies(self):
        for pair in self.odePandaRelationList:
            pandaNodePathGeom = pair[0]
            odeBody = pair[1]
            if pandaNodePathGeom:
                pandaNodePathGeom.setPos(odeBody.getPosition())
                pandaNodePathGeom.setQuat(Quat(odeBody.getQuaternion()[0], odeBody.getQuaternion()[1], odeBody.getQuaternion()[2], odeBody.getQuaternion()[3]))
                pandaNodePathGeom.setP(0)
                pandaNodePathGeom.setR(0)
                newQuat = pandaNodePathGeom.getQuat()
                odeBody.setQuaternion(newQuat)

    def postStep(self):
        DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.postStep(self)
        self.placeBodies()
        self.totalPhysicsSteps += 1

    def createObstacle(self, pos, obstacleIndex, cubicObstacle):
        if cubicObstacle:
            return self.createCubicObstacle(pos, obstacleIndex)
        else:
            return self.createCircularObstacle(pos, obstacleIndex)

    def createCircularObstacle(self, pos, obstacleIndex):
        self.notify.debug('create obstacleindex %s' % obstacleIndex)
        geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius)
        geom.setCollideBits(self.allTiresMask)
        geom.setCategoryBits(self.obstacleMask)
        self.space.setCollideId(geom, self.obstacleCollideId)
        tireModel = loader.loadModel('phase_4/models/minigames/ice_game_tirestack')
        tireHeight = 1
        tireModel.setPos(pos)
        tireModel.reparentTo(render)
        geom.setPosition(tireModel.getPos())
        tireModel.setZ(0)
        return tireModel

    def createCubicObstacle(self, pos, obstacleIndex):
        self.notify.debug('create obstacleindex %s' % obstacleIndex)
        sideLength = IceGameGlobals.TireRadius * 2
        geom = OdeBoxGeom(self.space, sideLength, sideLength, sideLength)
        geom.setCollideBits(self.allTiresMask)
        geom.setCategoryBits(self.obstacleMask)
        self.space.setCollideId(geom, self.obstacleCollideId)
        tireModel = loader.loadModel('phase_4/models/minigames/ice_game_crate')
        tireModel.setPos(pos)
        tireModel.reparentTo(render)
        geom.setPosition(tireModel.getPos())
        tireModel.setZ(0)
        return tireModel
Example #7
0
 def setupSimulation(self):
     DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.setupSimulation(self)
     self.world.setGravity(0, 0, -32.174)
     self.world.setAutoDisableFlag(1)
     self.world.setAutoDisableLinearThreshold(0.5 * MetersToFeet)
     self.world.setAutoDisableAngularThreshold(OdeUtil.getInfinity())
     self.world.setAutoDisableSteps(10)
     self.world.setCfm(1e-05 * MetersToFeet)
     self.world.initSurfaceTable(3)
     self.world.setSurfaceEntry(0, 1, 0.2, 0, 0, 0, 0, 0, 0.1)
     self.world.setSurfaceEntry(0, 0, 0.1, 0.9, 0.1, 0, 0, 0, 0)
     self.world.setSurfaceEntry(0, 2, 0.9, 0.9, 0.1, 0, 0, 0, 0)
     self.floor = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, -20.0))
     self.floor.setCollideBits(self.allTiresMask)
     self.floor.setCategoryBits(self.floorMask)
     self.westWall = OdePlaneGeom(self.space, Vec4(1.0, 0.0, 0.0, IceGameGlobals.MinWall[0]))
     self.westWall.setCollideBits(self.allTiresMask)
     self.westWall.setCategoryBits(self.wallMask)
     self.space.setSurfaceType(self.westWall, self.fenceSurfaceType)
     self.space.setCollideId(self.westWall, self.wallCollideId)
     self.eastWall = OdePlaneGeom(self.space, Vec4(-1.0, 0.0, 0.0, -IceGameGlobals.MaxWall[0]))
     self.eastWall.setCollideBits(self.allTiresMask)
     self.eastWall.setCategoryBits(self.wallMask)
     self.space.setSurfaceType(self.eastWall, self.fenceSurfaceType)
     self.space.setCollideId(self.eastWall, self.wallCollideId)
     self.southWall = OdePlaneGeom(self.space, Vec4(0.0, 1.0, 0.0, IceGameGlobals.MinWall[1]))
     self.southWall.setCollideBits(self.allTiresMask)
     self.southWall.setCategoryBits(self.wallMask)
     self.space.setSurfaceType(self.southWall, self.fenceSurfaceType)
     self.space.setCollideId(self.southWall, self.wallCollideId)
     self.northWall = OdePlaneGeom(self.space, Vec4(0.0, -1.0, 0.0, -IceGameGlobals.MaxWall[1]))
     self.northWall.setCollideBits(self.allTiresMask)
     self.northWall.setCategoryBits(self.wallMask)
     self.space.setSurfaceType(self.northWall, self.fenceSurfaceType)
     self.space.setCollideId(self.northWall, self.wallCollideId)
     self.floorTemp = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, 0.0))
     self.floorTemp.setCollideBits(self.allTiresMask)
     self.floorTemp.setCategoryBits(self.floorMask)
     self.space.setSurfaceType(self.floorTemp, self.iceSurfaceType)
     self.space.setCollideId(self.floorTemp, self.floorCollideId)
     self.space.setAutoCollideWorld(self.world)
     self.space.setAutoCollideJointGroup(self.contactgroup)
     self.totalPhysicsSteps = 0
Example #8
0
    boxBody.setPosition(boxNP.getPos(render))
    boxBody.setQuaternion(boxNP.getQuat(render))
    # Create a BoxGeom
    boxGeom = OdeBoxGeom(space, 1, 1, 1)
    boxGeom.setCollideBits(BitMask32(0x00000002))
    boxGeom.setCategoryBits(BitMask32(0x00000001))
    boxGeom.setBody(boxBody)
    boxes.append((boxNP, boxBody))

# Add a plane to collide with
cm = CardMaker("ground")
cm.setFrame(-20, 20, -20, 20)
ground = render.attachNewNode(cm.generate())
ground.setPos(0, 0, 0)
ground.lookAt(0, 0, -1)
groundGeom = OdePlaneGeom(space, Vec4(0, 0, 1, 0))
# groundGeom.setCollideBits(BitMask32(0x00000001))
# groundGeom.setCategoryBits(BitMask32(0x00000002))

# Set the camera position
base.disableMouse()
base.camera.setPos(40, 40, 20)
base.camera.lookAt(0, 0, 0)


# The task for our simulation
def simulationTask(task):
    space.autoCollide()  # Setup the contact joints
    # Step the simulation and set the new positions
    world.quickStep(globalClock.getDt())
    for np, body in boxes:
Example #9
0
class Physics():
    def __init__(self):
        #init the world
        self.world = OdeWorld()
        self.world.setGravity(0, 0, -9.81)
        #init the friction 
        self.world.initSurfaceTable(1)
        
        surfaceId1 = 0
        surfaceId2 = 0
        mu = 500
        bounce = 0. # 2
        bounce_vel = 0.1
        soft_erp = 0.9
        soft_cfm = 0.00001
        slip = 0.0
        dampen = 0.002

        
        self.world.setSurfaceEntry(
                surfaceId1,
                surfaceId2,
                mu,
                bounce,
                bounce_vel,
                soft_erp,
                soft_cfm,
                slip,
                dampen)
        
        #init the collision space
        self.space = OdeSimpleSpace()
        self.space.setAutoCollideWorld(self.world)
        self.contactgroup = OdeJointGroup()
        self.space.setAutoCollideJointGroup(self.contactgroup)
     
        self.servogroup = OdeJointGroup()
        #cm = CardMaker("ground")
        #cm.setFrame(-20, 20, -20, 20)
        #ground = render.attachNewNode(cm.generate())
        #ground.setPos(0, 0, 0); ground.lookAt(0, 0, -1)
        # Ground definition
        self.groundGeom = OdePlaneGeom(self.space, Vec4(0, 0, 1, 0))
        self.groundGeom.setCollideBits(BitMask32(0x00000001))
        self.groundGeom.setCategoryBits(BitMask32(0x00000002))

        self.deltaTimeAccumulator = 0.0 
        self.stepSize = 0.01

    # The task for our simulation
    def simulationTask(self, creatures, dt=0):
        # Add the deltaTime for the task to the accumulator
        self.stepSize = dt
        for c in creatures:
            c.update_angles(dt)
            c.draw()
            #model.setPosQuat(render, body.getPosition(), Quat(body.getQuaternion()))
        if dt == 0:
            self.deltaTimeAccumulator += globalClock.getDt()
        else:
            self.deltaTimeAccumulator = dt
        #while self.deltaTimeAccumulator > self.stepSize:
            # Remove a stepSize from the accumulator until
            # the accumulated time is less than the stepsize
           # self.deltaTimeAccumulator -= self.stepSize
            # Step the simulation
            self.space.autoCollide()  # Setup the contact joints
            self.world.quickStep(self.stepSize)
            # set the new positions
            self.contactgroup.empty() # Clear the contact joints
    
    def run_physics(self, t, creatures):
        """ run physics for t steps """
        for i in range(t):
            self.simulationTask(creatures, 0.01)