示例#1
0
文件: functions.py 项目: powergun/EHF
def getIdMatrix():
    mat = SimpleMatrix()
    mat.setM(0,0, 1.0)
    mat.setM(1,1, 1.0)
    mat.setM(2,2, 1.0)
    mat.setM(3,3, 1.0)
    return mat
示例#2
0
文件: functions.py 项目: ieralt/EHF
def getProjectionMatrix(nz, fz, fovH, fovV):
    """
    @param nz: near plane
    @type  nz: float
    
    @param fz: far plane
    @type  fz: float
    
    @param fovH: horizontal fov
    @type  fovH: float
    
    @param fovV: vertical fov
    @type  fovV: float
    
    D3DXMATRIX 
    ProjectionMatrix(const float near_plane, // Distance to near clipping 
                                             // plane
                     const float far_plane,  // Distance to far clipping 
                                             // plane
                     const float fov_horiz,  // Horizontal field of view 
                                             // angle, in radians
                     const float fov_vert)   // Vertical field of view 
                                             // angle, in radians
    {
        float    h, w, Q;
    
        w = (float)1/tan(fov_horiz*0.5);  // 1/tan(x) == cot(x)
        h = (float)1/tan(fov_vert*0.5);   // 1/tan(x) == cot(x)
        Q = far_plane/(far_plane - near_plane);
    
        D3DXMATRIX ret;
        ZeroMemory(&ret, sizeof(ret));
    
        ret(0, 0) = w;
        ret(1, 1) = h;
        ret(2, 2) = Q;
        ret(3, 2) = -Q*near_plane;
        ret(2, 3) = 1;
        return ret;
    }   // End of ProjectionMatrix
    """
    w = 1.0 / math.tan(fovH * 0.5)
    h = 1.0 / math.tan(fovV * 0.5)
    q = fz / (fz - nz)
    mat = SimpleMatrix()
    mat.setM(0, 0, w)
    mat.setM(1, 1, h)
    mat.setM(2, 2, q)
    mat.setM(3, 2, -1 * q * nz)
    mat.setM(2, 3, 1.0)
    return mat
示例#3
0
文件: functions.py 项目: powergun/EHF
def getProjectionMatrix(nz, fz, fovH, fovV):
    """
    @param nz: near plane
    @type  nz: float
    
    @param fz: far plane
    @type  fz: float
    
    @param fovH: horizontal fov
    @type  fovH: float
    
    @param fovV: vertical fov
    @type  fovV: float
    
    D3DXMATRIX 
    ProjectionMatrix(const float near_plane, // Distance to near clipping 
                                             // plane
                     const float far_plane,  // Distance to far clipping 
                                             // plane
                     const float fov_horiz,  // Horizontal field of view 
                                             // angle, in radians
                     const float fov_vert)   // Vertical field of view 
                                             // angle, in radians
    {
        float    h, w, Q;
    
        w = (float)1/tan(fov_horiz*0.5);  // 1/tan(x) == cot(x)
        h = (float)1/tan(fov_vert*0.5);   // 1/tan(x) == cot(x)
        Q = far_plane/(far_plane - near_plane);
    
        D3DXMATRIX ret;
        ZeroMemory(&ret, sizeof(ret));
    
        ret(0, 0) = w;
        ret(1, 1) = h;
        ret(2, 2) = Q;
        ret(3, 2) = -Q*near_plane;
        ret(2, 3) = 1;
        return ret;
    }   // End of ProjectionMatrix
    """
    w = 1.0 / math.tan( fovH*0.5 )
    h = 1.0 / math.tan( fovV*0.5 )
    q = fz / ( fz - nz )
    mat = SimpleMatrix()
    mat.setM(0, 0, w)
    mat.setM(1, 1, h)
    mat.setM(2, 2, q)
    mat.setM(3, 2, -1*q*nz)
    mat.setM(2, 3, 1.0)
    return mat
示例#4
0
文件: functions.py 项目: ieralt/EHF
def getIdMatrix():
    mat = SimpleMatrix()
    mat.setM(0, 0, 1.0)
    mat.setM(1, 1, 1.0)
    mat.setM(2, 2, 1.0)
    mat.setM(3, 3, 1.0)
    return mat
示例#5
0
文件: functions.py 项目: ieralt/EHF
def getViewMatrix(up, right, forward, position):
    mat = SimpleMatrix()

    mat.setM(0, 0, right.x)
    mat.setM(0, 1, up.x)
    mat.setM(0, 2, forward.x)
    mat.setM(0, 3, 0.0)

    mat.setM(1, 0, right.y)
    mat.setM(1, 1, up.y)
    mat.setM(1, 2, forward.y)
    mat.setM(1, 3, 0.0)

    mat.setM(2, 0, right.z)
    mat.setM(2, 1, up.z)
    mat.setM(2, 2, forward.z)
    mat.setM(2, 3, 0.0)

    mat.setM(3, 0, -position.dotProduct(right))
    mat.setM(3, 1, -position.dotProduct(up))
    mat.setM(3, 2, -position.dotProduct(forward))
    mat.setM(3, 3, 1.0)

    return mat
示例#6
0
文件: functions.py 项目: ieralt/EHF
def worldToScreenMatrix(vProjMatrix, position, scrCenterX, scrCenterY):
    _position = SimpleMatrix()
    _position.setM(0, 0, position.x)
    _position.setM(1, 0, position.y)
    _position.setM(2, 0, position.z)
    _position.setM(3, 0, 1.0)
    _position = vProjMatrix.multTo(_position)
    if _position.getM(3, 0) < 0.001:
        return None
    invW = 1.0 / _position.getM(3, 0)
    x = (1.0 + _position.getM(0, 0) * invW) * scrCenterX
    y = (1.0 + _position.getM(1, 0) * invW) * scrCenterY
    z = _position.getM(2, 0)
    if z < 0.001:
        return COORD(x, y)
    else:
        return None
示例#7
0
文件: functions.py 项目: powergun/EHF
def getViewMatrix(up, right, forward, position):
    mat = SimpleMatrix()
    
    mat.setM(0,0,right.x)
    mat.setM(0,1,up.x)
    mat.setM(0,2,forward.x)
    mat.setM(0,3,0.0)
    
    mat.setM(1,0,right.y)
    mat.setM(1,1,up.y)
    mat.setM(1,2,forward.y)
    mat.setM(1,3,0.0)
    
    mat.setM(2,0,right.z)
    mat.setM(2,1,up.z)
    mat.setM(2,2,forward.z)
    mat.setM(2,3,0.0)
    
    mat.setM(3,0,-position.dotProduct(right))
    mat.setM(3,1,-position.dotProduct(up))
    mat.setM(3,2,-position.dotProduct(forward))
    mat.setM(3,3,1.0)

    return mat
示例#8
0
文件: functions.py 项目: powergun/EHF
def worldToScreenMatrix(vProjMatrix, position, scrCenterX, scrCenterY):
    _position = SimpleMatrix()
    _position.setM(0,0,position.x)
    _position.setM(1,0,position.y)
    _position.setM(2,0,position.z)
    _position.setM(3,0,1.0)
    _position = vProjMatrix.multTo(_position)
    if _position.getM(3,0) < 0.001:
        return None
    invW = 1.0/_position.getM(3,0)
    x = (1.0 + _position.getM(0,0) * invW) * scrCenterX
    y = (1.0 + _position.getM(1,0) * invW) * scrCenterY
    z = _position.getM(2,0)
    if z < 0.001:
        return COORD(x,y)
    else:
        return None