Ejemplo n.º 1
0
    def setCamera(self,bbox=None,angles=None):
        """Sets the camera looking under angles at bbox.

        This function sets the camera angles and adjusts the zooming.
        The camera distance remains unchanged.
        If a bbox is specified, the camera will be zoomed to make the whole
        bbox visible.
        If no bbox is specified, the current scene bbox will be used.
        If no current bbox has been set, it will be calculated as the
        bbox of the whole scene.
        """
        self.makeCurrent()
        # go to a distance to have a good view with a 45 degree angle lens
        if bbox is None:
            bbox = self.bbox
        else:
            self.bbox = bbox
        center,size = vector.centerDiff(bbox[0],bbox[1])
        # calculating the bounding circle: this is rather conservative
        dist = vector.length(size)
        if dist <= 0.0:
            dist = 1.0
        self.camera.setCenter(*center)
        if angles:
            self.camera.setRotation(*angles)
        self.camera.setDist(dist)
        self.camera.setLens(45.,self.aspect)
        self.camera.setClip(0.01*dist,100.*dist)
Ejemplo n.º 2
0
    def setView(self,bbox=None,side='front'):
        """Sets the camera looking from one of the named views.

        On startup, the predefined views are 'front', 'back', 'left',
        'right', 'top', 'bottom' and 'iso'.
        This function does not only set the camera angles, but also
        adjust the zooming.
        If a bbox is specified, the camera will be zoomed to view the
        whole bbox.
        If no bbox is specified, the current scene bbox will be used.
        If no current bbox has been set, it will be calculated as the
        bbox of the whole scene.
        """
        self.makeCurrent()
        # select view angles: if undefined use (0,0,0)
        angles = self.views.get(side,(0,0,0))
        # go to a distance to have a good view with a 45 degree angle lens
        if type(bbox) == type(None):
            bbox = self.bbox
        else:
            self.bbox = bbox
        center,size = vector.centerDiff(bbox[0],bbox[1])
        #print "Setting view for bbox",bbox
        #print "center=",center
        #print "size=",size
        # calculating the bounding circle: this is rather conservative
        dist = vector.length(size)
        #print "dist = ",dist
        self.camera.setCenter(*center)
        self.camera.setRotation(*angles)
        self.camera.setDist(dist)
        self.camera.setLens(45.,self.aspect)
        if dist > 0.0:
            self.camera.setClip(0.01*dist,100*dist)
        else:
            self.camera.setClip(0.0,1.0)