blob: dc480715b716b7d1f0899e7f922a1772df87a5ad (
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
46
47
48
49
50
51
52
53
54
55
|
#ifndef _TRIANGLE_H_
#define _TRIANGLE_H_
#include "gl.h"
#include <vmmlib/vector.hpp>
#include <vmmlib/matrix.hpp>
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 {
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_*/
|