From ea08fea654b4702a77f623b74137fabc7d6800d8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 16 Dec 2009 14:58:56 +0100 Subject: Use perspective projection matrix without far clipping plane. --- CMakeLists.txt | 6 +++++- src/CMakeLists.txt | 3 ++- src/Game.cpp | 4 +++- src/MathUtil.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/MathUtil.h | 37 +++++++++++++++++++++++++++++++++++++ src/gl.h | 1 - src/zoom.cpp | 5 +++-- 7 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 src/MathUtil.cpp create mode 100644 src/MathUtil.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a57452..af00fd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,11 @@ project(ZOOM) set(CMAKE_MODULE_PATH ${ZOOM_SOURCE_DIR}) 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(GLPng REQUIRED) find_package(LibXml2 REQUIRED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e1c9378..6b56713 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,10 +4,11 @@ add_executable(zoom config.h gl.h Level.cpp Level.h + MathUtil.cpp MathUtil.h Renderer.cpp Renderer.h Shader.cpp Shader.h Texture.cpp Texture.h Triangle.h 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}) diff --git a/src/Game.cpp b/src/Game.cpp index d4991ed..487019c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -18,10 +18,12 @@ */ #include "Game.h" + #include "BSPTree.h" #include "Level.h" #include "Shader.h" #include "Triangle.h" + #include "gl.h" #include @@ -61,7 +63,7 @@ Game::Game(bool multisample) : playerPos(vmml::vec3f::ZERO), playerRot(vmml::mat Shader::loadProgram("default.vert", "default.frag"); - playerRot.rotate_y(M_PI/6); + playerRot.rotate_y(-M_PI/6); loadLevel("level.xml"); triangles.insert(triangles.end(), level->getRooms().front().walls.begin(), level->getRooms().front().walls.end()); diff --git a/src/MathUtil.cpp b/src/MathUtil.cpp new file mode 100644 index 0000000..3905450 --- /dev/null +++ b/src/MathUtil.cpp @@ -0,0 +1,38 @@ +/* + * MathUtil.cpp + * + * Copyright (C) 2009 Matthias Schiffer + * + * 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 . + */ + +#include "MathUtil.h" +#include + +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; +} + +} diff --git a/src/MathUtil.h b/src/MathUtil.h new file mode 100644 index 0000000..2376c2d --- /dev/null +++ b/src/MathUtil.h @@ -0,0 +1,37 @@ +/* + * MathUtil.h + * + * Copyright (C) 2009 Matthias Schiffer + * + * 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 . + */ + +#ifndef ZOOM_MATHUTIL_H_ +#define ZOOM_MATHUTIL_H_ + +#include + +namespace Zoom { + +class MathUtil { + public: + static vmml::mat4f perspective(float fovy, float aspect, float zNear); + + private: + MathUtil(); +}; + +} + +#endif /* ZOOM_MATHUTIL_H_ */ diff --git a/src/gl.h b/src/gl.h index 3272b25..cc71ce8 100644 --- a/src/gl.h +++ b/src/gl.h @@ -27,6 +27,5 @@ #include #include -#include #endif /* ZOOM_GL_H_ */ diff --git a/src/zoom.cpp b/src/zoom.cpp index d9df6d4..b222286 100644 --- a/src/zoom.cpp +++ b/src/zoom.cpp @@ -18,9 +18,11 @@ */ #include "Game.h" +#include "MathUtil.h" #include "config.h" #include "gl.h" + #ifdef _WIN32 #else #include @@ -38,8 +40,7 @@ void resize(int width, int height) glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(50.0f, (GLfloat)width/(GLfloat)height, 0.1, 1000); + glLoadMatrixf(Zoom::MathUtil::perspective(50.0f, (float)width/(float)height, 0.1).array); glMatrixMode(GL_MODELVIEW); -- cgit v1.2.3