Subversion Repositories gelsvn

Rev

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

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