diff options
Diffstat (limited to 'Triangle.h')
-rw-r--r-- | Triangle.h | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -20,9 +20,26 @@ class Triangle const Vertex& getVertex(int i) const {return v[i];} const Color& getColor() const {return c;} + Vertex getNormal() const { + Vector v1 = v[0]-v[2]; + Vector v2 = v[0]-v[1]; + + return v1.cross(v2).normalize(); + } + void render() const { - glColor4f(c.getR(), c.getG(), c.getB(), c.getA()); + //glColor4f(c.getR(), c.getG(), c.getB(), c.getA()); + float color[] = {c.getR(), c.getG(), c.getB(), c.getA()}; + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color); + + for(int i = 0; i < 3; ++i) { + color[i] /= 2; + } + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color); + Vector normal = getNormal(); + glNormal3f(normal.getX(), normal.getY(), normal.getZ()); + for(int i = 0; i < 3; ++i) { glVertex3f(v[i].getX(), v[i].getY(), v[i].getZ()); |