def zapolnenie(world, n, mi, ma): for i in range(n): sphere = loader.loadModel("smiley.egg") sphere.reparentTo(render) r = randint(mi, ma) sphere.setPos( sin(i * 2 * pi / n) * r, cos(i * 2 * pi / n) * r, r // 1.5) sphereBody = OdeBody(world.myWorld) sphereModel = OdeMass() sphereModel.setSphere(1, 2) sphereBody.setMass(sphereModel) sphereBody.setPosition( sin(i * 2 * pi / n) * r, cos(i * 2 * pi / n) * r, r // 1.5) world.spheres.append(sphereBody) world.objs.append(sphere) for i in range(n - 1): sphereJoint = OdeBallJoint(world.myWorld) sphereJoint.attach(world.spheres[i], world.spheres[i + 1]) sphereJoint.setAnchor(world.spheres[i].getPosition()) world.joints.append(sphereJoint) sphereJoint = OdeBallJoint(world.myWorld) sphereJoint.attach(world.spheres[-1], world.spheres[0]) sphereJoint.setAnchor(world.spheres[-1].getPosition()) world.joints.append(sphereJoint)
def __init__(self): ShowBase.__init__(self) dlight = DirectionalLight('dlight') dlight.setColor(VBase4(0.8, 0.8, 0.5, 1)) dlnp = self.render.attachNewNode(dlight) dlnp.setHpr(0, -60, 0) self.render.setLight(dlnp) self.balls = [Ball(self) for x in range(NUMBALLS)] # Setup our physics world and the body self.world = OdeWorld() self.world.setGravity(0, 0, -9.81) if 0: self.body = OdeBody(self.world) M = OdeMass() M.setSphere(7874, 1.0) self.body.setMass(M) self.body.setPosition(self.sphere.getPos(self.render)) self.body.setQuaternion(self.sphere.getQuat(self.render)) ## Set the camera position self.disableMouse() self.angle = 0.0 self.camera.setPos(1000, 1000, 1000) self.camera.lookAt(0, 0, 0) #self.enableMouse() # Create an accumulator to track the time since the sim # has been running self.deltaTimeAccumulator = 0.0 # This stepSize makes the simulation run at 60 frames per second self.stepSize = 1.0 / 60.0 taskMgr.doMethodLater(1.0, self.simulationTask, "Physics Simulation")
def __init__(self): ShowBase.__init__(self) dlight = DirectionalLight("dlight") dlight.setColor(VBase4(0.8, 0.8, 0.5, 1)) dlnp = self.render.attachNewNode(dlight) dlnp.setHpr(0, -60, 0) self.render.setLight(dlnp) self.balls = [Ball(self) for x in range(NUMBALLS)] # Setup our physics world and the body self.world = OdeWorld() self.world.setGravity(0, 0, -9.81) if 0: self.body = OdeBody(self.world) M = OdeMass() M.setSphere(7874, 1.0) self.body.setMass(M) self.body.setPosition(self.sphere.getPos(self.render)) self.body.setQuaternion(self.sphere.getQuat(self.render)) ## Set the camera position self.disableMouse() self.angle = 0.0 self.camera.setPos(1000, 1000, 1000) self.camera.lookAt(0, 0, 0) # self.enableMouse() # Create an accumulator to track the time since the sim # has been running self.deltaTimeAccumulator = 0.0 # This stepSize makes the simulation run at 60 frames per second self.stepSize = 1.0 / 60.0 taskMgr.doMethodLater(1.0, self.simulationTask, "Physics Simulation")
def createBonded(): global world electrons.append( electron(random.randint(-10, 10), random.randint(-10, 10), random.randint(-10, 10), True)) body = OdeBody(world) M = OdeMass() M.setSphere(7874, 1.0) body.setMass(M) bodies.append(body) button4.setText(("Remove Bonded Pair", "Destroy", "Destroy", "disabled"))
def __init__(self, world, loc=Point3()): """ the location is the bottom-left corner of the platform """ mass = OdeMass() mass.setSphere(1000, 1) geom = OdeSphereGeom(world.space, 1) super(Ball, self).__init__(world, mass, geom, "ball", loc)
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 __init__(self, app, distance=0, force=0): ElementModele.__init__(self, app, "balle", "modeles/ball/NBA BASKETBALL.obj", "modeles/ball/NBA BASKETBALL DIFFUSE.jpg") # Taille moyenne d'une balle taille = mean([23.8, 24.8]) * 10**-2 self.session_courante = Balle.session self.distance = distance self.force = force # Rayon de la balle rayon = taille / 2.0 # Poids moyen d'une balle poids = mean([567, 624]) * 10**-3 # Modification de la taille de la balle self.set_taille(taille, taille, taille) volume = (4.0 * pi / 3.0) * rayon**3 masse = OdeMass() masse.setSphere(poids / volume, rayon) self.corps.setMass(masse) # Creation d'un element geometrique spherique self.geom = OdeSphereGeom(self.app.monde.espace, taille / 2.0) # Defini les parametres de collision self.geom.setCollideBits(BitMask32(0x00000002)) self.geom.setCategoryBits(BitMask32(0x00000001)) # Attache l'element geometrique a la balle self.geom.setBody(self.corps) # Ajout de la balle comme element dynamique self.app.monde.ajouter_element(self)
sphere_b = cm.gen_sphere(radius=radius) sphere_b.set_pos([0, 1.25, -.7]) sphere_b.set_rgba([.3, .2, 1, 1]) sphere_b.attach_to(base) gm.gen_linesegs([[np.zeros(3), sphere_a.get_pos()]], thickness=.05, rgba=[0, 1, 0, 1]).attach_to(base) gm.gen_linesegs([[sphere_a.get_pos(), sphere_b.get_pos()]], thickness=.05, rgba=[0, 0, 1, 1]).attach_to(base) # Setup our physics world and the body world = OdeWorld() world.setGravity(0, 0, -9.81) body_sphere_a = OdeBody(world) M = OdeMass() M.setSphere(7874, radius) body_sphere_a.setMass(M) body_sphere_a.setPosition(da.npv3_to_pdv3(sphere_a.get_pos())) body_sphere_b = OdeBody(world) M = OdeMass() M.setSphere(7874, radius) body_sphere_b.setMass(M) body_sphere_b.setPosition(da.npv3_to_pdv3(sphere_b.get_pos())) # Create the joints earth_a_jnt = OdeBallJoint(world) earth_a_jnt.attach(body_sphere_a, None) # Attach it to the environment earth_a_jnt.setAnchor(0, 0, 0) earth_b_jnt = OdeBallJoint(world) earth_b_jnt.attach(body_sphere_a, body_sphere_b)
cube.reparentTo(render) cube.setColor(0.2, 0, 0.7) cube.setScale(20) # Load the smiley model which will act as our iron ball sphere = loader.loadModel("smiley.egg") sphere.reparentTo(render) sphere.setPos(10, 1, 21) sphere.setColor(0.7, 0.4, 0.4) # Setup our physics world and the body world = OdeWorld() world.setGravity(0, 0, -9.81) body = OdeBody(world) M = OdeMass() M.setSphere(7874, 1.0) body.setMass(M) body.setPosition(sphere.getPos()) body.setQuaternion(sphere.getQuat()) # Set the camera position base.disableMouse() base.camera.setPos(80, -20, 40) base.camera.lookAt(0, 0, 10) # Create an accumulator to track the time since the sim # has been running deltaTimeAccumulator = 0.0 # This stepSize makes the simulation run at 90 frames per second stepSize = 1.0 / 90.0