Subversion Repositories gelsvn

Rev

Rev 321 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 321 Rev 595
-
 
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
 
1
#include "AABox.h"
7
#include "AABox.h"
2
#include "BoundingINode.h"
8
#include "BoundingINode.h"
3
 
9
 
4
using namespace std;
10
using namespace std;
5
using namespace CGLA;
11
using namespace CGLA;
6
 
12
 
7
namespace Geometry
13
namespace Geometry
8
{
14
{
9
 
15
 
10
template<class BoxType>
16
template<class BoxType>
11
int BoundingINode<BoxType>::intersect_cnt(const CGLA::Vec3f& p , 
17
int BoundingINode<BoxType>::intersect_cnt(const CGLA::Vec3f& p , 
12
																 const CGLA::Vec3f& dir) const
18
																 const CGLA::Vec3f& dir) const
13
{
19
{
14
	if(!BoxType::intersect(p,dir))
20
	if(!BoxType::intersect(p,dir))
15
		return 0;
21
		return 0;
16
 
22
 
17
	int li = left->intersect_cnt(p,dir);
23
	int li = left->intersect_cnt(p,dir);
18
	int ri = right->intersect_cnt(p,dir);
24
	int ri = right->intersect_cnt(p,dir);
19
	return li + ri;
25
	return li + ri;
20
}
26
}
21
 
27
 
22
template<class BoxType>
28
template<class BoxType>
23
void BoundingINode<BoxType>::intersect(Ray& r) const 
29
void BoundingINode<BoxType>::intersect(Ray& r) const 
24
{
30
{
25
	if(BoxType::intersect(r.origin,r.direction))
31
	if(BoxType::intersect(r.origin,r.direction))
26
	{
32
	{
27
			left->intersect(r);
33
			left->intersect(r);
28
			right->intersect(r);
34
			right->intersect(r);
29
	}
35
	}
30
}
36
}
31
 
37
 
32
template<class BoxType>
38
template<class BoxType>
33
bool BoundingINode<BoxType>::intersect(const CGLA::Vec3f& p , const CGLA::Vec3f& dir,
39
bool BoundingINode<BoxType>::intersect(const CGLA::Vec3f& p , const CGLA::Vec3f& dir,
34
															float& tmin) const 
40
															float& tmin) const 
35
{
41
{
36
	if(!BoxType::intersect(p,dir))
42
	if(!BoxType::intersect(p,dir))
37
		return false;
43
		return false;
38
 
44
 
39
	float tminl=1e33f, tminr=1e33f;
45
	float tminl=1e33f, tminr=1e33f;
40
	bool li = left->intersect(p,dir,tminl);
46
	bool li = left->intersect(p,dir,tminl);
41
	bool ri = right->intersect(p,dir,tminr);
47
	bool ri = right->intersect(p,dir,tminr);
42
	if(li||ri)
48
	if(li||ri)
43
		{
49
		{
44
			tmin = min(tminl,tminr);
50
			tmin = min(tminl,tminr);
45
			return true;
51
			return true;
46
		}
52
		}
47
	return false;
53
	return false;
48
}
54
}
49
 
55
 
50
template class BoundingINode<AABox>;
56
template class BoundingINode<AABox>;
51
template class BoundingINode<OBox>;
57
template class BoundingINode<OBox>;
52
 
58
 
53
}
59
}
54
 
60