summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-12-24 23:17:51 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-12-24 23:17:51 +0100
commitd1c909ca57b1685d8c4303d1ff9018fdb152f889 (patch)
tree3cca2c7ac48f23bcc12f334c8367a3ab38dd5e3a /src
parentc883f50f90d6f0fcfa3bee94e974ede149c35ca6 (diff)
downloadzoom++-d1c909ca57b1685d8c4303d1ff9018fdb152f889.tar
zoom++-d1c909ca57b1685d8c4303d1ff9018fdb152f889.zip
Refactored Ray
Diffstat (limited to 'src')
-rw-r--r--src/MathUtil.h18
-rw-r--r--src/Renderer.cpp18
-rw-r--r--src/ShadowVolume.cpp6
-rw-r--r--src/ShadowVolume.h16
4 files changed, 32 insertions, 26 deletions
diff --git a/src/MathUtil.h b/src/MathUtil.h
index 9e6efc7..892d5dc 100644
--- a/src/MathUtil.h
+++ b/src/MathUtil.h
@@ -87,6 +87,24 @@ class MathUtil {
float d;
};
+ class Ray {
+ public:
+ Ray() : vertex(vmml::vec3f::ZERO), dir(vmml::vec3f::ZERO) {}
+ Ray(const vmml::vec3f &v, const vmml::vec3f &d) : vertex(v), dir(d) {}
+
+ const vmml::vec3f& getVertex() const {
+ return vertex;
+ }
+
+ const vmml::vec3f& getDirection() const {
+ return dir;
+ }
+
+ private:
+ vmml::vec3f vertex;
+ vmml::vec3f dir;
+ };
+
static vmml::mat4f perspective(float fovy, float aspect, float zNear);
private:
diff --git a/src/Renderer.cpp b/src/Renderer.cpp
index 0f4c4d7..5d86565 100644
--- a/src/Renderer.cpp
+++ b/src/Renderer.cpp
@@ -62,14 +62,14 @@ void Renderer::renderShadowVolume(const ShadowVolume &v) {
if(!v.isVisible())
return;
- glVertex3fv(v.getVertex(2).array);
- glVertex3fv(v.getVertex(1).array);
- glVertex3fv(v.getVertex(0).array);
+ glVertex3fv(v.getRay(2).getVertex().array);
+ glVertex3fv(v.getRay(1).getVertex().array);
+ glVertex3fv(v.getRay(0).getVertex().array);
for(int i = 0; i < 3; ++i) {
- const vmml::vec3f &p1 = v.getVertex(i), &p2 = v.getVertex((i+1)%3);
- vmml::vec4f dir1 = vmml::vec4f(v.getDirection(i), 0);
- vmml::vec4f dir2 = vmml::vec4f(v.getDirection((i+1)%3), 0);
+ const vmml::vec3f &p1 = v.getRay(i).getVertex(), &p2 = v.getRay((i+1)%3).getVertex();
+ vmml::vec4f dir1 = vmml::vec4f(v.getRay(i).getDirection(), 0);
+ vmml::vec4f dir2 = vmml::vec4f(v.getRay((i+1)%3).getDirection(), 0);
glVertex3fv(p1.array);
glVertex3fv(p2.array);
@@ -80,9 +80,9 @@ void Renderer::renderShadowVolume(const ShadowVolume &v) {
glVertex4fv(dir2.array);
}
- glVertex4fv(vmml::vec4f(v.getDirection(0), 0).array);
- glVertex4fv(vmml::vec4f(v.getDirection(1), 0).array);
- glVertex4fv(vmml::vec4f(v.getDirection(2), 0).array);
+ glVertex4fv(vmml::vec4f(v.getRay(0).getDirection(), 0).array);
+ glVertex4fv(vmml::vec4f(v.getRay(1).getDirection(), 0).array);
+ glVertex4fv(vmml::vec4f(v.getRay(2).getDirection(), 0).array);
}
void Renderer::useTexture(unsigned texture) {
diff --git a/src/ShadowVolume.cpp b/src/ShadowVolume.cpp
index 27aba6e..ed0cd76 100644
--- a/src/ShadowVolume.cpp
+++ b/src/ShadowVolume.cpp
@@ -27,10 +27,6 @@ namespace Zoom {
ShadowVolume::ShadowVolume(const Triangle &t, const vmml::vec3f &lightPos) : visible(true) {
MathUtil::Plane trianglePlane(t);
- for(int i = 0; i < 3; ++i) {
- rays[i].p = t.getVertex(i);
- }
-
if(!trianglePlane.isBehind(lightPos)) {
visible = false;
@@ -38,7 +34,7 @@ ShadowVolume::ShadowVolume(const Triangle &t, const vmml::vec3f &lightPos) : vis
}
for(int i = 0; i < 3; ++i) {
- rays[i].dir = rays[i].p - lightPos;
+ rays[i] = MathUtil::Ray(t.getVertex(i), t.getVertex(i) - lightPos);
}
}
diff --git a/src/ShadowVolume.h b/src/ShadowVolume.h
index 445e7ba..a7b276c 100644
--- a/src/ShadowVolume.h
+++ b/src/ShadowVolume.h
@@ -20,8 +20,7 @@
#ifndef ZOOM_SHADOWVOLUME_H_
#define ZOOM_SHADOWVOLUME_H_
-#include <vmmlib/vector.hpp>
-#include <vmmlib/matrix.hpp>
+#include "MathUtil.h"
namespace Zoom {
@@ -32,12 +31,8 @@ class ShadowVolume {
ShadowVolume(const Triangle &t, const vmml::vec3f &lightPos);
virtual ~ShadowVolume() {}
- const vmml::vec3f& getVertex(int i) const {
- return rays[i].p;
- }
-
- const vmml::vec3f& getDirection(int i) const {
- return rays[i].dir;
+ const MathUtil::Ray& getRay(int i) const {
+ return rays[i];
}
bool isVisible() const {
@@ -47,10 +42,7 @@ class ShadowVolume {
private:
bool visible;
- struct Ray {
- vmml::vec3f p;
- vmml::vec3f dir;
- } rays[3];
+ MathUtil::Ray rays[3];
};
}