def setup(self): self.worldNP = render.attachNewNode('World') # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) self.debugNP.show() self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) self.world.setDebugNode(self.debugNP.node()) # Plane shape = BulletPlaneShape(Vec3(0, 0, 1), 0) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground')) np.node().addShape(shape) np.setPos(0, 0, -1) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # initial vehicles self.vehicles = [] #self.vehicles.append(basicVehicle(self,[13,2,0.5],18)) # [10,0.1,0.5] is vehicle start position self.vehicles.append( basicVehicle(self, [10, 0.1, 0.5], 18)) # [10,0.1,0.5] is vehicle start position sensor = basicSensor(self) # initial sensor sensor.setVehicle(self.vehicles[0]) self.vehicles[0].setSensor(sensor) self.vehicles[0].sensor.align() agent = basicAgent(50, 10.8, 15) # initial agent agent.setVehicle(self.vehicles[0]) self.vehicles[0].setAgent(agent)
def createPlane(self): rb = BulletRigidBodyNode('Ground') rb.addShape(BulletPlaneShape(Vec3(0, 0, 1), 1)) rb.setFriction(1.0) np = self.render.attachNewNode(rb) np.setPos(Vec3(0, 0, -100)) np.setCollideMask(BitMask32.bit(0)) self.world.attachRigidBody(rb) return np
def createPlane(self, pos): rb = BulletRigidBodyNode("plane") rb.addShape(BulletPlaneShape(Vec3(0, 0, 1), 1)) rb.setFriction(1.0) rb.setAnisotropicFriction(1.0) rb.setRestitution(1.0) np = self.render.attachNewNode(rb) np.setPos(pos) np.setCollideMask(BitMask32.bit(0)) self.world.attachRigidBody(rb) return np
def setup(self): self.worldNP = render.attachNewNode('World') # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) # self.debugNP.show() self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) self.world.setDebugNode(self.debugNP.node()) # Plane shape = BulletPlaneShape(Vec3(0, 0, 1), 0) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground')) np.node().addShape(shape) np.setPos(0, 0, -1) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # initial vehicles length = 2.8 width = 1.2 height = 1 axisDis = 2.1 wheelDis = 1.4 wheelH = 0.3 radius = 0.25 self.vehicles = [] self.sensors = [] # Adding autonomous vehicles for i in range(len(self.initAV)): self.vehicles.append( basicVehicle(self, [self.initAV[i][0], self.initAV[i][1], -0.6], self.initAV[i][2], length, width, height, axisDis, wheelDis, radius, wheelH)) self.sensors.append(basicSensor(self)) # initial sensor self.sensors[i].setVehicle(self.vehicles[i]) self.vehicles[i].setSensor(self.sensors[i]) self.vehicles[i].sensor.align() self.agents[i].setVehicle(self.vehicles[i]) self.vehicles[i].setAgent(self.agents[i])
def createPlane(self, pos): rb = BulletRigidBodyNode("GroundPlane") rb.addShape(BulletPlaneShape(Vec3(0, 0, 1), 1)) rb.setFriction(1.0) rb.setAnisotropicFriction(1.0) rb.setRestitution(1.0) np = self.render.attachNewNode(rb) np.setPos(pos) np.setCollideMask(BitMask32.bit(0)) plane = self.loader.loadModel("cube") plane.setScale(Vec3(100, 100, 1)) plane.setPos(Vec3(0, 0, -0.5)) plane.setColor(VBase4(0.8, 0.8, 0.8, 1.0)) plane.reparentTo(np) self.world.attachRigidBody(rb) return np
def createCuttingPlanes(self): self.planes = self.render.attachNewNode("planes") pl = self.planes.attachNewNode("pl") data = EggData() self.planedata = [] vp = EggVertexPool('plane') data.addChild(vp) fac = 1.0 expanse = 10.0 rng = 4 for i in range(-rng, rng): poly = EggPolygon() data.addChild(poly) self.planedata.append(i * fac) v = EggVertex() v.setPos(Point3D(i * fac, -expanse, -expanse)) poly.addVertex(vp.addVertex(v)) v = EggVertex() v.setPos(Point3D(i * fac, -expanse, +expanse)) poly.addVertex(vp.addVertex(v)) v = EggVertex() v.setPos(Point3D(i * fac, +expanse, +expanse)) poly.addVertex(vp.addVertex(v)) v = EggVertex() v.setPos(Point3D(i * fac, +expanse, -expanse)) poly.addVertex(vp.addVertex(v)) node = loadEggData(data) np = NodePath(node) np.reparentTo(pl) np.setColor(0, 1, 0, 1) np.setTwoSided(True) np.setTransparency(TransparencyAttrib.MAlpha) np.setAlphaScale(0.1) np.setCollideMask(BitMask32(0x0)) return self.planes
def setup(self): self.worldNP = render.attachNewNode('World') # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) self.debugNP.show() self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) self.world.setDebugNode(self.debugNP.node()) # Plane shape = BulletPlaneShape(Vec3(0, 0, 1), 0) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground')) np.node().addShape(shape) np.setPos(0, 0, -1) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) self.vehicles = dict()
def createBox(self, mass, pos, scale, color): rb = BulletRigidBodyNode('box') rb.addShape(BulletBoxShape(scale)) rb.setMass(mass) rb.setLinearDamping(0.2) rb.setAngularDamping(0.9) rb.setFriction(1.0) rb.setAnisotropicFriction(1.0) rb.setRestitution(0.0) self.world.attachRigidBody(rb) np = self.render.attachNewNode(rb) np.setPos(pos) np.setCollideMask(BitMask32.bit(1)) cube = self.loader.loadModel('cube') cube.setScale(scale) cube.setColor(color) cube.reparentTo(np) return np
def setup(self): self.worldNP = render.attachNewNode('World') # World self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) # self.debugNP.show() self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) self.world.setDebugNode(self.debugNP.node()) # Plane shape = BulletPlaneShape(Vec3(0, 0, 1), 0) np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground')) np.node().addShape(shape) np.setPos(0, 0, -1) np.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(np.node()) # initial vehicles length=2.8 width=1.2 height=1 axisDis=2.1 wheelDis=1.4 wheelH=0.3 radius=0.25 self.vehicles=[] self.sensors=[] self.vehicles.append(basicVehicle(self,[self.initAV[0],self.initAV[1],-0.6],self.initAV[2],length,width,height,axisDis,wheelDis,radius,wheelH)) # [10,0.1,0.5] is vehicle start position self.sensors.append(basicSensor(self)) # initial sensor self.sensors[0].setVehicle(self.vehicles[0]) self.vehicles[0].setSensor(self.sensors[0]) self.vehicles[0].sensor.align() self.agents[0].setVehicle(self.vehicles[0]) self.vehicles[0].setAgent(self.agents[0]) #Adding laneKeeping vehicles for i in range(len(self.initSV)): self.vehicles.append(surroundingVehicle(self,[self.initSV[i][0],self.initSV[i][1],-0.6],self.initSV[i][2],length,width,height,axisDis,wheelDis,radius,wheelH)) # [10,0.1,0.5] is vehicle start position self.sensors.append(basicSensor(self)) # initial sensor self.sensors[i+1].setVehicle(self.vehicles[i+1]) self.vehicles[i+1].setSensor(self.sensors[i+1]) self.vehicles[i+1].sensor.align() self.agents[i+1].setVehicle(self.vehicles[i+1]) self.vehicles[i+1].setAgent(self.agents[i+1]) '''self.vehicles.append(basicVehicle(self,[50,-6,-0.6],30)) # [10,0.1,0.5] is vehicle start position sensor1=basicSensor(self) # initial sensor sensor1.setVehicle(self.vehicles[1]) self.vehicles[1].setSensor(sensor1) self.vehicles[1].sensor.align() #agent1=planningAgent(20,5,40,0,1) # initial agent agent1=laneKeepingAgent(20,20,30,1) agent1.setVehicle(self.vehicles[1]) self.vehicles[1].setAgent(agent1)''' #Surrounding vehicles' speed v1=25 v2=25 v3=25 v4=25 '''self.vehicles.append(basicVehicle(self,[60,-6.1,-0.6],v1))