0
每當我嘗試使用我的glmxLoadPerspective函數時,都不顯示任何內容。但是,我的glmxLoadOrtho函數顯示正常。我的數學錯了嗎?相關的代碼(無關位進行刪節)所示:是我的觀點數學錯了嗎?
(APP_WIDTH = 1000,APP_HEIGHT = 1000)
用法:
glmxMatrix ortho;
glmxGenMatrix(&ortho, GLMX_4X4); //This simply loads the identity matrix.
glmxLoadPerspective(&ortho, 45.0f, APP_WIDTH/APP_HEIGHT, 1.0f, 10.0f); //Implementation below.
glmxMatrix modelview;
glmxGenMatrix(&modelview, GLMX_4X4); //Same as above.
const GLfloat verts[] = {
//verts
100.0f, 100.0f, -3.0f, 1.0f,
200.0f, 200.0f, -3.0f, 1.0f,
100.0f, 200.0f, -3.0f, 1.0f,
200.0f, 100.0f, -3.0f, 1.0f,
//colors
1.0f, 0.3f, 0.4f, 0.5f,
0.5f, 0.1f, 0.4f, 0.3f,
0.0f, 1.0f, 0.5f, 0.6f,
0.0f, 1.0f, 0.5f, 0.6f,
};
glmxMultMatrix(&ortho, &modelview);
截FUNC:
glmxvoid glmxLoadFrustrum(glmxMatrix* matrix, glmxfloat left, glmxfloat right, glmxfloat bottom,
glmxfloat top, glmxfloat near, glmxfloat far){
if(matrix -> mx_type != GLMX_4X4){GLMX_ERROR = GLMX_NOT_4X4; return;}
matrix -> mx_data[0] = (2.0f * near)/(right - left);
matrix -> mx_data[1] = 0.0f;
matrix -> mx_data[2] = 0.0f;
matrix -> mx_data[3] = 0.0f;
matrix -> mx_data[4] = 0.0f;
matrix -> mx_data[5] = (2.0f * near)/(top - bottom);
matrix -> mx_data[6] = 0.0f;
matrix -> mx_data[7] = 0.0f;
matrix -> mx_data[8] = (right + left)/(right - left);
matrix -> mx_data[9] = (top + bottom)/(top - bottom);
matrix -> mx_data[10] = (-far - near)/(far - near);
matrix -> mx_data[11] = -1.0f;
matrix -> mx_data[12] = 0.0f;
matrix -> mx_data[13] = 0.0f;
matrix -> mx_data[14] = -(2.0f * near) * far/(far - near);
matrix -> mx_data[15] = 0.0f;
}
視角FUNC:
glmxvoid glmxLoadPerspective(glmxMatrix* matrix, glmxfloat fovy, glmxfloat aspect, glmxfloat near,
glmxfloat far){
glmxfloat ymax = near * tanf(fovy * GLMX_PI/360.0f), xmax = ymax * aspect;
glmxLoadFrustrum(matrix, -xmax, xmax, -ymax, ymax, near, far);
}