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
# Setup the geometry boxNP = box.copyTo(render) boxNP.setPos(randint(-10, 10), randint(-10, 10), 10 + random()) boxNP.setColor(random(), random(), random(), 1) boxNP.setHpr(0, 45, 0) # Create the body and set the mass boxBody = OdeBody(world) M = OdeMass() M.setBox(20, 1, 1, 1) boxBody.setMass(M) boxBody.setPosition(boxNP.getPos(render)) boxBody.setQuaternion(boxNP.getQuat(render)) # Create a BoxGeom boxGeom = OdeBoxGeom(space, 4, 4, 1) boxGeom.setCollideBits(BitMask32(0x00000002)) boxGeom.setCategoryBits(BitMask32(0x00000001)) boxGeom.setBody(boxBody) boxes.append((boxNP, boxBody)) boxNP2 = box.copyTo(render) boxNP2.reparentTo(boxNP) boxNP2.setPos(0.5, 0.5, 0) boxNP2.setScale(0.1, 0.1, 4) boxBody2 = OdeBody(world) M2 = OdeMass() M2.setBox(150, 0.1, 0.1, 2) boxBody2.setMass(M2)
boxNP = box.copyTo(render) # boxNP.setPos(randint(-10, 10), randint(-10, 10), 10 + random()) boxNP.setPos(random() * 10, random() * 10, 10 + random()) boxNP.setColor(random(), random(), random(), 1) boxNP.setHpr(randint(-45, 45), randint(-45, 45), randint(-45, 45)) # Create the body and set the mass boxBody = OdeBody(world) M = OdeMass() M.setBox(5, 1, 1, 1) boxBody.setMass(M) boxBody.setPosition(boxNP.getPos(render)) 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))