summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-12-16 14:58:56 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-12-16 14:58:56 +0100
commitea08fea654b4702a77f623b74137fabc7d6800d8 (patch)
tree7550e20704ee9a93e6b1ea95d72563250956ac17
parenta407f8b9edbc7a6e865b2daf65b2a6cd10edd2d7 (diff)
downloadzoom++-ea08fea654b4702a77f623b74137fabc7d6800d8.tar
zoom++-ea08fea654b4702a77f623b74137fabc7d6800d8.zip
Use perspective projection matrix without far clipping plane.
-rw-r--r--CMakeLists.txt6
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/Game.cpp4
-rw-r--r--src/MathUtil.cpp38
-rw-r--r--src/MathUtil.h37
-rw-r--r--src/gl.h1
-rw-r--r--src/zoom.cpp5
7 files changed, 88 insertions, 6 deletions
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 <algorithm>
@@ -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 <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;
+}
+
+}
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 <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_ */
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 <GL/glew.h>
#include <GL/gl.h>
-#include <GL/glu.h>
#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 <iostream>
@@ -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);