Subversion Repositories gelsvn

Rev

Rev 290 | 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 "AABox.h"
2
#include "AABox.h"
4
 
3
 
5
using namespace std;
4
using namespace std;
6
using namespace CGLA;
5
using namespace CGLA;
7
 
6
 
-
 
7
namespace Geometry
-
 
8
{
-
 
9
 
8
bool AABox::intersect(const CGLA::Vec3f& p, const CGLA::Vec3f& dir) const
10
bool AABox::intersect(const CGLA::Vec3f& p, const CGLA::Vec3f& dir) const
9
{
11
{
10
	Vec3f t0,t1;
12
	Vec3f t0,t1;
11
	for(int i=0;i<3;++i)
13
	for(int i=0;i<3;++i)
12
		{
14
		{
Line 17... Line 19...
17
	float tmax = min(max(t0[0],t1[0]),min(max(t0[1],t1[1]),max(t0[2],t1[2])));
19
	float tmax = min(max(t0[0],t1[0]),min(max(t0[1],t1[1]),max(t0[2],t1[2])));
18
 
20
 
19
	return ( (tmin + CGLA::TINY) <tmax);
21
	return ( (tmin + CGLA::TINY) <tmax);
20
}
22
}
21
 
23
 
22
void AABox::gl_draw() const
-
 
23
{
-
 
24
	glBegin(GL_QUADS);
-
 
25
	Vec3f norm_neg[] = {Vec3f(0,0,-1), Vec3f(-1,0,0), Vec3f(0,-1,0)};
-
 
26
	Vec3f norm_pos[] = {Vec3f(0,0, 1), Vec3f( 1,0,0), Vec3f(0, 1,0)};
-
 
27
	for(int j=0;j<3;++j)
-
 
28
		{
-
 
29
			glNormal3fv(norm_neg[j].get());
-
 
30
			Vec3f p = pmin;
-
 
31
			glVertex3f(p[0], p[1], p[2]);
-
 
32
			p[(j+1)%3] = pmax[(j+1)%3];
-
 
33
			glVertex3f(p[0], p[1], p[2]);
-
 
34
			p[j] = pmax[j];
-
 
35
			glVertex3f(p[0], p[1], p[2]);
-
 
36
			p[(j+1)%3] = pmin[(j+1)%3];
-
 
37
			glVertex3f(p[0], p[1], p[2]);
-
 
38
		}
-
 
39
	glEnd();
-
 
40
	glBegin(GL_QUADS);
-
 
41
	for(int j=0;j<3;++j)
-
 
42
		{
-
 
43
			glNormal3fv(norm_pos[j].get());
-
 
44
			Vec3f p = pmax;
-
 
45
			glVertex3f(p[0], p[1], p[2]);
-
 
46
			p[j] = pmin[j];
-
 
47
			glVertex3f(p[0], p[1], p[2]);
-
 
48
			p[(j+1)%3] = pmin[(j+1)%3];
-
 
49
			glVertex3f(p[0], p[1], p[2]);
-
 
50
			p[j] = pmax[j];
-
 
51
			glVertex3f(p[0], p[1], p[2]);
-
 
52
		}
-
 
53
	glEnd();
-
 
54
}
-
 
55
 
-
 
56
void AABox::minmax_sq_dist(const CGLA::Vec3f& p, 
24
void AABox::minmax_sq_dist(const CGLA::Vec3f& p, 
57
													 float& dmin, float& dmax) const
25
													 float& dmin, float& dmax) const
58
{
26
{
59
	const Vec3f a = 0.5*pmax-0.5*pmin;
27
	const Vec3f a = 0.5*pmax-0.5*pmin;
60
	const Vec3f p0 = pmin + a;
28
	const Vec3f p0 = pmin + a;
Line 170... Line 138...
170
	assert(!rvec.empty());
138
	assert(!rvec.empty());
171
	assert(lvec.size()+rvec.size() == invec.size());
139
	assert(lvec.size()+rvec.size() == invec.size());
172
	return AABox(tri_pmin, tri_pmax, centre_close);
140
	return AABox(tri_pmin, tri_pmax, centre_close);
173
}
141
}
174
 
142
 
-
 
143
}