From 083f4785ae55ea86d04f148f3eebf6531bb62380 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 20 Oct 2014 18:16:47 +0200 Subject: [PATCH] Organizing Code. (Deleted lookAt as it is available as part of GLM.) --- graphics.cc | 11 +++++++++++ graphics.hh | 14 ++++++++++++++ main.cc | 44 -------------------------------------------- main.hh | 37 ++++--------------------------------- 4 files changed, 29 insertions(+), 77 deletions(-) create mode 100644 graphics.hh diff --git a/graphics.cc b/graphics.cc index 5d94802..10039eb 100644 --- a/graphics.cc +++ b/graphics.cc @@ -79,3 +79,14 @@ void resizeCallback( GLFWwindow *, int newWidth, int newHeight ) g_windowSize = glm::uvec2( newWidth, newHeight); glViewport( 0, 0, g_windowSize.x, g_windowSize.y ); } + +glm::mat4 buildFrustum( float phiInDegree, float _near, float _far, float aspectRatio) { + + float phiHalfInRadians = 0.5*phiInDegree * (M_PI/180.0); + float top = _near * tan( phiHalfInRadians ); + float bottom = -top; + float left = bottom * aspectRatio; + float right = -left; + + return glm::frustum(left, right, bottom, top, _near, _far); +} diff --git a/graphics.hh b/graphics.hh new file mode 100644 index 0000000..1e919bc --- /dev/null +++ b/graphics.hh @@ -0,0 +1,14 @@ +// gets called after the OpenGL window is prepared, init of example specific stuff: +void initCustomResources(); + +// gets called at application shutdown: +void deleteCustomResources(); + +// gets called ech frame, runTime is in seconds: +void draw( float runTime ); + +// gets called at window resize: +void resizeCallback( GLFWwindow *, int newWidth, int newHeight ); + +// to build the projection matrix: +glm::mat4 buildFrustum( float phiInDegree, float near, float far, float aspectRatio); diff --git a/main.cc b/main.cc index d9fcaee..a4d9795 100644 --- a/main.cc +++ b/main.cc @@ -113,50 +113,6 @@ bool createWindow() return true; } -glm::mat4 buildFrustum( float phiInDegree, float _near, float _far, float aspectRatio) { - - float phiHalfInRadians = 0.5*phiInDegree * (M_PI/180.0); - float top = _near * tan( phiHalfInRadians ); - float bottom = -top; - float left = bottom * aspectRatio; - float right = -left; - - return glm::frustum(left, right, bottom, top, _near, _far); -} - -glm::mat4 lookAt(const glm::vec3 &camPos, const glm::vec3 &viewDirection, const glm::vec3 &up) { - - glm::vec3 right = glm::normalize( glm::cross( viewDirection, up ) ); - glm::vec3 orthoUp = glm::normalize( glm::cross( right, viewDirection ) ); - - glm::vec3 viewDir = glm::normalize( viewDirection ); - glm::mat4 m; - - m[0][0] = right.x; - m[1][0] = right.y; - m[2][0] = right.z; - m[3][0] = 0; - - m[0][1] = orthoUp.x; - m[1][1] = orthoUp.y; - m[2][1] = orthoUp.z; - m[3][1] = 0; - - m[0][2] = -viewDir.x; - m[1][2] = -viewDir.y; - m[2][2] = -viewDir.z; - m[3][2] = 0; - - m[0][3] = 0; - m[1][3] = 0; - m[2][3] = 0; - m[3][3] = 1.0; - - glm::mat4 tr = glm::translate(glm::mat4(),glm::vec3( -camPos.x, -camPos.y, -camPos.z)); - - return m*tr; -} - static void keyCallback(GLFWwindow* _window, int _key, int, int _action, int) { if (_key == GLFW_KEY_ESCAPE && _action == GLFW_PRESS) { diff --git a/main.hh b/main.hh index 54d87ed..dfc33d3 100644 --- a/main.hh +++ b/main.hh @@ -10,6 +10,10 @@ // /////////////////////////////////////////////////////////////////////////////////////////////////// +#include "physics.hh" +#include "graphics.hh" +#include "level.hh" + /////////////////////////////////////////////////////////////////////////////////////////////////// // // implement the following functions: @@ -21,36 +25,3 @@ extern float g_nearPlane; extern float g_farPlane; // /////////////////////////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// -// implement the following functions: -// - -// gets called after the OpenGL window is prepared, init of example specific stuff: -void initCustomResources(); - -// gets called at application shutdown: -void deleteCustomResources(); - -// gets called ech frame, runTime is in seconds: -void draw( float runTime ); - -// gets called at window resize: -void resizeCallback( GLFWwindow *, int newWidth, int newHeight ); -// -/////////////////////////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// -// useful functions: -// - -// to build the projection matrix: -glm::mat4 buildFrustum( float phiInDegree, float near, float far, float aspectRatio); - -// to build the view matrix: -glm::mat4 lookAt(const glm::vec3 &camPos, const glm::vec3 &viewDirection, const glm::vec3 &up); - -// -///////////////////////////////////////////////////////////////////////////////////////////////////