def set_clickable(self, clickable): self.clickable = clickable if self.use_collision_solid and self.collision_solid is not None: if clickable: self.collision_solid.node().setIntoCollideMask( CollisionNode.getDefaultCollideMask()) else: self.collision_solid.node().setIntoCollideMask( BitMask32.all_off()) #The instance itself is not clickable self.instance.setCollideMask(BitMask32.all_off()) else: if clickable: self.instance.setCollideMask(GeomNode.getDefaultCollideMask()) else: self.instance.setCollideMask(BitMask32.all_off())
def __init__(self, app, render, camera, mouseWatcher, pickKeyOn, pickKeyOff, collideMask, pickableTag="pickable"): self.render = render self.mouseWatcher = mouseWatcher.node() self.camera = camera self.camLens = camera.node().get_lens() self.collideMask = collideMask self.pickableTag = pickableTag self.taskMgr = app.task_mgr # setup event callback for picking body self.pickKeyOn = pickKeyOn self.pickKeyOff = pickKeyOff app.accept(self.pickKeyOn, self._pickBody, [self.pickKeyOn]) app.accept(self.pickKeyOff, self._pickBody, [self.pickKeyOff]) # collision data self.collideMask = collideMask self.cTrav = CollisionTraverser() self.collisionHandler = CollisionHandlerQueue() self.pickerRay = CollisionRay() pickerNode = CollisionNode("Utilities.pickerNode") node = NodePath("PhysicsNode") node.reparentTo(render) anp = node.attachNewNode(pickerNode) base.physicsMgr.attachPhysicalNode(pickerNode) pickerNode.add_solid(self.pickerRay) pickerNode.set_from_collide_mask(self.collideMask) pickerNode.set_into_collide_mask(BitMask32.all_off()) #pickerNode.node().getPhysicsObject().setMass(10) self.cTrav.add_collider(self.render.attach_new_node(pickerNode), self.collisionHandler) # service data self.pickedBody = None self.oldPickingDist = 0.0 self.deltaDist = 0.0 self.dragging = False self.updateTask = None
from panda3d.core import BitMask32, Vec3 #world defaults DEFAULT_AMBIENT_COLOR = (0.4, 0.4, 0.4, 1) DEFAULT_GROUND_COLOR = (0, 0, 0.15, 1) DEFAULT_SKY_COLOR = (0, 0, 0.15, 1) DEFAULT_HORIZON_COLOR = (0, 0, 0.8, 1) DEFAULT_HORIZON_SCALE = 0.05 MISSILE_SCALE = .29 GRENADE_SCALE = .35 #collision bitmask constants NO_COLLISION_BITS = BitMask32.all_off() MAP_COLLIDE_BIT = BitMask32.bit(0) SOLID_COLLIDE_BIT = BitMask32.bit(1) GHOST_COLLIDE_BIT = BitMask32.bit(2) #physics contstants EXPLOSIONS_DONT_PUSH = ["expl", "ground"] DEFAULT_GRAVITY = Vec3(0, -9.81, 0) DEFAULT_FRICTION = 1 AIR_FRICTION = 0.02 #weapons stuff PLASMA_SCALE = .3 MIN_PLASMA_CHARGE = .4
from panda3d.core import BitMask32, Vec3 # world defaults DEFAULT_AMBIENT_COLOR = (0.4, 0.4, 0.4, 1) DEFAULT_GROUND_COLOR = (0, 0, 0.15, 1) DEFAULT_SKY_COLOR = (0, 0, 0.15, 1) DEFAULT_HORIZON_COLOR = (0, 0, 0.8, 1) DEFAULT_HORIZON_SCALE = 0.05 MISSILE_SCALE = .29 GRENADE_SCALE = .35 # collision bitmask constants NO_COLLISION_BITS = BitMask32.all_off() MAP_COLLIDE_BIT = BitMask32.bit(0) SOLID_COLLIDE_BIT = BitMask32.bit(1) GHOST_COLLIDE_BIT = BitMask32.bit(2) # physics contstants EXPLOSIONS_DONT_PUSH = ["expl", "ground"] DEFAULT_GRAVITY = Vec3(0, -9.81, 0) DEFAULT_FRICTION = 1 AIR_FRICTION = 0.02 # weapons stuff PLASMA_SCALE = .3 MIN_PLASMA_CHARGE = .4
def __init__(self): self.userDetails = {} #added thi line of code self.users = [] self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0} base.win.setClearColor(Vec4(0,0,0,1)) # Post the instructions self.title = addTitle("Panda3D Tutorial: Roaming Ralph (Walking on Uneven Terrain)") self.inst1 = addInstructions(0.95, "[ESC]: Quit") self.inst2 = addInstructions(0.90, "[Left Arrow]: Rotate Ralph Left") self.inst3 = addInstructions(0.85, "[Right Arrow]: Rotate Ralph Right") self.inst4 = addInstructions(0.80, "[Up Arrow]: Run Ralph Forward") self.inst6 = addInstructions(0.70, "[A]: Rotate Camera Left") self.inst7 = addInstructions(0.65, "[S]: Rotate Camera Right") # Set up the environment # # This environment model contains collision meshes. If you look # in the egg file, you will see the following: # # <Collide> { Polyset keep descend } # # This tag causes the following mesh to be converted to a collision # mesh -- a mesh which is optimized for collision, not rendering. # It also keeps the original mesh, so there are now two copies --- # one optimized for rendering, one for collisions. self.environ = loader.loadModel("models/world") self.environ.reparentTo(render) self.environ.setPos(0,0,0) # Create the main character, Ralph ralphStartPos = self.environ.find("**/start_point").getPos() self.ralph = Actor("models/ralph", {"run":"models/ralph-run", "walk":"models/ralph-walk"}) self.ralph.reparentTo(render) self.ralph.setScale(.2) self.ralph.setPos(ralphStartPos) """ @Marvin Add a second and third player Username, pos, and h should be retrieved from Server or a users list """ self.ralph2 = self.createActor(render, 'Ralph2', -108.5739, 5.2108, -0.7866, 60.5011) self.ralph3 = self.createActor(render, 'Ralph3', -118.9658, 9.8990, 0.3478, 60.5011) taskMgr.add(self.movePlayersRandomly, "RandomPlayerMovementTask") # Create a floater object. We use the "floater" as a temporary # variable in a variety of calculations. self.floater = NodePath(PandaNode("floater")) self.floater.reparentTo(render) # Accept the control keys for movement and rotation self.accept("escape", sys.exit) self.accept("arrow_left", self.setKey, ["left",1]) self.accept("arrow_right", self.setKey, ["right",1]) self.accept("arrow_up", self.setKey, ["forward",1]) self.accept("a", self.setKey, ["cam-left",1]) self.accept("s", self.setKey, ["cam-right",1]) self.accept("arrow_left-up", self.setKey, ["left",0]) self.accept("arrow_right-up", self.setKey, ["right",0]) self.accept("arrow_up-up", self.setKey, ["forward",0]) self.accept("a-up", self.setKey, ["cam-left",0]) self.accept("s-up", self.setKey, ["cam-right",0]) taskMgr.add(self.move,"moveTask") # Game state variables self.isMoving = False # Set up the camera base.disableMouse() base.camera.setPos(self.ralph.getX(),self.ralph.getY()+10,2) # We will detect the height of the terrain by creating a collision # ray and casting it downward toward the terrain. One ray will # start above ralph's head, and the other will start above the camera. # A ray may hit the terrain, or it may hit a rock or a tree. If it # hits the terrain, we can detect the height. If it hits anything # else, we rule that the move is illegal. self.cTrav = CollisionTraverser() self.ralphGroundRay = CollisionRay() self.ralphGroundRay.setOrigin(0,0,1000) self.ralphGroundRay.setDirection(0,0,-1) self.ralphGroundCol = CollisionNode('ralphRay') self.ralphGroundCol.addSolid(self.ralphGroundRay) self.ralphGroundCol.setFromCollideMask(BitMask32.bit(0)) self.ralphGroundCol.setIntoCollideMask(BitMask32.all_off()) self.ralphGroundColNp = self.ralph.attachNewNode(self.ralphGroundCol) self.ralphGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler) self.camGroundRay = CollisionRay() self.camGroundRay.setOrigin(0,0,1000) self.camGroundRay.setDirection(0,0,-1) self.camGroundCol = CollisionNode('camRay') self.camGroundCol.addSolid(self.camGroundRay) self.camGroundCol.setFromCollideMask(BitMask32.bit(0)) self.camGroundCol.setIntoCollideMask(BitMask32.all_off()) self.camGroundColNp = base.camera.attachNewNode(self.camGroundCol) self.camGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.camGroundColNp, self.camGroundHandler) # Uncomment this line to see the collision rays #self.ralphGroundColNp.show() #self.camGroundColNp.show() # Uncomment this line to show a visual representation of the # collisions occuring #self.cTrav.showCollisions(render) # Create some lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.3, .3, .3, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(-5, -5, -5)) directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight))