示例#1
0
 def get_proj(self):
     """Create the projection matrix from the current viewing
     position.
     elev stores the elevation angle in the z plane
     azim stores the azimuth angle in the x,y plane
     dist is the distance of the eye viewing point from the object
     point.
     """
     relev, razim = np.pi * self.elev/180, np.pi * self.azim/180
     xmin, xmax = self.get_xlim3d()
     ymin, ymax = self.get_ylim3d()
     zmin, zmax = self.get_zlim3d()
     worldM = proj3d.world_transformation(xmin, xmax,
                                          ymin, ymax,
                                          zmin, zmax)
     R = np.array([0.5, 0.5, 0.5])
     xp = R[0] + np.cos(razim) * np.cos(relev) * self.dist
     yp = R[1] + np.sin(razim) * np.cos(relev) * self.dist
     zp = R[2] + np.sin(relev) * self.dist
     E = np.array((xp, yp, zp))
     self.eye = E
     self.vvec = R - E
     self.vvec = self.vvec / proj3d.mod(self.vvec)
     if abs(relev) > np.pi/2:
         V = np.array((0, 0, -1))
     else:
         V = np.array((0, 0, 1))
     zfront, zback = -self.dist, self.dist
     viewM = proj3d.view_transformation(E, R, V)
     perspM = proj3d.persp_transformation(zfront, zback)
     M0 = np.dot(viewM, worldM)
     M = np.dot(perspM, M0)
     return M
示例#2
0
    def get_proj(self):
        """Create the projection matrix from the current viewing
        position.

        elev stores the elevation angle in the z plane
        azim stores the azimuth angle in the x,y plane

        dist is the distance of the eye viewing point from the object
        point.

        """
        relev,razim = npy.pi * self.elev/180, npy.pi * self.azim/180

        xmin,xmax = self.get_w_xlim()
        ymin,ymax = self.get_w_ylim()
        zmin,zmax = self.get_w_zlim()

        # transform to uniform world coordinates 0-1.0,0-1.0,0-1.0
        worldM = proj3d.world_transformation(xmin,xmax,
                                             ymin,ymax,
                                             zmin,zmax)

        # look into the middle of the new coordinates
        R = npy.array([0.5,0.5,0.5])
        #
        xp = R[0] + npy.cos(razim)*npy.cos(relev)*self.dist
        yp = R[1] + npy.sin(razim)*npy.cos(relev)*self.dist
        zp = R[2] + npy.sin(relev)*self.dist

        E = npy.array((xp, yp, zp))
        #
        self.eye = E
        self.vvec = R - E
        self.vvec = self.vvec / proj3d.mod(self.vvec)

        if abs(relev) > npy.pi/2:
            # upside down
            V = npy.array((0,0,-1))
        else:
            V = npy.array((0,0,1))
        zfront,zback = -self.dist,self.dist

        viewM = proj3d.view_transformation(E,R,V)
        perspM = proj3d.persp_transformation(zfront,zback)
        M0 = npy.dot(viewM,worldM)
        M = npy.dot(perspM,M0)
        return M