summaryrefslogtreecommitdiffstats
path: root/Triangle.h
diff options
context:
space:
mode:
Diffstat (limited to 'Triangle.h')
-rw-r--r--Triangle.h90
1 files changed, 74 insertions, 16 deletions
diff --git a/Triangle.h b/Triangle.h
index 16b0d73..2b34c3f 100644
--- a/Triangle.h
+++ b/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_
#define ZOOM_TRIANGLE_H_
-#include "gl.h"
#include <vmmlib/vector.hpp>
#include <vmmlib/matrix.hpp>
@@ -9,36 +27,76 @@ namespace Zoom {
class Triangle {
public:
- Triangle() : c(vmml::vec4f::ONE) {
- v[0] = v[1] = v[2] = vmml::vec3f::ZERO;
+ Triangle() : color(vmml::vec4f::ONE), texture(0) {
+ 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) {
- v[0] = v1;
- v[1] = v2;
- v[2] = v3;
+ Triangle(const vmml::vec3f &v1, const vmml::vec3f &v2, const vmml::vec3f &v3, const vmml::vec4f &color0) : color(color0), texture(0) {
+ vertices[0] = v1;
+ vertices[1] = v2;
+ 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::vec4f& getColor() const {return c;}
+ const vmml::vec3f& getVertex(int i) const {return vertices[i];}
+ vmml::vec3f& getVertex(int i) {return vertices[i];}
+ void setVertex(int i, vmml::vec3f v) {
+ vertices[i] = v;
+ }
+
+ 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;
+ }
- vmml::vec3f getNormal() const {
- return v[0].compute_normal(v[1], v[2]);
+ vmml::vec3f computeNormal() const {
+ return vertices[0].compute_normal(vertices[1], vertices[2]);
}
- void transform(const vmml::mat4f &m) {
+ bool isDegenerate() const {
+ return (computeNormal().squared_length() == 0);
+ }
+
+ void transform(const vmml::mat4f &matrix) {
for(int i = 0; i < 3; ++i) {
- v[i] = m*v[i];
+ vertices[i] = matrix*vertices[i];
}
}
vmml::vec3f getCenter() const {
- return (v[0]+v[1]+v[2])/3;
+ return (vertices[0]+vertices[1]+vertices[2])/3;
}
private:
- vmml::vec3f v[3];
- vmml::vec4f c;
+ vmml::vec3f vertices[3];
+ vmml::vec3f normals[3];
+ vmml::vec2f texcoords[3];
+ vmml::vec4f color;
+ unsigned texture;
};
}