This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
neofx-zoom-plusplus/Triangle.h
2009-12-13 18:49:36 +01:00

47 lines
935 B
C++

#ifndef ZOOM_TRIANGLE_H_
#define ZOOM_TRIANGLE_H_
#include "gl.h"
#include <vmmlib/vector.hpp>
#include <vmmlib/matrix.hpp>
namespace Zoom {
class Triangle {
public:
Triangle() : c(vmml::vec4f::ONE) {
v[0] = v[1] = v[2] = vmml::vec3f::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;
}
const vmml::vec3f& getVertex(int i) const {return v[i];}
const vmml::vec4f& getColor() const {return c;}
vmml::vec3f getNormal() const {
return v[0].compute_normal(v[1], v[2]);
}
void transform(const vmml::mat4f &m) {
for(int i = 0; i < 3; ++i) {
v[i] = m*v[i];
}
}
vmml::vec3f getCenter() const {
return (v[0]+v[1]+v[2])/3;
}
private:
vmml::vec3f v[3];
vmml::vec4f c;
};
}
#endif /*ZOOM_TRIANGLE_H_*/