コード例 #1
0
    def __init__(self,
                 world,
                 parent,
                 pos,
                 dir,
                 width,
                 height,
                 color,
                 name,
                 textureFilename=None):
        self.node = parent.attachNewNode("")
        self.node.setPos(*pos)
        self.node.lookAt(self.node, *dir)
        self.name = name

        divisions = 1
        for i in range(divisions):
            for j in range(divisions):
                self.makeCard(color, width, height, i, j, divisions)

        if textureFilename == None:
            self.texture = None
        else:
            self.texture = loader.loadTexture(textureFilename)
            self.texture.setWrapU(Texture.WMRepeat)
            self.texture.setWrapV(Texture.WMRepeat)
            self.node.setTexture(self.texture)
            self.node.setTexScale(TextureStage.getDefault(), 0.5, 0.5)

        self.geom = OdePlaneGeom(world.space,
                                 makeVec4FromPointAndNormal(pos, dir))
        world.space.setSurfaceType(self.geom, world.surfaces["plane"])
コード例 #2
0
 def setupSimulation(self):
     DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.setupSimulation(
         self)
     self.world.setGravity(0, 0, -32.173999999999999)
     self.world.setAutoDisableFlag(1)
     self.world.setAutoDisableLinearThreshold(0.5 * MetersToFeet)
     self.world.setAutoDisableAngularThreshold(OdeUtil.getInfinity())
     self.world.setAutoDisableSteps(10)
     self.world.setCfm(1.0000000000000001e-005 * MetersToFeet)
     self.world.initSurfaceTable(3)
     self.world.setSurfaceEntry(0, 1, 0.20000000000000001, 0, 0, 0, 0, 0,
                                0.10000000000000001)
     self.world.setSurfaceEntry(0, 0, 0.10000000000000001,
                                0.90000000000000002, 0.10000000000000001, 0,
                                0, 0, 0)
     self.world.setSurfaceEntry(0, 2, 0.90000000000000002,
                                0.90000000000000002, 0.10000000000000001, 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
コード例 #3
0
    def setupSimulation(self):
        """Setup the ice game specific parameters."""
        DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.setupSimulation(
            self)
        # toontown uses feet, 1 meter = 3.2808399 feet
        # for this game lets express mass in kilograms
        # so gravity at 9.8 meters per seconds squared becomes
        self.world.setGravity(0, 0, -32.174)

        # ODE's default is meter, kilograms, seconds, let's change the defaults
        # do we need to change global ERP value,
        # that controls how much error correction is performed in each time step
        # default is 0.2
        self.world.setAutoDisableFlag(1)  # lets try auto disable
        self.world.setAutoDisableLinearThreshold(0.5 * MetersToFeet)
        # skipping AutoDisableAngularThreshold as that is radians per second
        # self.world.setAutoDisableAngularThreshold(0.01)
        # don't consider rotation for auto disable
        self.world.setAutoDisableAngularThreshold(OdeUtil.getInfinity())
        self.world.setAutoDisableSteps(10)

        # Set and the global CFM (constraint force mixing) value.
        # Typical values are in the range 10-9 -- 1.
        # The default is 10-5 if single precision is being used
        self.world.setCfm(1E-5 * MetersToFeet)

        # Our surfaces
        # 0 = tire
        # 1 = ice
        # 2 = fence
        self.world.initSurfaceTable(3)  # 3 types of surfaces

        # PN_uint8 pos1, PN_uint8 pos2,  - surface0, surface1
        #            dReal mu, - 0 frictionless, 1 infinite friction
        #            dReal bounce, # Restitution parameter 0 not bouncy, 1 max bouncy
        #            dReal bounce_vel, #The minimum incoming velocity necessary for bounce.
        #                              Incoming velocities below this will
        #                              effectively have a bounce parameter of 0.
        #            dReal soft_erp, # Contact normal "softness" parameter.
        #            dReal soft_cfm, # Contact normal "softness" paramete
        #            dReal slip,     # The coefficients of force-dependent-slip (FDS)
        #            dReal dampen)   # dampening constant

        # the most usual collision, tire against ice
        self.world.setSurfaceEntry(
            0,
            1,
            0.2,  # near frictionless
            0,  # not bouncy
            0,  # bounce_vel
            0,  # soft_erp
            0,  # soft_cfm
            0,  # slip
            0.1,  # dampen
        )
        # tire against tire
        self.world.setSurfaceEntry(
            0,
            0,
            0.1,  # friction
            0.9,  # bounciness
            0.1,  # bounce_vel
            0,  # soft_erp
            0,  # soft_cfm
            0,  # slip
            0,  # dampen
        )

        # tire against fence
        self.world.setSurfaceEntry(
            0,
            2,
            0.9,  # friction
            0.9,  # bounciness
            0.1,  # bounce_vel
            0,  # soft_erp
            0,  # soft_cfm
            0,  # slip
            0,  # dampen
        )

        # Create a plane geom which prevent the objects from falling forever
        self.floor = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, -20.0))
        self.floor.setCollideBits(
            self.allTiresMask)  # we only collide against tires
        self.floor.setCategoryBits(self.floorMask)

        # normal pointing towards +x axis
        self.westWall = OdePlaneGeom(
            self.space, Vec4(1.0, 0.0, 0.0, IceGameGlobals.MinWall[0]))
        self.westWall.setCollideBits(
            self.allTiresMask)  # we only collide against tires
        self.westWall.setCategoryBits(self.wallMask)
        self.space.setSurfaceType(self.westWall, self.fenceSurfaceType)
        self.space.setCollideId(self.westWall, self.wallCollideId)

        # normal pointing towards -x axis
        self.eastWall = OdePlaneGeom(
            self.space, Vec4(-1.0, 0.0, 0.0, -IceGameGlobals.MaxWall[0]))
        self.eastWall.setCollideBits(
            self.allTiresMask)  # we only collide against tires
        self.eastWall.setCategoryBits(self.wallMask)
        self.space.setSurfaceType(self.eastWall, self.fenceSurfaceType)
        self.space.setCollideId(self.eastWall, self.wallCollideId)

        # normal pointing toward the +y axis
        self.southWall = OdePlaneGeom(
            self.space, Vec4(0.0, 1.0, 0.0, IceGameGlobals.MinWall[1]))
        self.southWall.setCollideBits(
            self.allTiresMask)  # we only collide against tires
        self.southWall.setCategoryBits(self.wallMask)
        self.space.setSurfaceType(self.southWall, self.fenceSurfaceType)
        self.space.setCollideId(self.southWall, self.wallCollideId)

        # normal pointing toward the -y axis
        self.northWall = OdePlaneGeom(
            self.space, Vec4(0.0, -1.0, 0.0, -IceGameGlobals.MaxWall[1]))
        self.northWall.setCollideBits(
            self.allTiresMask)  # we only collide against tires
        self.northWall.setCategoryBits(self.wallMask)
        self.space.setSurfaceType(self.northWall, self.fenceSurfaceType)
        self.space.setCollideId(self.northWall, self.wallCollideId)

        # a temporary floor at z=0, until we implement ice with holes
        self.floorTemp = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, 0.0))
        self.floorTemp.setCollideBits(
            self.allTiresMask)  # we only collide against tires
        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
コード例 #4
0
ファイル: ode.py プロジェクト: gurgelff/Bast
  # Create a ballGeom
  ballGeom = OdeSphereGeom(space, 1)
  ballGeom.setCollideBits(BitMask32(0x00000001))
  ballGeom.setCategoryBits(BitMask32(0x00000001))
  ballGeom.setBody(ballBody)
  # Create the sound
  ballSound = loader.loadSfx("audio/sfx/GUI_rollover.wav")
  balls.append((ballNP, ballGeom, ballSound))

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

# Add a texture to the ground
groundImage = PNMImage(512, 512)
groundImage.fill(1, 1, 1)
groundBrush = PNMBrush.makeSpot((0, 0, 0, 1), 8, True)
groundPainter = PNMPainter(groundImage)
groundPainter.setPen(groundBrush)
groundTexture = Texture("ground")
ground.setTexture(groundTexture)
groundImgChanged = False

# Set the camera position
base.disableMouse()