Subversion Repositories gelsvn

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
595 jab 1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * ----------------------------------------------------------------------- */
6
 
7
/**
8
 * @file Triangle.h
9
 * @brief Triangle class for use with bbox hierarchies.
10
 */
11
 
443 jab 12
#ifndef __GEOMETRY_TRIANGLE_H
13
#define __GEOMETRY_TRIANGLE_H
290 jrf 14
 
601 jab 15
#include "../CGLA/Vec2f.h"
16
#include "../CGLA/Vec3f.h"
17
#include "../CGLA/Mat3x3f.h"
290 jrf 18
 
291 jrf 19
namespace Geometry
20
{
21
 
290 jrf 22
class Triangle
23
{
24
	CGLA::Vec3f vert[3];
25
	CGLA::Vec3f edge[3];
26
 
27
	CGLA::Vec3f vert_norm[3];
28
	CGLA::Vec3f edge_norm[3];
29
	CGLA::Vec3f face_norm;
30
 
31
	CGLA::Vec3f tri_plane_edge_norm[3];
32
	float edge_len[3];
33
 
34
 public:
35
 
36
	Triangle() {}
37
 
38
	Triangle(const CGLA::Vec3f& _v0, 
39
					 const CGLA::Vec3f& _v1, 
40
					 const CGLA::Vec3f& _v2,
41
 
42
					 const CGLA::Vec3f& _vn0,
43
					 const CGLA::Vec3f& _vn1,
44
					 const CGLA::Vec3f& _vn2,
45
 
46
					 const CGLA::Vec3f& _en0,
47
					 const CGLA::Vec3f& _en1,
48
					 const CGLA::Vec3f& _en2);
49
 
50
	bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&, float&) const;
51
 
52
	const CGLA::Vec3f get_pmin() const 
53
	{
54
		return v_min(vert[0],v_min(vert[1],vert[2]));
55
	}
56
 
57
	const CGLA::Vec3f get_pmax() const 
58
	{
59
		return v_max(vert[0],v_max(vert[1],vert[2]));
60
	}
61
 
62
	const CGLA::Vec3f centre() const
63
		{
64
			return (vert[0]+vert[1]+vert[2])/3.0f;
65
		}
66
 
67
	const float area() const 
68
		{
69
			return 0.5 * (cross(edge[0],-edge[2])).length();
70
		}
71
 
72
	const CGLA::Vec3f get_centre() const 
73
	{
74
		CGLA::Vec3f pmin = get_pmin();
75
		CGLA::Vec3f pmax = get_pmax();
76
		return (pmax-pmin)/2.0f+pmin;
77
	}
78
 
79
	bool signed_distance(const CGLA::Vec3f& p, float& sq_dist, float& sgn) const;
80
 
81
	CGLA::Vec3f get_v0() const {return vert[0];}
82
	CGLA::Vec3f get_v1() const {return vert[1];}
83
	CGLA::Vec3f get_v2() const {return vert[2];}
84
 
85
	const CGLA::Vec3f& get_edge(int i) const {return edge[i];}
309 jab 86
 
87
	const CGLA::Vec3f& get_face_norm() const {return face_norm;}
290 jrf 88
 
89
};	
90
 
291 jrf 91
}
290 jrf 92
#endif