class Sphere(GameObject): def __init__(self, world, parent, color, pos, dir, radius, density, posParent=None): GameObject.__init__(self, world) self.node = parent.attachNewNode("") if posParent == None: self.node.setPos(*pos) else: self.node.setPos(posParent, *pos) self.node.setColor(*color) self.node.setScale(radius) self.node.lookAt(self.node, *dir) self.parent = parent self.color = color self.scale = radius self.model = loader.loadModel("models/smiley.egg") self.model.reparentTo(self.node) self.mass = OdeMass() self.mass.setSphere(density, radius) self.body = OdeBody(world.world) self.body.setMass(self.mass) self.body.setPosition(self.node.getPos()) self.body.setQuaternion(self.node.getQuat()) self.body.setData(self) self.geom = OdeSphereGeom(world.space, radius) self.geom.setBody(self.body) world.space.setSurfaceType(self.geom, world.surfaces["sphere"]) def onCollision(self, otherBody, entry): if otherBody.isEmpty(): # Collision on a wall geom = entry.getContactGeom(0) Ripple(self.parent, self.color, geom.getPos(), geom.getNormal() * -1, self.scale * 2.5)
def createBallBody(self, modelNode, world): ballBody = OdeBody(world) M = OdeMass() M.setSphere(Ball.BALL_BODY_MASS_WEIGHT, Ball.BALL_BODY_MASS_RADIUS) ballBody.setMass(M) ballBody.setPosition(modelNode.getPos(render)) ballBody.setQuaternion(modelNode.getQuat(render)) return ballBody
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 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 createTire(self, tireIndex): """Create one physics tire. Returns a (nodePath, OdeBody, OdeGeom) tuple""" if (tireIndex < 0) or (tireIndex >= len(self.tireMasks)): self.notify.error('invalid tireIndex %s' % tireIndex) self.notify.debug("create tireindex %s" % (tireIndex)) zOffset = 0 # for now the tires are spheres 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.setAutoDisableFlag(1) #body.setAutoDisableLinearThreshold(1.01 * MetersToFeet) # skipping AutoDisableAngularThreshold as that is radians per second #body.setAutoDisableAngularThreshold(0.1) 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) # a tire collides against other tires, the wall and the floor 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( ) # loader.loadModel('models/misc/smiley') # smiley! if not smileyModel.isEmpty(): smileyModel.setScale(IceGameGlobals.TireRadius) smileyModel.reparentTo(testTire) smileyModel.setAlphaScale(0.5) smileyModel.setTransparency(1) testTire.setPos(IceGameGlobals.StartingPositions[tireIndex]) #debugAxis = loader.loadModel('models/misc/xyzAxis') if 0: #not debugAxis.isEmpty(): debugAxis.reparentTo(testTire) debugAxis.setScale(IceGameGlobals.TireRadius / 10.0) debugAxis2 = loader.loadModel('models/misc/xyzAxis') debugAxis2.reparentTo(testTire) debugAxis2.setScale(-IceGameGlobals.TireRadius / 10.0) # lets create a black tire #tireModel = loader.loadModel('phase_3/models/misc/sphere') tireModel = loader.loadModel( "phase_4/models/minigames/ice_game_tire") # assuming it has a radius of 1 tireHeight = 1 #tireModel.setScale(IceGameGlobals.TireRadius, IceGameGlobals.TireRadius, 1) #tireModel.setZ( 0 - IceGameGlobals.TireRadius + (tireHeight /2.0)) #tireModel.setColor(0,0,0) tireModel.setZ(-IceGameGlobals.TireRadius + 0.01) tireModel.reparentTo(testTire) #tireModel.setAlphaScale(0.5) #tireModel.setTransparency(1) self.odePandaRelationList.append((testTire, body)) else: testTire = None self.bodyList.append((None, body)) return testTire, body, geom
ball.flattenLight() # Apply transform ball.setTextureOff() # Add a random amount of balls balls = [] # This 'balls' list contains tuples of nodepaths with their ode geoms for i in range(15): # Setup the geometry ballNP = ball.copyTo(render) ballNP.setPos(randint(-7, 7), randint(-7, 7), 10 + random() * 5.0) ballNP.setColor(random(), random(), random(), 1) ballNP.setHpr(randint(-45, 45), randint(-45, 45), randint(-45, 45)) # Create the body and set the mass ballBody = OdeBody(world) M = OdeMass() M.setSphere(50, 1) ballBody.setMass(M) ballBody.setPosition(ballNP.getPos(render)) ballBody.setQuaternion(ballNP.getQuat(render)) # 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)