Reviewed example with new maths

This commit is contained in:
raysan5 2017-07-22 13:02:02 +02:00
parent cbb134946c
commit 2fc7bc9504

View File

@ -128,14 +128,15 @@ int main(void)
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rlClearScreenBuffers(); // Clear current framebuffer rlClearScreenBuffers(); // Clear current framebuffer
// Draw '3D' elements in the scene
//-----------------------------------------------
// Calculate projection matrix (from perspective) and view matrix from camera look at // Calculate projection matrix (from perspective) and view matrix from camera look at
Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, (double)screenWidth/(double)screenHeight, 0.01, 1000.0); Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, (double)screenWidth/(double)screenHeight, 0.01, 1000.0);
MatrixTranspose(&matProj);
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
SetMatrixModelview(matView); // Replace internal modelview matrix by a custom one SetMatrixModelview(matView); // Set internal modelview matrix (default shader)
SetMatrixProjection(matProj); // Replace internal projection matrix by a custom one SetMatrixProjection(matProj); // Set internal projection matrix (default shader)
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, RAYWHITE); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, RAYWHITE);
@ -143,16 +144,17 @@ int main(void)
// NOTE: Internal buffers drawing (3D data) // NOTE: Internal buffers drawing (3D data)
rlglDraw(); rlglDraw();
//-----------------------------------------------
// Draw '2D' elements in the scene (GUI) // Draw '2D' elements in the scene (GUI)
//-----------------------------------------------
#define RLGL_CREATE_MATRIX_MANUALLY #define RLGL_CREATE_MATRIX_MANUALLY
#if defined(RLGL_CREATE_MATRIX_MANUALLY) #if defined(RLGL_CREATE_MATRIX_MANUALLY)
matProj = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); matProj = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0);
MatrixTranspose(&matProj);
matView = MatrixIdentity(); matView = MatrixIdentity();
SetMatrixModelview(matView); // Replace internal modelview matrix by a custom one SetMatrixModelview(matView); // Set internal modelview matrix (default shader)
SetMatrixProjection(matProj); // Replace internal projection matrix by a custom one SetMatrixProjection(matProj); // Set internal projection matrix (default shader)
#else // Let rlgl generate and multiply matrix internally #else // Let rlgl generate and multiply matrix internally
@ -166,6 +168,7 @@ int main(void)
// NOTE: Internal buffers drawing (2D data) // NOTE: Internal buffers drawing (2D data)
rlglDraw(); rlglDraw();
//-----------------------------------------------
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();