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 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()
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 sentrotival = sentinel.hprInterval(8, (630, a, 0), startHpr=(270, a, 0))