Subversion Repositories gelsvn

Rev

Rev 290 | Rev 299 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 290 Rev 291
Line 1... Line 1...
1
#include <cfloat>
1
#include <cfloat>
2
#include <GL/gl.h>
-
 
3
#include "CGLA/statistics.h"
2
#include "CGLA/statistics.h"
4
#include "CGLA/eigensolution.h"
3
#include "CGLA/eigensolution.h"
5
#include "CGLA/Mat4x4f.h"
4
#include "CGLA/Mat4x4f.h"
6
#include "AABox.h"
5
#include "AABox.h"
7
#include "OBox.h"
6
#include "OBox.h"
-
 
7
#include "Triangle.h"
8
 
8
 
9
using namespace std;
9
using namespace std;
10
using namespace CGLA;
10
using namespace CGLA;
11
 
11
 
12
namespace
12
namespace
13
{
13
{
14
 
14
 
15
	Mat3x3f compute_rotation(const vector<Triangle>& invec)
15
	Mat3x3f compute_rotation(const vector<Geometry::Triangle>& invec)
16
	{
16
	{
17
		const int N_tri = invec.size();
17
		const int N_tri = invec.size();
18
 
18
 
19
		Mat3x3f C;
19
		Mat3x3f C;
20
		float a_H = 0;
20
		float a_H = 0;
21
		Vec3f m_H(0);
21
		Vec3f m_H(0);
22
		
22
		
23
		for(int i=0;i<N_tri;++i)
23
		for(int i=0;i<N_tri;++i)
24
			{
24
			{
25
				const Triangle& tri = invec[i];
25
				const Geometry::Triangle& tri = invec[i];
26
				
26
				
27
				float a_k = tri.area();
27
				float a_k = tri.area();
28
				a_H += a_k;
28
				a_H += a_k;
29
				
29
				
30
				Vec3f m_k = tri.centre();
30
				Vec3f m_k = tri.centre();
Line 80... Line 80...
80
 
80
 
81
 
81
 
82
 
82
 
83
}
83
}
84
 
84
 
-
 
85
namespace Geometry
-
 
86
{
-
 
87
 
85
bool OBox::intersect(const CGLA::Vec3f& p, const CGLA::Vec3f& d) const 
88
bool OBox::intersect(const CGLA::Vec3f& p, const CGLA::Vec3f& d) const 
86
{
89
{
87
	Vec3f pr = R * p;
90
	Vec3f pr = R * p;
88
	Vec3f dr = R * d;
91
	Vec3f dr = R * d;
89
	return aabox.intersect(pr, dr);
92
	return aabox.intersect(pr, dr);
Line 94... Line 97...
94
{
97
{
95
	Vec3f pr = R * p;
98
	Vec3f pr = R * p;
96
	aabox.minmax_sq_dist(pr, dmin, dmax);
99
	aabox.minmax_sq_dist(pr, dmin, dmax);
97
}
100
}
98
 
101
 
99
void OBox::gl_draw() const
-
 
100
{
-
 
101
	Mat4x4f m = identity_Mat4x4f();
-
 
102
	copy_matrix(R, m);
-
 
103
	glPushMatrix();
-
 
104
	glMultMatrixf(m.get());
-
 
105
	aabox.gl_draw();
-
 
106
	glPopMatrix();
-
 
107
}
-
 
108
 
-
 
109
OBox OBox::box_triangle(const Triangle& t)
102
OBox OBox::box_triangle(const Triangle& t)
110
{
103
{
111
	Vec3f e0 = t.get_v1()-t.get_v0();
104
	Vec3f e0 = t.get_v1()-t.get_v0();
112
	Vec3f e1 = t.get_v2()-t.get_v1();
105
	Vec3f e1 = t.get_v2()-t.get_v1();
113
	Vec3f e2 = t.get_v0()-t.get_v2();
106
	Vec3f e2 = t.get_v0()-t.get_v2();
Line 223... Line 216...
223
		}
216
		}
224
		
217
		
225
	return OBox(Rot, AABox(tri_pmin, tri_pmax, centre_close));
218
	return OBox(Rot, AABox(tri_pmin, tri_pmax, centre_close));
226
}
219
}
227
 
220
 
-
 
221
}
228
 
222