Organizing Code. (Deleted lookAt as it is available as part of GLM.)
This commit is contained in:
parent
81d4b67030
commit
083f4785ae
11
graphics.cc
11
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);
|
||||
}
|
||||
|
14
graphics.hh
Normal file
14
graphics.hh
Normal file
@ -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);
|
44
main.cc
44
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) {
|
||||
|
37
main.hh
37
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);
|
||||
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user