summaryrefslogtreecommitdiffstats
path: root/Triangle.h
blob: 807b5b9edaf10dcd8c88ab76757629d8ae3bc5e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef _TRIANGLE_H_
#define _TRIANGLE_H_

#include "gl.h"
#include "Color.h"
#include "Vector.h"
#include "Vertex.h"
#include "Matrix.h"

class Triangle
{
  public:
    Triangle(const Vertex &v1, const Vertex &v2, const Vertex &v3, const Color &c0) : c(c0)
    {
      v[0] = v1;
      v[1] = v2;
      v[2] = v3;
    }
    
    const Vertex& getVertex(int i) const {return v[i];}
    const Color& getColor() const {return c;}
    
    void render() const {
      glColor4f(c.getR(), c.getG(), c.getB(), c.getA());
      
      for(int i = 0; i < 3; ++i)
      {
        glVertex3f(v[i].getX(), v[i].getY(), v[i].getZ());
      }
    }
    
    void transform(const Matrix &m) {
      for(int i = 0; i < 3; ++i)
      {
        v[i] = m*v[i];
      }
    }
    
  private:
    Vertex v[3];
    Color c;
};

#endif /*_TRIANGLE_H_*/