#ifndef _TRIANGLE_H_ #define _TRIANGLE_H_ #include "gl.h" #include #include class Triangle { public: Triangle() {} 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 render() const { glColor4fv(c.array); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c.array); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (c/2).array); glNormal3fv(getNormal().array); for(int i = 0; i < 3; ++i) { glVertex3fv(v[i].array); } } 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 /*_TRIANGLE_H_*/