def __init__( self, name='camera', pos=Vec3( 0, 0, 0 ), targetPos=Vec3( 0, 0, 0 ), style=CAM_DEFAULT_STYLE ): self.zoomLevel = 2 self.defaultPos = pos self.style = style # Use Panda's default camera if self.style & CAM_USE_DEFAULT: self.cam = getBase().cam #self.camNode = getBase().camNode # Otherwise create a new one else: # Create camera self.cam = NodePath( PCamera( name ) ) # Create lens lens = PerspectiveLens() lens.setAspectRatio( 800.0 / 300.0 ) self.cam.node().setLens( lens ) # Wrap the camera in this node path class NodePath.__init__( self, self.cam ) # Create camera styles if self.style & CAM_VIEWPORT_AXES: self.axes = self.Axes() self.axes.reparentTo( pixel2d ) # Create camera target self.target = self.Target( pos=targetPos ) self.Reset()
def __init__(self, manager, xml): self.light = PSpotLight('slight') lens = PerspectiveLens() self.light.setLens(lens) self.lightNode = render.attachNewNode(self.light) self.reload(manager, xml)
def make_camera(self, output, sort=0, dr_dims=(0, 1, 0, 1), aspect_ratio=None, clear_depth=False, clear_color=None, lens=None, cam_name='camera0', mask=None): """ Makes a new 3-d camera associated with the indicated window, and creates a display region in the indicated subrectangle. If stereo is True, then a stereo camera is created, with a pair of DisplayRegions. If stereo is False, then a standard camera is created. If stereo is None or omitted, a stereo camera is created if the window says it can render in stereo. If useCamera is not None, it is a NodePath to be used as the camera to apply to the window, rather than creating a new camera. """ # self.cameras is the parent node of all cameras: a node that # we can move around to move all cameras as a group. if self.cameras is None: # We make it a ModelNode with the PTLocal flag, so that a # wayward flatten operations won't attempt to mangle the # camera. self.cameras = self.rootnode.attachNewNode(ModelNode('cameras')) self.cameras.node().setPreserveTransform(ModelNode.PTLocal) # Make a new Camera node. cam_node = Camera(cam_name) if lens is None: lens = PerspectiveLens() if aspect_ratio is None: aspect_ratio = self.get_aspect_ratio(output) lens.setAspectRatio(aspect_ratio) lens.setNear(0.1) lens.setFar(1000.0) if lens is not None: cam_node.setLens(lens) camera = self.cameras.attachNewNode(cam_node) # Masks out part of scene from camera if mask is not None: if (isinstance(mask, int)): mask = BitMask32(mask) cam_node.setCameraMask(mask) # Make a display region dr = output.makeDisplayRegion(*dr_dims) # By default, we do not clear 3-d display regions (the entire # window will be cleared, which is normally sufficient). But # we will if clearDepth is specified. if clear_depth: dr.setClearDepthActive(1) if clear_color: dr.setClearColorActive(1) dr.setClearColor(clear_color) dr.setSort(sort) dr.setCamera(camera) dr.setActive(True) return camera
def __init__( self, name='camera', *args, **kwargs ): pos = kwargs.pop( 'pos', (0, 0, 0) ) targetPos = kwargs.pop( 'targetPos', (0, 0, 0) ) style = kwargs.pop( 'style', CAM_DEFAULT_STYLE ) p3d.SingleTask.__init__( self, name, *args, **kwargs ) self.zoomLevel = 2 self.defaultPos = pos self.style = style # Use Panda's default camera if self.style & CAM_USE_DEFAULT: self.cam = getBase().cam #self.camNode = getBase().camNode # Otherwise create a new one else: # Create camera self.cam = NodePath( PCamera( name ) ) # Create lens lens = PerspectiveLens() lens.setAspectRatio( 800.0 / 300.0 ) self.cam.node().setLens( lens ) # Wrap the camera in this node path class NodePath.__init__( self, self.cam ) # Create camera styles if self.style & CAM_VIEWPORT_AXES: self.axes = self.Axes() self.axes.reparentTo( self.rootP2d ) # Create camera target self.target = self.Target( pos=targetPos ) self.Reset()
def __init__(self, name='camera', *args, **kwargs): pos = kwargs.pop('pos', (0, 0, 0)) targetPos = kwargs.pop('targetPos', (0, 0, 0)) style = kwargs.pop('style', CAM_DEFAULT_STYLE) p3d.SingleTask.__init__(self, name, *args, **kwargs) self.zoomLevel = 2 self.defaultPos = pos self.style = style # Use Panda's default camera if self.style & CAM_USE_DEFAULT: self.cam = getBase().cam #self.camNode = getBase().camNode # Otherwise create a new one else: # Create camera self.cam = NodePath(PCamera(name)) # Create lens lens = PerspectiveLens() lens.setAspectRatio(800.0 / 300.0) self.cam.node().setLens(lens) # Wrap the camera in this node path class NodePath.__init__(self, self.cam) # Create camera styles if self.style & CAM_VIEWPORT_AXES: self.axes = pm.NodePath(p3d.geometry.Axes()) self.axes.reparentTo(self.rootP2d) # Create camera target self.target = self.Target(pos=targetPos) self.Reset()
def __init__(self): super(SimViewer, self).__init__() # Make a window. size = (700, 520) self.create_output(size, "SimViewer") self.output.setClearColor((0.0, 0.0, 0.0, 1.0)) # Lights node self.lights = NodePath('lights') # Create a spotlight slight = Spotlight('slight') slight.setScene(self.root) slight.setShadowCaster(True, 2**11, 2**11) # Set shadow mask, so we can exclude objects from casting shadows self.shadow_mask = BitMask32.bit(2) slight.setCameraMask(self.shadow_mask) c = 1.4 slight.setColor((c, c, c, 1.0)) slight.getLens().setNearFar(4, 100) slight.getLens().setFov(45) slnp = self.lights.attachNewNode(slight) slnp.setPos((7, 10, 40)) slnp.lookAt(2, 0, 1.5) self.root.setLight(slnp) # Create an ambient light. alight = AmbientLight('alight') c = 0.6 alight.setColor((c, c, c, 1.0)) alnp = self.lights.attachNewNode(alight) self.root.setLight(alnp) self.lights.reparentTo(self.root) # Set auto shading for shadows. self.root.setShaderAuto() # Set antialiasing on. self.root.setAntialias(AntialiasAttrib.MAuto) # Camera. lens = PerspectiveLens() self.lens = lens self.lens.setNearFar(0.1, 1000.) self.lens.setFov((40, 30)) self.cameras = self.root.attachNewNode('cameras') self.camera = self.make_camera(self.output, lens=self.lens) self.camera.setPos(15, 44, 3.) self.camera.setPos(15, 35, 15.) self.camera.lookAt(0, 0, 1.)
def initialize(self): # creates the root node self.sceneRoot = render.attachNewNode(PanoConstants.NODE_ROOT_NODE) self.debugGeomsParent = self.sceneRoot.attachNewNode( PanoConstants.NODE_DEBUG_GEOMS_PARENT) self.debugGeomsParent.hide() self.collisionsGeomsParent = self.sceneRoot.attachNewNode( PanoConstants.NODE_COLLISIONS_GEOMS_PARENT) self.collisionsGeomsParent.hide() self.spritesParent = self.sceneRoot.attachNewNode( PanoConstants.NODE_SPRITES_PARENT) self.raycaster = NodeRaycaster(self) self.raycaster.initialize() # we want perspective # TODO: modify view parameters per node and in real-time lens = PerspectiveLens() lens.setFar(10000) lens.setFocalLength(1) base.cam.node().setLens(lens) self.loadCubeModel()
def __init__(self): """Initialise the scene.""" # Show the framerate base.setFrameRateMeter(True) # Initialise terrain: # Make 4 terrain nodepath objects with different hilliness values # and arrange them side-by-side in a 2x2 grid, giving a big terrain # with variable hilly and flat areas. color = (0.6, 0.8, 0.5, 1) # Bright green-ish scale = 12 height = 18 # FIXME: For now we are raising the terrain so it # floats above the sea to prevent lakes from # appearing (but you still get them sometimes) t1 = Terrain(color=color, scale=scale, trees=0.7, pos=P.Point3(0, 0, height)) t1.prime.reparentTo(render) t2 = Terrain(color=color, scale=scale, h=24, pos=P.Point3(32 * scale, 0, height), trees=0.5) t2.prime.reparentTo(render) t3 = Terrain(color=color, scale=scale, h=16, pos=P.Point3(32 * scale, 32 * scale, height), trees=0.3) t3.prime.reparentTo(render) t4 = Terrain(color=color, scale=scale, h=2, pos=P.Point3(0, 32 * scale, height), trees=0.9) t4.prime.reparentTo(render) #tnp1.setPos(tnp1,-32,-32,terrainHeight) # Initialise sea sea = Sea() # Initialise skybox. self.box = loader.loadModel("models/skybox/space_sky_box.x") self.box.setScale(6) self.box.reparentTo(render) # Initialise characters self.characters = [] self.player = C.Character(model='models/eve', run='models/eve-run', walk='models/eve-walk') self.player.prime.setZ(100) self.player._pos = SteerVec(32 * 12 + random.random() * 100, 32 * 12 + random.random() * 100) self.player.maxforce = 0.4 self.player.maxspeed = 0.55 EdgeScreenTracker(self.player.prime, dist=200) # Setup camera for i in range(0, 11): self.characters.append(C.Character()) self.characters[i].prime.setZ(100) self.characters[i].wander() self.characters[i].maxforce = 0.3 self.characters[i].maxspeed = 0.2 self.characters[i]._pos = SteerVec(32 * 12 + random.random() * 100, 32 * 12 + random.random() * 100) C.setContainer( ContainerSquare(pos=SteerVec(32 * 12, 32 * 12), radius=31 * 12)) #C.toggleAnnotation() # Initialise keyboard controls. self.accept("c", C.toggleAnnotation) self.accept("escape", sys.exit) # Setup CollisionRay and CollisionHandlerQueue for mouse picking. self.pickerQ = P.CollisionHandlerQueue() self.picker = camera.attachNewNode( P.CollisionNode('Picker CollisionNode')) self.picker.node().addSolid(P.CollisionRay()) # We want the picker ray to collide with the floor and nothing else. self.picker.node().setFromCollideMask(C.floorMASK) self.picker.setCollideMask(P.BitMask32.allOff()) base.cTrav.addCollider(self.picker, self.pickerQ) try: handler.addCollider(self.picker, camera) except: pass self.accept('mouse1', self.onClick) # Set the far clipping plane to be far enough away that we can see the # skybox. base.camLens.setFar(10000) # Initialise lighting self.alight = AmbientLight('alight') self.alight.setColor(VBase4(0.35, 0.35, 0.35, 1)) self.alnp = render.attachNewNode(self.alight) render.setLight(self.alnp) self.dlight = DirectionalLight('dlight') self.dlight.setColor(VBase4(0.4, 0.4, 0.4, 1)) self.dlnp = render.attachNewNode(self.dlight) self.dlnp.setHpr(45, -45, 0) render.setLight(self.dlnp) self.plight = PointLight('plight') self.plight.setColor(VBase4(0.8, 0.8, 0.5, 1)) self.plnp = render.attachNewNode(self.plight) self.plnp.setPos(160, 160, 50) self.slight = Spotlight('slight') self.slight.setColor(VBase4(1, 1, 1, 1)) lens = PerspectiveLens() self.slight.setLens(lens) self.slnp = render.attachNewNode(self.slight) self.slnp.setPos(-20, -20, 20) self.slnp.lookAt(50, 50, 0) # Initialise some scene-wide exponential fog colour = (0.5, 0.8, 0.8) self.expfog = Fog("Scene-wide exponential Fog object") self.expfog.setColor(*colour) self.expfog.setExpDensity(0.0005) render.setFog(self.expfog) base.setBackgroundColor(*colour) # Add a task for this Plant to the global task manager. self.stepcount = 0 taskMgr.add(self.step, "Plant step task")
def __init__(self, controlScheme, camera, game, xStart = 0, yStart = 0, zStart = 0): models = MODELS_PATH + "SleekCraft" anims = {} Unit.__init__(self, models, anims, "**/CollisionSphere", game, xStart, yStart, zStart) self.controlScheme = controlScheme self.camera = camera self.game = game #set up sounds self.thrustSound = game.loader.loadSfx(SFX_PATH + "thrust.wav") self.electricSound = game.loader.loadSfx(SFX_PATH + "electricity.wav") self.magnetSound = game.loader.loadSfx(SFX_PATH + "magnet.wav") #set up the collisions in unit #set up the headlamp specific to the model headLampMain = Spotlight('headLampMain') #headLampMain.showFrustum() headLampMain.setColor(VBase4(1.5, 1.5, 1.5, 1)) mlens = PerspectiveLens() mlens.setNearFar(0.25, 1500) headLampMain.setLens(mlens) headLampMainnode = self.attachNewNode(headLampMain) headLampMainnode.setPos(self.find("**/LightCubeMain").getPos()) headLampMainnode.setHpr(-180, 0, 0)#reverse completely because our model is backwards game.render.setLight(headLampMainnode) headLampLeft = Spotlight('headLampLeft') #headLampLeft.showFrustum() headLampLeft.setColor(VBase4(0.6, 0.6, 0.6, 1)) llens = PerspectiveLens() headLampLeft.setLens(llens) llens.setNearFar(0.25, 500) headLampLeftnode = self.attachNewNode(headLampLeft) headLampLeftnode.setPos(self.find("**/LightCubeLeft").getPos()) headLampLeftnode.setHpr(-105, 0, 0)#reverse completely because our model is backwards game.render.setLight(headLampLeftnode) headLampRight = Spotlight('headLampRight') #headLampRight.showFrustum() headLampRight.setColor(VBase4(0.6, 0.6, 0.6, 1)) rlens = PerspectiveLens() rlens.setNearFar(0.25, 500) headLampRight.setLens(rlens) headLampRightnode = self.attachNewNode(headLampRight) headLampRightnode.setPos(self.find("**/LightCubeRight").getPos()) headLampRightnode.setHpr(105, 0, 0)#reverse completely because our model is backwards game.render.setLight(headLampRightnode) self.maxHealth = 50 self.health = self.maxHealth self.collisionAttackPower = 0 #the currently active weapon self.currentWeapon = AREA #the maximum amount of energy available self.maxEnergy = 2000 #the amount of energy currently available self.energy = self.maxEnergy #the amount of energy that is restored each second self.energyRegen = 300 #the energy cost of attacking with a given weapon for one second self.magnetCost = {NARROW:self.energyRegen + 100, AREA:self.energyRegen + 120} #the strength of a sustained attack per unit of energy used self.magnetStrength = {NARROW:2.5, AREA:20} #the energy cost of a burst attack with a given weapon self.burstCost = {NARROW:0, AREA:600} #the strength of a burst attack with a given weapon #(yes, the area value really does have to be this high) self.burstStrength = {NARROW:90, AREA:7000} #the enemy that the narrow weapon has locked on to self.target = None #whether the player was attacking the previous frame; this is used #to determine whether to release a large burst or a smaller #sustained force self.sustainedAttack = False #action flag self.switchPressed = False self.extraForwardAccel = 2.2 self.accelMultiplier *= 1.2 self.maxTurnRate = 720 #self.shooting = False #used in main to check if the unit can be shot with the narrow attack self.shootable = False self.immune = False
floorcollider.node().setFromCollideMask(BitMask32.allOff()) floorcollider.node().setIntoCollideMask(FLOOR_MASK) wallcollider = terrain.find("**/wall_collide") wallcollider.node().setFromCollideMask(BitMask32.allOff()) wallcollider.node().setIntoCollideMask(WALL_MASK) #** Here the sentinel - the only collider we put in it is the ray detector (see below) sentinel = loader.loadModel("frowney") sentinel.setCollideMask(BitMask32.allOff()) sentinel.reparentTo(render) sentinel.setPos((7.83, -25.31, 24)) avatar_in_sight = False # we create a spotlight that will be the sentinel's eye and will be used to fire the inView method slight = Spotlight('slight') slight.setColor((1, 1, 1, 1)) lens = PerspectiveLens() lens.setFar(80) slight.setLens(lens) slnp = sentinel.attachNewNode(slight) render.setLight(slnp) # this is important: as we said the inView method don't cull geometry but take everything is in sight frustum - therefore to simulate an hide and seek feature we gotta cheat a little: this ray is masked to collide with walls and so if the avatar is behind a wall the ray will be 'deflected' (we'll see how later in the sent_traverse function) - so we know who's behind a wall but we fake we can't see it. sentraygeom = CollisionRay(0, 0, 0, 0, 1, 0) sentinelRay = sentinel.attachNewNode(CollisionNode('sentinelray')) sentinelRay.node().addSolid(sentraygeom) # we set to the ray a cumulative masking using the or operator to detect either the avatar's body and the wall geometry sentinelRay.node().setFromCollideMask(SENTINEL_MASK | WALL_MASK) sentinelRay.node().setIntoCollideMask(BitMask32.allOff()) # we add the ray to the sentinel collider and now it is ready to go base.cTrav.addCollider(sentinelRay, sentinelHandler) # this interval will rotate the sentinel 360 deg indefinitely a = -30