コード例 #1
0
ファイル: camera.py プロジェクト: Derfies/p3d
    def Frame(self, nps):

        # Get a list of bounding spheres for each NodePath in world space.
        allBnds = []
        allCntr = pm.Vec3()
        for np in nps:
            bnds = np.getBounds()
            if bnds.isInfinite():
                continue
            mat = np.getParent().getMat(self.rootNp)
            bnds.xform(mat)
            allBnds.append(bnds)
            allCntr += bnds.getCenter()

        # Now create a bounding sphere at the center point of all the
        # NodePaths and extend it to encapsulate each one.
        bnds = pm.BoundingSphere(pm.Point3(allCntr / len(nps)), 0)
        for bnd in allBnds:
            bnds.extendBy(bnd)

        # Move the camera and the target the the bounding sphere's center.
        self.target.setPos(bnds.getCenter())
        self.setPos(bnds.getCenter())

        # Now move the camera back so the view accomodates all NodePaths.
        # Default the bounding radius to something reasonable if the object
        # has no size.
        fov = self.GetLens().getFov()
        radius = bnds.getRadius() or 0.5
        dist = radius / math.tan(math.radians(min(fov[0], fov[1]) * 0.5))
        self.setY(self, -dist)