def __init__(self, world, loc = Point3()): """ the location is the bottom-left corner of the platform """ mass = OdeMass() mass.setBox(1000, 2, 2, 2) geom = OdeBoxGeom(world.space, 2, 2, 2) super(Block, self).__init__(world, mass, geom, "block", loc, False)
def create_robot(self): bot = DynamicObject() bot.model = loader.loadModel('data/QuadRotor') bot.model.reparentTo(render) bot.model.setPos(1.29,0.7,2.5) bot.body = OdeBody(self.world) M = OdeMass() M.setBox(5,0.6,0.45,0.15) bot.body.setMass(M) bot.body.setPosition(bot.model.getPos(render)) bot.body.setQuaternion(bot.model.getQuat(render)) bot.geom = OdeBoxGeom(self.space, 0.6,0.45,0.15) bot.geom.setCollideBits(BitMask32(0x00000001)) bot.geom.setCategoryBits(BitMask32(0x00000001)) bot.geom.setBody(bot.body) self.obj_list.append(bot) cube = sf.makeCube(self,1,1,1,5) cube.setpos((1.2,1,1.5)) self.obj_list.append(cube)
def __init__(self, world, loc = Point3()): """ the location is the bottom-left corner of the platform """ geom = OdeBoxGeom(world.space, 2,5,2) mass = OdeMass() mass.setBox(1000, 2, 5, 2) super(Player, self).__init__(world, mass, geom, "player", loc, False) self.setRevertable(False) self.key = {"left": False, "right": False} self.direction = 0 self.speed = 13 self.accept("player_left_down", self.setKey, ["left", True]) self.accept("player_left_up", self.setKey, ["left", False]) self.accept("player_right_down", self.setKey, ["right", True]) self.accept("player_right_up", self.setKey, ["right", False]) self.accept("player_jump", self.jump)
# Add a random amount of boxes boxes = [] # 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)
box.flattenLight() # Apply transform box.setTextureOff() # Add a random amount of boxes boxes = [] for i in range(randint(5, 10)): # Setup the geometry 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())
box.setScale(0.05, 0.05, 0.05) box.flattenLight() # Apply transform box.setTextureOff() # Add a random amount of boxes boxes = [] for i in range(randint(1, 1)): # 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(randint(-45, 45), randint(-45, 45), randint(-45, 45)) # Create the body and set the mass boxBody = OdeBody(world) M = OdeMass() M.setBox(50, 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.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)
for i in range(randint(5, 10)): # Setup the geometry new_box = box.copy() new_box.set_pos( np.array([random() * 10 - 5, random() * 10 - 5, 1 + random()])) new_box.set_rgba([random(), random(), random(), 1]) new_box.set_rotmat( rm.rotmat_from_euler(random() * math.pi / 4, random() * math.pi / 4, random() * math.pi / 4)) new_box.attach_to(base) # Create the body and set the mass boxBody = OdeBody(world) M = OdeMass() M.setBox(3, .3, .3, .3) boxBody.setMass(M) boxBody.setPosition(da.npv3_to_pdv3(new_box.get_pos())) boxBody.setQuaternion(da.npmat3_to_pdquat(new_box.get_rotmat())) # Create a BoxGeom boxGeom = OdeBoxGeom(space, .3, .3, .3) # boxGeom = OdeTriMeshGeom(space, OdeTriMeshData(new_box.objpdnp, True)) boxGeom.setCollideBits(BitMask32(0x00000002)) boxGeom.setCategoryBits(BitMask32(0x00000001)) boxGeom.setBody(boxBody) boxes.append((new_box, boxBody)) # Add a plane to collide with ground = cm.gen_box(extent=[20, 20, 1], rgba=[.3, .3, .3, 1]) ground.set_pos(np.array([0, 0, -1.5])) ground.attach_to(base)