ShadowVolume: Well, it's a beginning...
This commit is contained in:
parent
4e3efa239c
commit
a540d6b167
5 changed files with 132 additions and 12 deletions
|
@ -40,6 +40,22 @@
|
||||||
<vertex x="2.0" y="-2.0" z="2.0"/>
|
<vertex x="2.0" y="-2.0" z="2.0"/>
|
||||||
<texcoords s="0.0" t="1.0"/>
|
<texcoords s="0.0" t="1.0"/>
|
||||||
</triangle>
|
</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="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>
|
||||||
<triangle texture="t1">
|
<triangle texture="t1">
|
||||||
<vertex x="-2.0" y="2.0" z="-6.0"/>
|
<vertex x="-2.0" y="2.0" z="-6.0"/>
|
||||||
<texcoords s="0.0" t="1.0"/>
|
<texcoords s="0.0" t="1.0"/>
|
||||||
|
|
|
@ -7,6 +7,7 @@ add_executable(zoom
|
||||||
MathUtil.cpp MathUtil.h
|
MathUtil.cpp MathUtil.h
|
||||||
Renderer.cpp Renderer.h
|
Renderer.cpp Renderer.h
|
||||||
Shader.cpp Shader.h
|
Shader.cpp Shader.h
|
||||||
|
ShadowVolume.cpp ShadowVolume.h
|
||||||
Texture.cpp Texture.h
|
Texture.cpp Texture.h
|
||||||
Triangle.h
|
Triangle.h
|
||||||
zoom.cpp
|
zoom.cpp
|
||||||
|
|
31
src/Game.cpp
31
src/Game.cpp
|
@ -19,12 +19,13 @@
|
||||||
|
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
|
||||||
|
#include "gl.h"
|
||||||
#include "BSPTree.h"
|
#include "BSPTree.h"
|
||||||
#include "Level.h"
|
#include "Level.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
#include "ShadowVolume.h"
|
||||||
#include "Triangle.h"
|
#include "Triangle.h"
|
||||||
|
|
||||||
#include "gl.h"
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Zoom {
|
namespace Zoom {
|
||||||
|
@ -34,17 +35,16 @@ Game::Game(bool multisample) : playerPos(vmml::vec3f::ZERO), playerRotY(vmml::ma
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||||
glClearDepth(1.0);
|
glClearDepth(1.0);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
//glDepthFunc(GL_LEQUAL);
|
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if(multisample)
|
if(multisample)
|
||||||
glEnable(GL_MULTISAMPLE_ARB);
|
glEnable(GL_MULTISAMPLE_ARB);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, vmml::vec4f(0.1, 0.1, 0.1, 1).array);
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0, GL_AMBIENT, vmml::vec4f::ZERO.array);
|
glLightfv(GL_LIGHT0, GL_AMBIENT, vmml::vec4f::ZERO.array);
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, vmml::vec4f::ONE.array);
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, vmml::vec4f::ONE.array);
|
||||||
glLightfv(GL_LIGHT0, GL_SPECULAR, vmml::vec4f::ONE.array);
|
glLightfv(GL_LIGHT0, GL_SPECULAR, vmml::vec4f::ONE.array);
|
||||||
|
@ -142,17 +142,24 @@ void Game::render() {
|
||||||
|
|
||||||
renderer.render(triangles);
|
renderer.render(triangles);
|
||||||
|
|
||||||
/*glBegin(GL_LINES);
|
Shader::disable();
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glBlendFunc(GL_ONE, GL_ZERO);
|
||||||
|
|
||||||
glColor3f(0, 0, 1);
|
glBegin(GL_LINES);
|
||||||
glVertex4f(-1, -0.5, -2, 1);
|
|
||||||
glVertex4f(1, -0.5, -2, 1);
|
|
||||||
|
|
||||||
glColor3f(1, 0, 0);
|
glColor3f(1, 1, 0);
|
||||||
glVertex4f(0, -0.5, -2, 1);
|
|
||||||
glVertex4f(1, 0, 0, 0);
|
|
||||||
|
|
||||||
glEnd();*/
|
for(std::vector<BSPTree::TriangleRecord>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
|
||||||
|
ShadowVolume v(t->triangle, light);
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; ++i) {
|
||||||
|
glVertex3fv(v.getVertex(i).array);
|
||||||
|
glVertex3fv((v.getVertex(i)+v.getDirection(i)).array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
45
src/ShadowVolume.cpp
Normal file
45
src/ShadowVolume.cpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* ShadowVolume.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 "ShadowVolume.h"
|
||||||
|
#include "MathUtil.h"
|
||||||
|
|
||||||
|
namespace Zoom {
|
||||||
|
|
||||||
|
ShadowVolume::ShadowVolume(const Triangle &t, const vmml::vec3f &lightPos) {
|
||||||
|
MathUtil::Plane trianglePlane(t);
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; ++i) {
|
||||||
|
rays[i].p = t.getVertex(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(trianglePlane.isBehind(lightPos)) {
|
||||||
|
for(int i = 0; i < 3; ++i) {
|
||||||
|
rays[i].dir = vmml::vec3f::ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; ++i) {
|
||||||
|
rays[i].dir = rays[i].p - lightPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
src/ShadowVolume.h
Normal file
51
src/ShadowVolume.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* ShadowVolume.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_SHADOWVOLUME_H_
|
||||||
|
#define ZOOM_SHADOWVOLUME_H_
|
||||||
|
|
||||||
|
#include <vmmlib/vector.hpp>
|
||||||
|
|
||||||
|
namespace Zoom {
|
||||||
|
|
||||||
|
class Triangle;
|
||||||
|
|
||||||
|
class ShadowVolume {
|
||||||
|
public:
|
||||||
|
ShadowVolume(const Triangle &t, const vmml::vec3f &lightPos);
|
||||||
|
virtual ~ShadowVolume() {}
|
||||||
|
|
||||||
|
const vmml::vec3f& getVertex(int i) {
|
||||||
|
return rays[i].p;
|
||||||
|
}
|
||||||
|
|
||||||
|
const vmml::vec3f& getDirection(int i) {
|
||||||
|
return rays[i].dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Ray {
|
||||||
|
vmml::vec3f p;
|
||||||
|
vmml::vec3f dir;
|
||||||
|
} rays[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ZOOM_SHADOWVOLUME_H_ */
|
Reference in a new issue