2014-03-25 24 views
3

我無法理解glm :: perspective。我知道它做了什麼,但不明白這個機制。有誰知道源代碼/過程是什麼?在代碼中複製GLM :: perspective

+0

[glm :: perspective explanation]的可能重複(http://stackoverflow.com/questions/8115352/glmperspective-explanation) –

+0

請參閱:http://stackoverflow.com/questions/8115352/glmperspective-explanation –

回答

4

這都是開源的。只要看看the code

template <typename valType> 
GLM_FUNC_QUALIFIER detail::tmat4x4<valType, defaultp> perspective 
(
    valType const & fovy, 
    valType const & aspect, 
    valType const & zNear, 
    valType const & zFar 
) 
{ 
    assert(aspect != valType(0)); 
    assert(zFar != zNear); 

#ifdef GLM_FORCE_RADIANS 
    valType const rad = fovy; 
#else 
# pragma message("GLM: perspective function taking degrees as a parameter is deprecated.  #define GLM_FORCE_RADIANS before including GLM headers to remove this message.") 
    valType const rad = glm::radians(fovy); 
#endif 

    valType tanHalfFovy = tan(rad/valType(2)); 

    detail::tmat4x4<valType, defaultp> Result(valType(0)); 
    Result[0][0] = valType(1)/(aspect * tanHalfFovy); 
    Result[1][1] = valType(1)/(tanHalfFovy); 
    Result[2][2] = - (zFar + zNear)/(zFar - zNear); 
    Result[2][3] = - valType(1); 
    Result[3][2] = - (valType(2) * zFar * zNear)/(zFar - zNear); 
    return Result; 
} 

...剛剛創建了一個矩陣按照gluPerspective() documentation