Subversion Repositories gelsvn

Rev

Rev 309 | Rev 595 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 309 Rev 443
1
#ifndef __TRIANGLE_H
1
#ifndef __GEOMETRY_TRIANGLE_H
2
#define __TRIANGLE_H
2
#define __GEOMETRY_TRIANGLE_H
3
 
3
 
4
#include "CGLA/Vec2f.h"
4
#include "CGLA/Vec2f.h"
5
#include "CGLA/Vec3f.h"
5
#include "CGLA/Vec3f.h"
6
#include "CGLA/Mat3x3f.h"
6
#include "CGLA/Mat3x3f.h"
7
 
7
 
8
#define COMPUTE_SIGN
8
#define COMPUTE_SIGN
9
 
9
 
10
namespace Geometry
10
namespace Geometry
11
{
11
{
12
 
12
 
13
class Triangle
13
class Triangle
14
{
14
{
15
	CGLA::Vec3f vert[3];
15
	CGLA::Vec3f vert[3];
16
	CGLA::Vec3f edge[3];
16
	CGLA::Vec3f edge[3];
17
 
17
 
18
#ifdef COMPUTE_SIGN
18
#ifdef COMPUTE_SIGN
19
	CGLA::Vec3f vert_norm[3];
19
	CGLA::Vec3f vert_norm[3];
20
	CGLA::Vec3f edge_norm[3];
20
	CGLA::Vec3f edge_norm[3];
21
#endif
21
#endif
22
	CGLA::Vec3f face_norm;
22
	CGLA::Vec3f face_norm;
23
 
23
 
24
	CGLA::Vec3f tri_plane_edge_norm[3];
24
	CGLA::Vec3f tri_plane_edge_norm[3];
25
	float edge_len[3];
25
	float edge_len[3];
26
	
26
	
27
 public:
27
 public:
28
 
28
 
29
	Triangle() {}
29
	Triangle() {}
30
	
30
	
31
	Triangle(const CGLA::Vec3f& _v0, 
31
	Triangle(const CGLA::Vec3f& _v0, 
32
					 const CGLA::Vec3f& _v1, 
32
					 const CGLA::Vec3f& _v1, 
33
					 const CGLA::Vec3f& _v2,
33
					 const CGLA::Vec3f& _v2,
34
 
34
 
35
					 const CGLA::Vec3f& _vn0,
35
					 const CGLA::Vec3f& _vn0,
36
					 const CGLA::Vec3f& _vn1,
36
					 const CGLA::Vec3f& _vn1,
37
					 const CGLA::Vec3f& _vn2,
37
					 const CGLA::Vec3f& _vn2,
38
 
38
 
39
					 const CGLA::Vec3f& _en0,
39
					 const CGLA::Vec3f& _en0,
40
					 const CGLA::Vec3f& _en1,
40
					 const CGLA::Vec3f& _en1,
41
					 const CGLA::Vec3f& _en2);
41
					 const CGLA::Vec3f& _en2);
42
 
42
 
43
	bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&, float&) const;
43
	bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&, float&) const;
44
 
44
 
45
	const CGLA::Vec3f get_pmin() const 
45
	const CGLA::Vec3f get_pmin() const 
46
	{
46
	{
47
		return v_min(vert[0],v_min(vert[1],vert[2]));
47
		return v_min(vert[0],v_min(vert[1],vert[2]));
48
	}
48
	}
49
 
49
 
50
	const CGLA::Vec3f get_pmax() const 
50
	const CGLA::Vec3f get_pmax() const 
51
	{
51
	{
52
		return v_max(vert[0],v_max(vert[1],vert[2]));
52
		return v_max(vert[0],v_max(vert[1],vert[2]));
53
	}
53
	}
54
 
54
 
55
	const CGLA::Vec3f centre() const
55
	const CGLA::Vec3f centre() const
56
		{
56
		{
57
			return (vert[0]+vert[1]+vert[2])/3.0f;
57
			return (vert[0]+vert[1]+vert[2])/3.0f;
58
		}
58
		}
59
 
59
 
60
	const float area() const 
60
	const float area() const 
61
		{
61
		{
62
			return 0.5 * (cross(edge[0],-edge[2])).length();
62
			return 0.5 * (cross(edge[0],-edge[2])).length();
63
		}
63
		}
64
 
64
 
65
	const CGLA::Vec3f get_centre() const 
65
	const CGLA::Vec3f get_centre() const 
66
	{
66
	{
67
		CGLA::Vec3f pmin = get_pmin();
67
		CGLA::Vec3f pmin = get_pmin();
68
		CGLA::Vec3f pmax = get_pmax();
68
		CGLA::Vec3f pmax = get_pmax();
69
		return (pmax-pmin)/2.0f+pmin;
69
		return (pmax-pmin)/2.0f+pmin;
70
	}
70
	}
71
 
71
 
72
	bool signed_distance(const CGLA::Vec3f& p, float& sq_dist, float& sgn) const;
72
	bool signed_distance(const CGLA::Vec3f& p, float& sq_dist, float& sgn) const;
73
 
73
 
74
	CGLA::Vec3f get_v0() const {return vert[0];}
74
	CGLA::Vec3f get_v0() const {return vert[0];}
75
	CGLA::Vec3f get_v1() const {return vert[1];}
75
	CGLA::Vec3f get_v1() const {return vert[1];}
76
	CGLA::Vec3f get_v2() const {return vert[2];}
76
	CGLA::Vec3f get_v2() const {return vert[2];}
77
 
77
 
78
	const CGLA::Vec3f& get_edge(int i) const {return edge[i];}
78
	const CGLA::Vec3f& get_edge(int i) const {return edge[i];}
79
 
79
 
80
	const CGLA::Vec3f& get_face_norm() const {return face_norm;}
80
	const CGLA::Vec3f& get_face_norm() const {return face_norm;}
81
	
81
	
82
};	
82
};	
83
 
83
 
84
}
84
}
85
#endif
85
#endif
86
 
86