Added everything... -.-
83
BSPTree.cpp
|
@ -1,5 +1,23 @@
|
||||||
#include "BSPTree.h"
|
/*
|
||||||
|
* BSPTree.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 "BSPTree.h"
|
||||||
|
|
||||||
namespace Zoom {
|
namespace Zoom {
|
||||||
|
|
||||||
|
@ -9,20 +27,20 @@ vmml::vec3f BSPTree::Plane::intersection(const vmml::vec3f &p, const vmml::vec3f
|
||||||
return p + r*dir;
|
return p + r*dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BSPTree::Plane::partition(const Triangle &t, std::list<Triangle> *front, std::list<Triangle> *back) const {
|
void BSPTree::Plane::partition(const TriangleRecord &t, std::list<TriangleRecord> *front, std::list<TriangleRecord> *back) const {
|
||||||
for(int i = 0; i < 3; ++i) {
|
for(int i = 0; i < 3; ++i) {
|
||||||
if(contains(t.getVertex(i))) {
|
if(contains(t.triangle.getVertex(i))) {
|
||||||
const vmml::vec3f *v[3] = {&t.getVertex(i), &t.getVertex((i+1)%3), &t.getVertex((i+2)%3)};
|
const vmml::vec3f *v[3] = {&t.triangle.getVertex(i), &t.triangle.getVertex((i+1)%3), &t.triangle.getVertex((i+2)%3)};
|
||||||
|
|
||||||
vmml::vec3f is = intersection(*v[1], *v[2]-*v[1]);
|
vmml::vec3f is = intersection(*v[1], *v[2]-*v[1]);
|
||||||
|
|
||||||
if(isInFront(*v[1])) {
|
if(isInFront(*v[1])) {
|
||||||
front->push_back(Triangle(*v[0], *v[1], is, t.getColor()));
|
front->push_back(TriangleRecord(Triangle(*v[0], *v[1], is, t.triangle.getColor()), t.data));
|
||||||
back->push_back(Triangle(*v[0], is, *v[2], t.getColor()));
|
back->push_back(TriangleRecord(Triangle(*v[0], is, *v[2], t.triangle.getColor()), t.data));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
back->push_back(Triangle(*v[0], *v[1], is, t.getColor()));
|
back->push_back(TriangleRecord(Triangle(*v[0], *v[1], is, t.triangle.getColor()), t.data));
|
||||||
front->push_back(Triangle(*v[0], is, *v[2], t.getColor()));
|
front->push_back(TriangleRecord(Triangle(*v[0], is, *v[2], t.triangle.getColor()), t.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -30,7 +48,7 @@ void BSPTree::Plane::partition(const Triangle &t, std::list<Triangle> *front, st
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; ++i) {
|
for(int i = 0; i < 3; ++i) {
|
||||||
const vmml::vec3f *v[3] = {&t.getVertex(i), &t.getVertex((i+1)%3), &t.getVertex((i+2)%3)};
|
const vmml::vec3f *v[3] = {&t.triangle.getVertex(i), &t.triangle.getVertex((i+1)%3), &t.triangle.getVertex((i+2)%3)};
|
||||||
|
|
||||||
if((isInFront(*v[0]) && isBehind(*v[1]) && isBehind(*v[2]))
|
if((isInFront(*v[0]) && isBehind(*v[1]) && isBehind(*v[2]))
|
||||||
|| (isBehind(*v[0]) && isInFront(*v[1]) && isInFront(*v[2]))) {
|
|| (isBehind(*v[0]) && isInFront(*v[1]) && isInFront(*v[2]))) {
|
||||||
|
@ -38,14 +56,14 @@ void BSPTree::Plane::partition(const Triangle &t, std::list<Triangle> *front, st
|
||||||
vmml::vec3f is2 = intersection(*v[0], *v[2]-*v[0]);
|
vmml::vec3f is2 = intersection(*v[0], *v[2]-*v[0]);
|
||||||
|
|
||||||
if(isInFront(*v[0])) {
|
if(isInFront(*v[0])) {
|
||||||
front->push_back(Triangle(*v[0], is1, is2, t.getColor()));
|
front->push_back(TriangleRecord(Triangle(*v[0], is1, is2, t.triangle.getColor()), t.data));
|
||||||
back->push_back(Triangle(is1, *v[1], is2, t.getColor()));
|
back->push_back(TriangleRecord(Triangle(is1, *v[1], is2, t.triangle.getColor()), t.data));
|
||||||
back->push_back(Triangle(*v[1], *v[2], is2, t.getColor()));
|
back->push_back(TriangleRecord(Triangle(*v[1], *v[2], is2, t.triangle.getColor()), t.data));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
back->push_back(Triangle(*v[0], is1, is2, t.getColor()));
|
back->push_back(TriangleRecord(Triangle(*v[0], is1, is2, t.triangle.getColor()), t.data));
|
||||||
front->push_back(Triangle(is1, *v[1], is2, t.getColor()));
|
front->push_back(TriangleRecord(Triangle(is1, *v[1], is2, t.triangle.getColor()), t.data));
|
||||||
front->push_back(Triangle(*v[1], *v[2], is2, t.getColor()));
|
front->push_back(TriangleRecord(Triangle(*v[1], *v[2], is2, t.triangle.getColor()), t.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -54,7 +72,7 @@ void BSPTree::Plane::partition(const Triangle &t, std::list<Triangle> *front, st
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BSPTree::BSPTree(const std::list<Triangle> &triangles) : frontTree(0), backTree(0) {
|
BSPTree::BSPTree(const std::list<TriangleRecord> &triangles) : frontTree(0), backTree(0) {
|
||||||
const Triangle *planeT = findNearestTriangle(triangles, findCenter(triangles));
|
const Triangle *planeT = findNearestTriangle(triangles, findCenter(triangles));
|
||||||
|
|
||||||
if(!planeT)
|
if(!planeT)
|
||||||
|
@ -62,29 +80,26 @@ BSPTree::BSPTree(const std::list<Triangle> &triangles) : frontTree(0), backTree(
|
||||||
|
|
||||||
plane = Plane(*planeT);
|
plane = Plane(*planeT);
|
||||||
|
|
||||||
std::list<Triangle> front, back;
|
std::list<TriangleRecord> front, back;
|
||||||
|
|
||||||
for(std::list<Triangle>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
for(std::list<TriangleRecord>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
||||||
if(t->getNormal().squared_length() == 0)
|
if(t->triangle.isDegenerate())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(plane.contains(*t)) {
|
if(plane.contains(t->triangle)) {
|
||||||
this->triangles.push_back(*t);
|
this->triangles.push_back(*t);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(plane.isInFront(*t)) {
|
else if(plane.isInFront(t->triangle)) {
|
||||||
front.push_back(*t);
|
front.push_back(*t);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(plane.isBehind(*t)) {
|
else if(plane.isBehind(t->triangle)) {
|
||||||
back.push_back(*t);
|
back.push_back(*t);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Triangle> frontPart, backPart;
|
plane.partition(*t, &front, &back);
|
||||||
plane.partition(*t, &frontPart, &backPart);
|
|
||||||
front.splice(front.end(), frontPart);
|
|
||||||
back.splice(back.end(), backPart);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!front.empty())
|
if(!front.empty())
|
||||||
|
@ -117,28 +132,28 @@ BSPTree& BSPTree::operator=(const BSPTree &tree) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
vmml::vec3f BSPTree::findCenter(const std::list<Triangle> &triangles) {
|
vmml::vec3f BSPTree::findCenter(const std::list<TriangleRecord> &triangles) {
|
||||||
vmml::vec3f v;
|
vmml::vec3f v;
|
||||||
|
|
||||||
for(std::list<Triangle>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
for(std::list<TriangleRecord>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
||||||
v += t->getCenter();
|
v += t->triangle.getCenter();
|
||||||
}
|
}
|
||||||
|
|
||||||
return v/triangles.size();
|
return v/triangles.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Triangle* BSPTree::findNearestTriangle(const std::list<Triangle> &triangles, const vmml::vec3f &v) {
|
const Triangle* BSPTree::findNearestTriangle(const std::list<TriangleRecord> &triangles, const vmml::vec3f &v) {
|
||||||
const Triangle *current = 0;
|
const Triangle *current = 0;
|
||||||
float distanceSq;
|
float distanceSq;
|
||||||
|
|
||||||
for(std::list<Triangle>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
for(std::list<TriangleRecord>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
||||||
if(t->getNormal().squared_length() == 0)
|
if(t->triangle.isDegenerate())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float d = t->getCenter().squared_distance(v);
|
float d = t->triangle.getCenter().squared_distance(v);
|
||||||
|
|
||||||
if(!current || d < distanceSq) {
|
if(!current || d < distanceSq) {
|
||||||
current = &*t;
|
current = &t->triangle;
|
||||||
distanceSq = d;
|
distanceSq = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
93
BSPTree.h
|
@ -1,20 +1,61 @@
|
||||||
|
/*
|
||||||
|
* BSPTree.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_BSPTREE_H_
|
#ifndef ZOOM_BSPTREE_H_
|
||||||
#define ZOOM_BSPTREE_H_
|
#define ZOOM_BSPTREE_H_
|
||||||
|
|
||||||
#include "Triangle.h"
|
#include "Triangle.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include <vmmlib/vector.hpp>
|
#include <vmmlib/vector.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
namespace Zoom {
|
namespace Zoom {
|
||||||
|
|
||||||
class BSPTree {
|
class BSPTree {
|
||||||
|
public:
|
||||||
|
class TriangleData {
|
||||||
|
protected:
|
||||||
|
TriangleData() {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~TriangleData() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TriangleRecord {
|
||||||
|
public:
|
||||||
|
TriangleRecord(Triangle triangle0, boost::shared_ptr<TriangleData> data0)
|
||||||
|
: triangle(triangle0), data(data0) {}
|
||||||
|
TriangleRecord(Triangle triangle0) : triangle(triangle0) {}
|
||||||
|
TriangleRecord() {}
|
||||||
|
|
||||||
|
Triangle triangle;
|
||||||
|
boost::shared_ptr<TriangleData> data;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Plane {
|
class Plane {
|
||||||
public:
|
public:
|
||||||
Plane() : d(0) {}
|
Plane() : d(0) {}
|
||||||
Plane(const vmml::vec3f &n, float d0) : normal(n), d(d0) {}
|
Plane(const vmml::vec3f &n, float d0) : normal(n), d(d0) {}
|
||||||
Plane(const Triangle &t) : normal(t.getNormal()), d(t.getVertex(0).dot(normal)) {}
|
Plane(const Triangle &t) : normal(t.computeNormal()), d(t.getVertex(0).dot(normal)) {}
|
||||||
|
|
||||||
bool contains(const vmml::vec3f &v) const {
|
bool contains(const vmml::vec3f &v) const {
|
||||||
return (fabsf(normal.dot(v) - d) < 1E-6);
|
return (fabsf(normal.dot(v) - d) < 1E-6);
|
||||||
|
@ -62,7 +103,7 @@ class BSPTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
vmml::vec3f intersection(const vmml::vec3f &p, const vmml::vec3f &dir) const;
|
vmml::vec3f intersection(const vmml::vec3f &p, const vmml::vec3f &dir) const;
|
||||||
void partition(const Triangle &t, std::list<Triangle> *front, std::list<Triangle> *back) const;
|
void partition(const TriangleRecord &t, std::list<TriangleRecord> *front, std::list<TriangleRecord> *back) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vmml::vec3f normal;
|
vmml::vec3f normal;
|
||||||
|
@ -70,7 +111,7 @@ class BSPTree {
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BSPTree(const std::list<Triangle> &triangles);
|
BSPTree(const std::list<TriangleRecord> &triangles);
|
||||||
|
|
||||||
BSPTree(const BSPTree &tree) : frontTree(0), backTree(0) {
|
BSPTree(const BSPTree &tree) : frontTree(0), backTree(0) {
|
||||||
*this = tree;
|
*this = tree;
|
||||||
|
@ -86,16 +127,6 @@ class BSPTree {
|
||||||
|
|
||||||
BSPTree& operator=(const BSPTree &tree);
|
BSPTree& operator=(const BSPTree &tree);
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void visit(const T& visitor, const vmml::vec3f &p) {
|
|
||||||
doVisit<const T>(visitor, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void visit(T& visitor, const vmml::vec3f &p) {
|
|
||||||
doVisit(visitor, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void visit(const T& visitor, const vmml::vec3f &p) const {
|
void visit(const T& visitor, const vmml::vec3f &p) const {
|
||||||
doVisit<const T>(visitor, p);
|
doVisit<const T>(visitor, p);
|
||||||
|
@ -108,42 +139,16 @@ class BSPTree {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Plane plane;
|
Plane plane;
|
||||||
std::list<Triangle> triangles;
|
std::list<TriangleRecord> triangles;
|
||||||
BSPTree *frontTree, *backTree;
|
BSPTree *frontTree, *backTree;
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void doVisit(T& visitor, const vmml::vec3f &p) {
|
|
||||||
if(plane.isBehind(p)) {
|
|
||||||
if(frontTree)
|
|
||||||
frontTree->visit(visitor, p);
|
|
||||||
|
|
||||||
for(std::list<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
|
||||||
visitor(*t);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(backTree)
|
|
||||||
backTree->visit(visitor, p);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(backTree)
|
|
||||||
backTree->visit(visitor, p);
|
|
||||||
|
|
||||||
for(std::list<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
|
||||||
visitor(*t);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(frontTree)
|
|
||||||
frontTree->visit(visitor, p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void doVisit(T& visitor, const vmml::vec3f &p) const {
|
void doVisit(T& visitor, const vmml::vec3f &p) const {
|
||||||
if(plane.isBehind(p)) {
|
if(plane.isBehind(p)) {
|
||||||
if(frontTree)
|
if(frontTree)
|
||||||
frontTree->visit(visitor, p);
|
frontTree->visit(visitor, p);
|
||||||
|
|
||||||
for(std::list<Triangle>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
for(std::list<TriangleRecord>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
||||||
visitor(*t);
|
visitor(*t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +159,7 @@ class BSPTree {
|
||||||
if(backTree)
|
if(backTree)
|
||||||
backTree->visit(visitor, p);
|
backTree->visit(visitor, p);
|
||||||
|
|
||||||
for(std::list<Triangle>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
for(std::list<TriangleRecord>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
||||||
visitor(*t);
|
visitor(*t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,8 +168,8 @@ class BSPTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static vmml::vec3f findCenter(const std::list<Triangle> &triangles);
|
static vmml::vec3f findCenter(const std::list<TriangleRecord> &triangles);
|
||||||
static const Triangle* findNearestTriangle(const std::list<Triangle> &triangles, const vmml::vec3f &v);
|
static const Triangle* findNearestTriangle(const std::list<TriangleRecord> &triangles, const vmml::vec3f &v);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,25 @@
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 2.6)
|
||||||
project(ZOOM)
|
project(ZOOM)
|
||||||
|
|
||||||
find_package(OpenGL REQUIRED)
|
set(CMAKE_MODULE_PATH ${ZOOM_SOURCE_DIR})
|
||||||
|
|
||||||
include_directories(${OPENGL_INCLUDE_DIR})
|
find_package(Boost REQUIRED)
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
find_package(GLPng REQUIRED)
|
||||||
|
find_package(LibXml2 REQUIRED)
|
||||||
|
|
||||||
|
include_directories(${Boost_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${GLPNG_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR})
|
||||||
|
|
||||||
add_executable(zoom
|
add_executable(zoom
|
||||||
BSPTree.cpp BSPTree.h
|
BSPTree.cpp BSPTree.h
|
||||||
Game.cpp Game.h
|
Game.cpp Game.h
|
||||||
config.h
|
config.h
|
||||||
gl.h
|
gl.h
|
||||||
|
Level.cpp Level.h
|
||||||
Renderer.cpp Renderer.h
|
Renderer.cpp Renderer.h
|
||||||
|
Texture.cpp Texture.h
|
||||||
Triangle.h
|
Triangle.h
|
||||||
zoom.cpp
|
zoom.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(zoom ${OPENGL_LIBRARIES})
|
target_link_libraries(zoom ${Boost_LIBRARIES} ${OPENGL_LIBRARIES} ${GLPNG_LIBRARY} ${LIBXML2_LIBRARIES})
|
||||||
|
|
16
FindGLPng.cmake
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
FIND_PATH(GLPNG_INCLUDE_DIR GL/glpng.h)
|
||||||
|
FIND_LIBRARY(GLPNG_LIBRARY NAMES glpng)
|
||||||
|
|
||||||
|
IF (GLPNG_INCLUDE_DIR AND GLPNG_LIBRARY)
|
||||||
|
SET(GLPNG_FOUND TRUE)
|
||||||
|
ENDIF (GLPNG_INCLUDE_DIR AND GLPNG_LIBRARY)
|
||||||
|
|
||||||
|
IF (GLPNG_FOUND)
|
||||||
|
IF (NOT GLPng_FIND_QUIETLY)
|
||||||
|
MESSAGE(STATUS "Found glpng: ${GLPNG_LIBRARY}")
|
||||||
|
ENDIF (NOT GLPng_FIND_QUIETLY)
|
||||||
|
ELSE (GLPNG_FOUND)
|
||||||
|
IF (GLPng_FIND_REQUIRED)
|
||||||
|
MESSAGE(FATAL_ERROR "Could not find glpng")
|
||||||
|
ENDIF (GLPng_FIND_REQUIRED)
|
||||||
|
ENDIF (GLPNG_FOUND)
|
47
Game.cpp
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "BSPTree.h"
|
#include "BSPTree.h"
|
||||||
|
#include "Level.h"
|
||||||
#include "Triangle.h"
|
#include "Triangle.h"
|
||||||
#include "gl.h"
|
#include "gl.h"
|
||||||
|
|
||||||
|
@ -26,8 +27,9 @@ namespace Zoom {
|
||||||
|
|
||||||
Game::Game(bool multisample) : angle(0) {
|
Game::Game(bool multisample) : angle(0) {
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||||
//glEnable(GL_DEPTH_TEST);
|
glClearDepth(1.0);
|
||||||
//glDepthFunc(GL_LEQUAL);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
|
||||||
//glEnable(GL_BLEND);
|
//glEnable(GL_BLEND);
|
||||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
@ -37,43 +39,52 @@ Game::Game(bool multisample) : angle(0) {
|
||||||
glEnable(GL_MULTISAMPLE_ARB);
|
glEnable(GL_MULTISAMPLE_ARB);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*glEnable(GL_LIGHTING);
|
glShadeModel(GL_SMOOTH);
|
||||||
static const float light[] = {1, 1, 1, 0};
|
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
static const float light[] = {0, 0, 0, 1};
|
||||||
static const float lightColor[] = {1, 1, 1, 1};
|
static const float lightColor[] = {1, 1, 1, 1};
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light);
|
glLightfv(GL_LIGHT0, GL_POSITION, light);
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
|
||||||
glEnable(GL_LIGHT0);*/
|
glEnable(GL_LIGHT0);
|
||||||
|
|
||||||
//glEnable(GL_CULL_FACE);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
//glFrontFace(GL_CCW);
|
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
||||||
|
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glFrontFace(GL_CCW);
|
||||||
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0, 0, -5);
|
|
||||||
|
loadLevel("level.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Game::loadLevel(const std::string &name) {
|
||||||
|
level = Level::loadLevel(name);
|
||||||
|
|
||||||
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::run(int delta) {
|
void Game::run(int delta) {
|
||||||
angle += delta*0.2;
|
angle += delta*0.01;
|
||||||
|
|
||||||
if(angle >= 360)
|
if(angle >= 360)
|
||||||
angle -= 360;
|
angle -= 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::render() {
|
void Game::render() {
|
||||||
std::list<Triangle> triangles;
|
std::list<BSPTree::TriangleRecord> triangles;
|
||||||
|
|
||||||
triangles.push_back(Triangle(vmml::vec3f(-1, -1, 0), vmml::vec3f(1, -1, 0), vmml::vec3f(1, 1, 0), vmml::vec3f(0, 1, 0)));
|
triangles.insert(triangles.end(), level->getRooms().front().walls.begin(), level->getRooms().front().walls.end());
|
||||||
triangles.push_back(Triangle(vmml::vec3f(-1, -1, 0), vmml::vec3f(-1, 1, 0), vmml::vec3f(1, 1, 0), vmml::vec3f(0, 1, 0)));
|
|
||||||
triangles.push_back(Triangle(vmml::vec3f(-1, -1, -1), vmml::vec3f(1, -1, -1), vmml::vec3f(1, 1, -1), vmml::vec3f(0, 0, 1)));
|
|
||||||
triangles.push_back(Triangle(vmml::vec3f(-1, -1, -1), vmml::vec3f(-1, 1, -1), vmml::vec3f(1, 1, -1), vmml::vec3f(0, 0, 1)));
|
|
||||||
|
|
||||||
BSPTree tree(triangles);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glRotatef(angle, 1, 2, 1);
|
glRotatef(angle, 1, 2, 1);
|
||||||
|
//glRotatef(3*angle, 0, -1, 2);
|
||||||
|
//glRotatef(5*angle, 2, -1, 0);
|
||||||
|
|
||||||
renderer.render(tree);
|
renderer.render(triangles);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
6
Game.h
|
@ -21,20 +21,26 @@
|
||||||
#define ZOOM_GAME_H_
|
#define ZOOM_GAME_H_
|
||||||
|
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace Zoom {
|
namespace Zoom {
|
||||||
|
|
||||||
|
class Level;
|
||||||
class Triangle;
|
class Triangle;
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
public:
|
public:
|
||||||
Game(bool multisample);
|
Game(bool multisample);
|
||||||
|
|
||||||
|
bool loadLevel(const std::string &name);
|
||||||
|
|
||||||
void run(int delta);
|
void run(int delta);
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Renderer renderer;
|
Renderer renderer;
|
||||||
|
boost::shared_ptr<Level> level;
|
||||||
|
|
||||||
float angle;
|
float angle;
|
||||||
};
|
};
|
||||||
|
|
260
Level.cpp
Normal file
|
@ -0,0 +1,260 @@
|
||||||
|
/*
|
||||||
|
* Level.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 "Level.h"
|
||||||
|
#include "Texture.h"
|
||||||
|
#include <libxml/tree.h>
|
||||||
|
#include <libxml/valid.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace Zoom {
|
||||||
|
|
||||||
|
boost::shared_ptr<Level> Level::loadLevel(const std::string &filename) {
|
||||||
|
boost::shared_ptr<Level> level;
|
||||||
|
|
||||||
|
xmlDocPtr doc = xmlParseFile(("levels/"+filename).c_str());
|
||||||
|
|
||||||
|
if(doc) {
|
||||||
|
if(validateLevel(doc)) {
|
||||||
|
xmlNodePtr root = xmlDocGetRootElement(doc);
|
||||||
|
if(root && !xmlStrcmp(root->name, (xmlChar*)"level")) {
|
||||||
|
level = boost::shared_ptr<Level>(new Level);
|
||||||
|
|
||||||
|
for(xmlNodePtr node = root->children; node != 0; node = node->next) {
|
||||||
|
if(node->type != XML_ELEMENT_NODE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!xmlStrcmp(node->name, (xmlChar*)"info")) {
|
||||||
|
level->loadLevelInfo(node);
|
||||||
|
}
|
||||||
|
else if(!xmlStrcmp(node->name, (xmlChar*)"rooms")) {
|
||||||
|
level->loadRooms(node);
|
||||||
|
}
|
||||||
|
else if(!xmlStrcmp(node->name, (xmlChar*)"textures")) {
|
||||||
|
level->loadTextures(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(std::list<Room>::iterator room = level->rooms.begin(); room != level->rooms.end(); ++room) {
|
||||||
|
for(std::list<BSPTree::TriangleRecord>::iterator wall = room->walls.begin(); wall != room->walls.end(); ++wall) {
|
||||||
|
boost::shared_ptr<WallData> wallData = boost::dynamic_pointer_cast<WallData>(wall->data);
|
||||||
|
|
||||||
|
if(!wallData->texture.empty()) {
|
||||||
|
std::map<std::string, unsigned>::iterator texture = level->textures.find(wallData->texture);
|
||||||
|
|
||||||
|
if(texture != level->textures.end())
|
||||||
|
wall->triangle.setTexture(texture->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlFreeDoc(doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlCleanupParser();
|
||||||
|
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Level::loadLevelInfo(xmlNodePtr infoNode) {
|
||||||
|
for(xmlNodePtr node = infoNode->children; node != 0; node = node->next) {
|
||||||
|
if(node->type != XML_ELEMENT_NODE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!xmlStrcmp(node->name, (xmlChar*)"name")) {
|
||||||
|
xmlChar *data = xmlNodeGetContent(node);
|
||||||
|
name = (char*)data;
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
else if(!xmlStrcmp(node->name, (xmlChar*)"desc")) {
|
||||||
|
xmlChar *data = xmlNodeGetContent(node);
|
||||||
|
description = (char*)data;
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
else if(!xmlStrcmp(node->name, (xmlChar*)"start")) {
|
||||||
|
startPoint = loadVector(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Level::loadRooms(xmlNodePtr roomsNode) {
|
||||||
|
for(xmlNodePtr node = roomsNode->children; node != 0; node = node->next) {
|
||||||
|
if(node->type == XML_ELEMENT_NODE && !xmlStrcmp(node->name, (xmlChar*)"room")) {
|
||||||
|
loadRoom(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Level::loadRoom(xmlNodePtr roomNode) {
|
||||||
|
rooms.push_back(Room());
|
||||||
|
|
||||||
|
xmlChar *data = xmlGetProp(roomNode, (xmlChar*)"id");
|
||||||
|
if(data) {
|
||||||
|
rooms.back().id = (char*)data;
|
||||||
|
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(xmlNodePtr node = roomNode->children; node != 0; node = node->next) {
|
||||||
|
if(node->type == XML_ELEMENT_NODE && !xmlStrcmp(node->name, (xmlChar*)"triangle")) {
|
||||||
|
rooms.back().walls.push_back(loadWall(node));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Level::loadTextures(xmlNodePtr texturesNode) {
|
||||||
|
for(xmlNodePtr node = texturesNode->children; node != 0; node = node->next) {
|
||||||
|
if(node->type == XML_ELEMENT_NODE && !xmlStrcmp(node->name, (xmlChar*)"texture")) {
|
||||||
|
std::string id, name;
|
||||||
|
|
||||||
|
xmlChar *data = xmlGetProp(node, (xmlChar*)"id");
|
||||||
|
if(data) {
|
||||||
|
id = (char*)data;
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
data = xmlGetProp(node, (xmlChar*)"name");
|
||||||
|
if(data) {
|
||||||
|
name = (char*)data;
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!id.empty() && !name.empty()) {
|
||||||
|
unsigned texture = Texture::loadTexture(name);
|
||||||
|
|
||||||
|
if(texture) {
|
||||||
|
textures.insert(std::make_pair(id, texture));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BSPTree::TriangleRecord Level::loadWall(xmlNodePtr wallNode) {
|
||||||
|
boost::shared_ptr<WallData> wallData(new WallData);
|
||||||
|
|
||||||
|
BSPTree::TriangleRecord wall;
|
||||||
|
wall.data = wallData;
|
||||||
|
|
||||||
|
|
||||||
|
xmlChar *data = xmlGetProp(wallNode, (xmlChar*)"texture");
|
||||||
|
if(data) {
|
||||||
|
wallData->texture = (char*)data;
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
int vertexNum = -1;
|
||||||
|
|
||||||
|
for(xmlNodePtr node = wallNode->children; node != 0; node = node->next) {
|
||||||
|
if(node->type != XML_ELEMENT_NODE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!xmlStrcmp(node->name, (xmlChar*)"vertex")) {
|
||||||
|
if(++vertexNum > 2)
|
||||||
|
break;
|
||||||
|
|
||||||
|
wall.triangle.setVertex(vertexNum, loadVector(node));
|
||||||
|
}
|
||||||
|
else if(!xmlStrcmp(node->name, (xmlChar*)"normal")) {
|
||||||
|
if(vertexNum < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
wall.triangle.setNormal(vertexNum, loadVector(node));
|
||||||
|
}
|
||||||
|
else if(!xmlStrcmp(node->name, (xmlChar*)"texcoords")) {
|
||||||
|
if(vertexNum < 0) continue;
|
||||||
|
|
||||||
|
data = xmlGetProp(node, (xmlChar*)"s");
|
||||||
|
if(data) {
|
||||||
|
wall.triangle.getTexCoords(vertexNum)[0] = atof((char*)data);
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
data = xmlGetProp(node, (xmlChar*)"t");
|
||||||
|
if(data) {
|
||||||
|
wall.triangle.getTexCoords(vertexNum)[1] = atof((char*)data);
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vmml::vec3f normal = wall.triangle.computeNormal();
|
||||||
|
|
||||||
|
if(normal.squared_length() > 0) {
|
||||||
|
normal.normalize();
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; ++i) {
|
||||||
|
if(wall.triangle.getNormal(i).squared_length() == 0)
|
||||||
|
wall.triangle.setNormal(i, normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return wall;
|
||||||
|
}
|
||||||
|
|
||||||
|
vmml::vec3f Level::loadVector(xmlNodePtr node) {
|
||||||
|
vmml::vec3f ret(vmml::vec3f::ZERO);
|
||||||
|
|
||||||
|
xmlChar *data = xmlGetProp(node, (xmlChar*)"x");
|
||||||
|
if(data) {
|
||||||
|
ret.x() = atof((char*)data);
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
data = xmlGetProp(node, (xmlChar*)"y");
|
||||||
|
if(data) {
|
||||||
|
ret.y() = atof((char*)data);
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
data = xmlGetProp(node, (xmlChar*)"z");
|
||||||
|
if(data) {
|
||||||
|
ret.z() = atof((char*)data);
|
||||||
|
xmlFree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Level::validateLevel(xmlDocPtr doc) {
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
xmlDtdPtr dtd = xmlParseDTD((xmlChar*)"-//libzoom//DTD level 0.1//EN", (xmlChar*)"levels/level.dtd");
|
||||||
|
|
||||||
|
if(dtd) {
|
||||||
|
xmlValidCtxtPtr validCtxt = xmlNewValidCtxt();
|
||||||
|
|
||||||
|
if(validCtxt) {
|
||||||
|
if(xmlValidateDtd(validCtxt, doc, dtd))
|
||||||
|
ret = true;
|
||||||
|
|
||||||
|
xmlFreeValidCtxt(validCtxt);
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlFreeDtd(dtd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
Level.h
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Level.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_LEVEL_H_
|
||||||
|
#define ZOOM_LEVEL_H_
|
||||||
|
|
||||||
|
#include "BSPTree.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <libxml/parser.h>
|
||||||
|
#include <vmmlib/vector.hpp>
|
||||||
|
|
||||||
|
namespace Zoom {
|
||||||
|
|
||||||
|
class Level {
|
||||||
|
public:
|
||||||
|
static boost::shared_ptr<Level> loadLevel(const std::string &filename);
|
||||||
|
|
||||||
|
struct WallData : public BSPTree::TriangleData {
|
||||||
|
std::string texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Room {
|
||||||
|
std::string id;
|
||||||
|
std::list<BSPTree::TriangleRecord> walls;
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::list<Room> &getRooms() const {
|
||||||
|
return rooms;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::list<Room> rooms;
|
||||||
|
std::map<std::string, unsigned> textures;
|
||||||
|
|
||||||
|
std::string name, description;
|
||||||
|
vmml::vec3f startPoint;
|
||||||
|
|
||||||
|
Level() {}
|
||||||
|
|
||||||
|
void loadLevelInfo(xmlNodePtr infoNode);
|
||||||
|
void loadRooms(xmlNodePtr roomsNode);
|
||||||
|
void loadRoom(xmlNodePtr roomNode);
|
||||||
|
void loadTextures(xmlNodePtr texturesNode);
|
||||||
|
|
||||||
|
static BSPTree::TriangleRecord loadWall(xmlNodePtr wallNode);
|
||||||
|
static vmml::vec3f loadVector(xmlNodePtr node);
|
||||||
|
|
||||||
|
static bool validateLevel(xmlDocPtr doc);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ZOOM_LEVEL_H_ */
|
34
Renderer.cpp
|
@ -19,11 +19,10 @@
|
||||||
|
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "BSPTree.h"
|
#include "BSPTree.h"
|
||||||
|
#include "gl.h"
|
||||||
|
|
||||||
namespace Zoom {
|
namespace Zoom {
|
||||||
|
|
||||||
const Renderer::RenderVisitor Renderer::renderVisitor = Renderer::RenderVisitor();
|
|
||||||
|
|
||||||
void Renderer::render(const BSPTree &tree) {
|
void Renderer::render(const BSPTree &tree) {
|
||||||
vmml::mat4f transform, inverseTransform;
|
vmml::mat4f transform, inverseTransform;
|
||||||
glGetFloatv(GL_MODELVIEW_MATRIX, transform.array);
|
glGetFloatv(GL_MODELVIEW_MATRIX, transform.array);
|
||||||
|
@ -38,14 +37,39 @@ void Renderer::render(const BSPTree &tree) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::render(const std::list<BSPTree::TriangleRecord> &triangles) {
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
for(std::list<BSPTree::TriangleRecord>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
||||||
|
renderTriangle(t->triangle);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::renderTriangle(const Triangle &t) {
|
void Renderer::renderTriangle(const Triangle &t) {
|
||||||
glColor4fv(t.getColor().array);
|
glColor4fv(t.getColor().array);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, t.getColor().array);
|
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (t.getColor()/2).array);
|
|
||||||
|
|
||||||
glNormal3fv(t.getNormal().array);
|
if(t.getTexture() != lastTexture) {
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
if(t.getTexture()) {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, t.getTexture());
|
||||||
|
|
||||||
|
if(!lastTexture) {
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastTexture = t.getTexture();
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; ++i) {
|
for(int i = 0; i < 3; ++i) {
|
||||||
|
glTexCoord2fv(t.getTexCoords(i).array);
|
||||||
|
glNormal3fv(t.getNormal(i).array);
|
||||||
glVertex3fv(t.getVertex(i).array);
|
glVertex3fv(t.getVertex(i).array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
Renderer.h
|
@ -20,25 +20,35 @@
|
||||||
#ifndef ZOOM_RENDERER_H_
|
#ifndef ZOOM_RENDERER_H_
|
||||||
#define ZOOM_RENDERER_H_
|
#define ZOOM_RENDERER_H_
|
||||||
|
|
||||||
namespace Zoom {
|
#include "BSPTree.h"
|
||||||
|
|
||||||
class Triangle;
|
namespace Zoom {
|
||||||
class BSPTree;
|
|
||||||
|
|
||||||
class Renderer {
|
class Renderer {
|
||||||
public:
|
public:
|
||||||
|
Renderer() : lastTexture(0), renderVisitor(this) {}
|
||||||
|
|
||||||
void render(const BSPTree &tree);
|
void render(const BSPTree &tree);
|
||||||
|
void render(const std::list<BSPTree::TriangleRecord> &triangles);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void renderTriangle(const Triangle &t);
|
void renderTriangle(const Triangle &t);
|
||||||
|
|
||||||
struct RenderVisitor {
|
class RenderVisitor {
|
||||||
void operator() (const Triangle &t) const {
|
public:
|
||||||
renderTriangle(t);
|
RenderVisitor(Renderer *renderer0) : renderer(renderer0) {}
|
||||||
|
|
||||||
|
void operator() (const BSPTree::TriangleRecord &t) const {
|
||||||
|
renderer->renderTriangle(t.triangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Renderer *renderer;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const RenderVisitor renderVisitor;
|
unsigned lastTexture;
|
||||||
|
|
||||||
|
const RenderVisitor renderVisitor;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
44
Texture.cpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Texture.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 "Texture.h"
|
||||||
|
#include "gl.h"
|
||||||
|
#include <GL/glpng.h>
|
||||||
|
|
||||||
|
namespace Zoom {
|
||||||
|
|
||||||
|
std::map<std::string, unsigned> Texture::textures;
|
||||||
|
|
||||||
|
unsigned Texture::loadTexture(const std::string &name) {
|
||||||
|
std::map<std::string, unsigned>::iterator it = textures.find(name);
|
||||||
|
|
||||||
|
if(it != textures.end())
|
||||||
|
return it->second;
|
||||||
|
|
||||||
|
pngInfo info;
|
||||||
|
unsigned texture = pngBind(("tex/" + name).c_str(), PNG_NOMIPMAP, PNG_ALPHA, &info, GL_REPEAT, GL_LINEAR, GL_LINEAR);
|
||||||
|
|
||||||
|
if(texture) {
|
||||||
|
textures.insert(std::make_pair(name, texture));
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
Texture.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Texture.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_TEXTURE_H_
|
||||||
|
#define ZOOM_TEXTURE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
namespace Zoom {
|
||||||
|
|
||||||
|
class Texture {
|
||||||
|
public:
|
||||||
|
static unsigned loadTexture(const std::string &name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Texture();
|
||||||
|
|
||||||
|
static std::map<std::string, unsigned> textures;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ZOOM_TEXTURE_H_ */
|
92
Triangle.h
|
@ -1,7 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Triangle.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_TRIANGLE_H_
|
#ifndef ZOOM_TRIANGLE_H_
|
||||||
#define ZOOM_TRIANGLE_H_
|
#define ZOOM_TRIANGLE_H_
|
||||||
|
|
||||||
#include "gl.h"
|
|
||||||
#include <vmmlib/vector.hpp>
|
#include <vmmlib/vector.hpp>
|
||||||
#include <vmmlib/matrix.hpp>
|
#include <vmmlib/matrix.hpp>
|
||||||
|
|
||||||
|
@ -9,36 +27,76 @@ namespace Zoom {
|
||||||
|
|
||||||
class Triangle {
|
class Triangle {
|
||||||
public:
|
public:
|
||||||
Triangle() : c(vmml::vec4f::ONE) {
|
Triangle() : color(vmml::vec4f::ONE), texture(0) {
|
||||||
v[0] = v[1] = v[2] = vmml::vec3f::ZERO;
|
vertices[0] = vertices[1] = vertices[2] = vmml::vec3f::ZERO;
|
||||||
|
normals[0] = normals[1] = normals[2] = vmml::vec3f::ZERO;
|
||||||
|
texcoords[0] = texcoords[1] = texcoords[2] = vmml::vec2f::ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
Triangle(const vmml::vec3f &v1, const vmml::vec3f &v2, const vmml::vec3f &v3, const vmml::vec4f &c0) : c(c0) {
|
Triangle(const vmml::vec3f &v1, const vmml::vec3f &v2, const vmml::vec3f &v3, const vmml::vec4f &color0) : color(color0), texture(0) {
|
||||||
v[0] = v1;
|
vertices[0] = v1;
|
||||||
v[1] = v2;
|
vertices[1] = v2;
|
||||||
v[2] = v3;
|
vertices[2] = v3;
|
||||||
|
|
||||||
|
normals[0] = normals[1] = normals[2] = vmml::vec3f::ZERO;
|
||||||
|
texcoords[0] = texcoords[1] = texcoords[2] = vmml::vec2f::ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vmml::vec3f& getVertex(int i) const {return v[i];}
|
const vmml::vec3f& getVertex(int i) const {return vertices[i];}
|
||||||
const vmml::vec4f& getColor() const {return c;}
|
vmml::vec3f& getVertex(int i) {return vertices[i];}
|
||||||
|
void setVertex(int i, vmml::vec3f v) {
|
||||||
vmml::vec3f getNormal() const {
|
vertices[i] = v;
|
||||||
return v[0].compute_normal(v[1], v[2]);
|
}
|
||||||
|
|
||||||
|
const vmml::vec3f& getNormal(int i) const {return normals[i];}
|
||||||
|
vmml::vec3f& getNormal(int i) {return normals[i];}
|
||||||
|
void setNormal(int i, vmml::vec3f n) {
|
||||||
|
normals[i] = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
const vmml::vec2f& getTexCoords(int i) const {return texcoords[i];}
|
||||||
|
vmml::vec2f& getTexCoords(int i) {return texcoords[i];}
|
||||||
|
void setTexCoords(int i, vmml::vec2f t) {
|
||||||
|
texcoords[i] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned getTexture() const {
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
void setTexture(unsigned tex) {
|
||||||
|
texture = tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
const vmml::vec4f& getColor() const {return color;}
|
||||||
|
vmml::vec4f& getColor() {return color;}
|
||||||
|
void setColor(vmml::vec4f c) {
|
||||||
|
color = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void transform(const vmml::mat4f &m) {
|
vmml::vec3f computeNormal() const {
|
||||||
|
return vertices[0].compute_normal(vertices[1], vertices[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isDegenerate() const {
|
||||||
|
return (computeNormal().squared_length() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void transform(const vmml::mat4f &matrix) {
|
||||||
for(int i = 0; i < 3; ++i) {
|
for(int i = 0; i < 3; ++i) {
|
||||||
v[i] = m*v[i];
|
vertices[i] = matrix*vertices[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vmml::vec3f getCenter() const {
|
vmml::vec3f getCenter() const {
|
||||||
return (v[0]+v[1]+v[2])/3;
|
return (vertices[0]+vertices[1]+vertices[2])/3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vmml::vec3f v[3];
|
vmml::vec3f vertices[3];
|
||||||
vmml::vec4f c;
|
vmml::vec3f normals[3];
|
||||||
|
vmml::vec2f texcoords[3];
|
||||||
|
vmml::vec4f color;
|
||||||
|
unsigned texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
2
config.h
|
@ -20,7 +20,7 @@
|
||||||
#ifndef ZOOM_CONFIG_H_
|
#ifndef ZOOM_CONFIG_H_
|
||||||
#define ZOOM_CONFIG_H_
|
#define ZOOM_CONFIG_H_
|
||||||
|
|
||||||
#define MIN_FRAME_DELTA 16
|
#define MIN_FRAME_DELTA 10
|
||||||
#define DEFAULT_WIDTH 800
|
#define DEFAULT_WIDTH 800
|
||||||
#define DEFAULT_HEIGHT 600
|
#define DEFAULT_HEIGHT 600
|
||||||
|
|
||||||
|
|
25
gl.h
|
@ -1,5 +1,24 @@
|
||||||
#ifndef _GL_H_
|
/*
|
||||||
#define _GL_H_
|
* gl.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_GL_H_
|
||||||
|
#define ZOOM_GL_H_
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
@ -9,4 +28,4 @@
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
#endif /* _GL_H_ */
|
#endif /* ZOOM_GL_H_ */
|
||||||
|
|
61
levels/level.dtd
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<!ELEMENT level (info, rooms, gates, textures)>
|
||||||
|
|
||||||
|
<!ELEMENT info (name, desc, start)>
|
||||||
|
<!ELEMENT rooms (room)*>
|
||||||
|
<!ELEMENT gates (gate)*>
|
||||||
|
<!ELEMENT textures (texture)*>
|
||||||
|
|
||||||
|
<!ELEMENT name (#PCDATA)>
|
||||||
|
<!ELEMENT desc (#PCDATA)>
|
||||||
|
<!ELEMENT start EMPTY>
|
||||||
|
<!ATTLIST start
|
||||||
|
x CDATA #REQUIRED
|
||||||
|
y CDATA #REQUIRED
|
||||||
|
z CDATA #REQUIRED
|
||||||
|
>
|
||||||
|
|
||||||
|
<!ELEMENT room (triangle)*>
|
||||||
|
<!ATTLIST room
|
||||||
|
id ID #REQUIRED
|
||||||
|
>
|
||||||
|
|
||||||
|
<!ELEMENT gate (triangle)*>
|
||||||
|
<!ATTLIST gate
|
||||||
|
room1 IDREF #REQUIRED
|
||||||
|
room2 IDREF #REQUIRED
|
||||||
|
>
|
||||||
|
|
||||||
|
<!ELEMENT triangle (vertex, normal?, texcoords?, vertex, normal?, texcoords?, vertex, normal?, texcoords?)>
|
||||||
|
<!ATTLIST triangle
|
||||||
|
visible (true|false) "true"
|
||||||
|
texture IDREF #IMPLIED
|
||||||
|
>
|
||||||
|
|
||||||
|
<!ELEMENT texture EMPTY>
|
||||||
|
<!ATTLIST texture
|
||||||
|
id ID #REQUIRED
|
||||||
|
name CDATA #REQUIRED
|
||||||
|
>
|
||||||
|
|
||||||
|
<!ELEMENT vertex EMPTY>
|
||||||
|
<!ATTLIST vertex
|
||||||
|
x CDATA #REQUIRED
|
||||||
|
y CDATA #REQUIRED
|
||||||
|
z CDATA #REQUIRED
|
||||||
|
>
|
||||||
|
|
||||||
|
<!ELEMENT normal EMPTY>
|
||||||
|
<!ATTLIST normal
|
||||||
|
x CDATA #REQUIRED
|
||||||
|
y CDATA #REQUIRED
|
||||||
|
z CDATA #REQUIRED
|
||||||
|
>
|
||||||
|
|
||||||
|
<!ELEMENT texcoords EMPTY>
|
||||||
|
<!ATTLIST texcoords
|
||||||
|
s CDATA #REQUIRED
|
||||||
|
t CDATA #IMPLIED
|
||||||
|
r CDATA #IMPLIED
|
||||||
|
q CDATA #IMPLIED
|
||||||
|
>
|
||||||
|
|
392
levels/level.xml
Normal file
|
@ -0,0 +1,392 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE level PUBLIC "-//libzoom//DTD level 0.1//EN" "level.dtd">
|
||||||
|
<level>
|
||||||
|
<info>
|
||||||
|
<name>Test Level</name>
|
||||||
|
<desc>Just a simple test level.</desc>
|
||||||
|
<start x="0.0" y="0.0" z="0.0"/>
|
||||||
|
</info>
|
||||||
|
<rooms>
|
||||||
|
<room id="r0">
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="-2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="-2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-10.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-10.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-10.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-10.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-10.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-10.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-10.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-10.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-10.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-10.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-10.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-10.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-10.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-10.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-10.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="6.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-10.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="6.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-10.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-10.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="6.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="6.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-6.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
</room>
|
||||||
|
<room id="r1">
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t2">
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="-2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t1">
|
||||||
|
<vertex x="-2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
</room>
|
||||||
|
</rooms>
|
||||||
|
<gates>
|
||||||
|
<gate room1="r0" room2="r1">
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="2.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
</triangle>
|
||||||
|
<triangle texture="t0">
|
||||||
|
<vertex x="2.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="1.0" t="1.0"/>
|
||||||
|
<vertex x="6.0" y="2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="0.0"/>
|
||||||
|
<vertex x="6.0" y="-2.0" z="-2.0"/>
|
||||||
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
</triangle>
|
||||||
|
</gate>
|
||||||
|
</gates>
|
||||||
|
<textures>
|
||||||
|
<texture id="t0" name="green.png"/>
|
||||||
|
<texture id="t1" name="metallic2.png"/>
|
||||||
|
<texture id="t2" name="light.png"/>
|
||||||
|
</textures>
|
||||||
|
</level>
|
BIN
tex/blue.png
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
tex/cursor.png
Normal file
After Width: | Height: | Size: 651 B |
BIN
tex/dark.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
tex/door.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
tex/fire.png
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
tex/green.png
Normal file
After Width: | Height: | Size: 692 KiB |
BIN
tex/green2.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
tex/light.png
Normal file
After Width: | Height: | Size: 210 KiB |
BIN
tex/lightmap.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tex/lightmap2.png
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
tex/medib.png
Normal file
After Width: | Height: | Size: 136 B |
BIN
tex/metallic.png
Normal file
After Width: | Height: | Size: 558 KiB |
BIN
tex/metallic2.png
Normal file
After Width: | Height: | Size: 533 KiB |
BIN
tex/textur.png
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
tex/wall1.png
Normal file
After Width: | Height: | Size: 435 B |
BIN
tex/wall2.png
Normal file
After Width: | Height: | Size: 698 B |
BIN
tex/wall3.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
tex/wall4.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
tex/wall5.png
Normal file
After Width: | Height: | Size: 12 KiB |
24
zoom.cpp
|
@ -1,3 +1,22 @@
|
||||||
|
/*
|
||||||
|
* zoom.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 "Game.h"
|
#include "Game.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gl.h"
|
#include "gl.h"
|
||||||
|
@ -13,9 +32,8 @@
|
||||||
|
|
||||||
void resize(int width, int height)
|
void resize(int width, int height)
|
||||||
{
|
{
|
||||||
if(height==0)
|
if(height == 0) {
|
||||||
{
|
height = 1;
|
||||||
height=1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|