Use perspective projection matrix without far clipping plane.
This commit is contained in:
parent
a407f8b9ed
commit
ea08fea654
7 changed files with 88 additions and 6 deletions
|
@ -4,7 +4,11 @@ project(ZOOM)
|
||||||
set(CMAKE_MODULE_PATH ${ZOOM_SOURCE_DIR})
|
set(CMAKE_MODULE_PATH ${ZOOM_SOURCE_DIR})
|
||||||
|
|
||||||
find_package(Boost REQUIRED)
|
find_package(Boost REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL)
|
||||||
|
IF (NOT OPENGL_FOUND)
|
||||||
|
MESSAGE(FATAL_ERROR "Could not find OpenGL")
|
||||||
|
ENDIF (NOT OPENGL_FOUND)
|
||||||
|
|
||||||
find_package(GLEW REQUIRED)
|
find_package(GLEW REQUIRED)
|
||||||
find_package(GLPng REQUIRED)
|
find_package(GLPng REQUIRED)
|
||||||
find_package(LibXml2 REQUIRED)
|
find_package(LibXml2 REQUIRED)
|
||||||
|
|
|
@ -4,10 +4,11 @@ add_executable(zoom
|
||||||
config.h
|
config.h
|
||||||
gl.h
|
gl.h
|
||||||
Level.cpp Level.h
|
Level.cpp Level.h
|
||||||
|
MathUtil.cpp MathUtil.h
|
||||||
Renderer.cpp Renderer.h
|
Renderer.cpp Renderer.h
|
||||||
Shader.cpp Shader.h
|
Shader.cpp Shader.h
|
||||||
Texture.cpp Texture.h
|
Texture.cpp Texture.h
|
||||||
Triangle.h
|
Triangle.h
|
||||||
zoom.cpp
|
zoom.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(zoom ${Boost_LIBRARIES} ${OPENGL_LIBRARIES} ${GLEW_LIBRARY} ${GLPNG_LIBRARY} ${LIBXML2_LIBRARIES})
|
target_link_libraries(zoom ${Boost_LIBRARIES} ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARY} ${GLPNG_LIBRARY} ${LIBXML2_LIBRARIES})
|
||||||
|
|
|
@ -18,10 +18,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
|
||||||
#include "BSPTree.h"
|
#include "BSPTree.h"
|
||||||
#include "Level.h"
|
#include "Level.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
#include "Triangle.h"
|
#include "Triangle.h"
|
||||||
|
|
||||||
#include "gl.h"
|
#include "gl.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -61,7 +63,7 @@ Game::Game(bool multisample) : playerPos(vmml::vec3f::ZERO), playerRot(vmml::mat
|
||||||
|
|
||||||
Shader::loadProgram("default.vert", "default.frag");
|
Shader::loadProgram("default.vert", "default.frag");
|
||||||
|
|
||||||
playerRot.rotate_y(M_PI/6);
|
playerRot.rotate_y(-M_PI/6);
|
||||||
|
|
||||||
loadLevel("level.xml");
|
loadLevel("level.xml");
|
||||||
triangles.insert(triangles.end(), level->getRooms().front().walls.begin(), level->getRooms().front().walls.end());
|
triangles.insert(triangles.end(), level->getRooms().front().walls.begin(), level->getRooms().front().walls.end());
|
||||||
|
|
38
src/MathUtil.cpp
Normal file
38
src/MathUtil.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* MathUtil.cpp
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "MathUtil.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace Zoom {
|
||||||
|
|
||||||
|
vmml::mat4f MathUtil::perspective(float fovy, float aspect, float zNear) {
|
||||||
|
float f = 1/std::tan(fovy*M_PI/360);
|
||||||
|
|
||||||
|
vmml::mat4f ret(vmml::mat4f::ZERO);
|
||||||
|
ret[0][0] = f/aspect;
|
||||||
|
ret[1][1] = f;
|
||||||
|
ret[2][2] = -1;
|
||||||
|
ret[2][3] = -2*zNear;
|
||||||
|
ret[3][2] = -1;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
src/MathUtil.h
Normal file
37
src/MathUtil.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* MathUtil.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZOOM_MATHUTIL_H_
|
||||||
|
#define ZOOM_MATHUTIL_H_
|
||||||
|
|
||||||
|
#include <vmmlib/matrix.hpp>
|
||||||
|
|
||||||
|
namespace Zoom {
|
||||||
|
|
||||||
|
class MathUtil {
|
||||||
|
public:
|
||||||
|
static vmml::mat4f perspective(float fovy, float aspect, float zNear);
|
||||||
|
|
||||||
|
private:
|
||||||
|
MathUtil();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ZOOM_MATHUTIL_H_ */
|
1
src/gl.h
1
src/gl.h
|
@ -27,6 +27,5 @@
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
|
||||||
|
|
||||||
#endif /* ZOOM_GL_H_ */
|
#endif /* ZOOM_GL_H_ */
|
||||||
|
|
|
@ -18,9 +18,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
#include "MathUtil.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gl.h"
|
#include "gl.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#else
|
#else
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -38,8 +40,7 @@ void resize(int width, int height)
|
||||||
|
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadMatrixf(Zoom::MathUtil::perspective(50.0f, (float)width/(float)height, 0.1).array);
|
||||||
gluPerspective(50.0f, (GLfloat)width/(GLfloat)height, 0.1, 1000);
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
|
|
Reference in a new issue