Ejemplo n.º 1
0
def _test_proj_make_M():
    # eye point
    E = np.array([1000, -1000, 2000])
    R = np.array([100, 100, 100])
    V = np.array([0, 0, 1])
    viewM = proj3d.view_transformation(E, R, V)
    perspM = proj3d.persp_transformation(100, -100)
    M = np.dot(perspM, viewM)
    return M
Ejemplo n.º 2
0
def _test_proj_make_M():
    # eye point
    E = np.array([1000, -1000, 2000])
    R = np.array([100, 100, 100])
    V = np.array([0, 0, 1])
    viewM = proj3d.view_transformation(E, R, V)
    perspM = proj3d.persp_transformation(100, -100)
    M = np.dot(perspM, viewM)
    return M
Ejemplo n.º 3
0
    def get_proj():
        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()

        # transform to uniform world coordinates 0-1.0,0-1.0,0-1.0
        worldM = proj3d.world_transformation(xmin, xmax, ymin, ymax, zmin,
                                             zmax)
        ratio = 0.5
        # adjust the aspect ratio                          ##
        aspectM = proj3d.world_transformation(
            -kx + 1,
            kx,  ##
            -ky + 1,
            ky,  ##
            -kz + 1,
            kz)  ##

        # look into the middle of the new coordinates
        R = np.array([0.5, 0.5, 0.5])

        xp = R[0] + np.cos(razim) * np.cos(relev) * self.dist * ratio
        yp = R[1] + np.sin(razim) * np.cos(relev) * self.dist * ratio
        zp = R[2] + np.sin(relev) * self.dist * ratio
        E = np.array((xp, yp, zp))

        self.eye = E
        self.vvec = R - E
        self.vvec = self.vvec / np.linalg.norm(self.vvec)

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

        viewM = proj3d.view_transformation(E, R, V)
        perspM = proj3d.persp_transformation(zfront, zback)
        M0 = np.dot(viewM, np.dot(aspectM, worldM))  ##
        M = np.dot(perspM, M0)
        return M
Ejemplo n.º 4
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()/self.pbaspect[0]
    ymin, ymax = self.get_ylim3d()/self.pbaspect[1]
    zmin, zmax = self.get_zlim3d()/self.pbaspect[2]

    # 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 = 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:
      # upside down                                                                                
      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