Subversion Repositories gelsvn

Rev

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

Rev Author Line No. Line
290 jrf 1
#ifndef __BOUNDINGLNODE_H
2
#define __BOUNDINGLNODE_H
3
 
4
#include "BoundingNode.h"
5
 
6
#define USE_LEAF_BOXES 1
7
 
8
/// Leaf node of a bounding box tree. References triangle.
9
template<class BoxType>
10
class BoundingLNode: public BoundingNode<BoxType>
11
{
12
	Triangle tri;
13
 public:
14
 
15
#if USE_LEAF_BOXES
16
	BoundingLNode(const BoxType& box,
17
								const Triangle& _tri): BoundingNode<BoxType>(box), tri(_tri) {}
18
#else
19
	BoundingLNode(const Triangle& _tri): BoundingNode<BoxType>(BoxType()), tri(_tri) {}
20
#endif
21
 
22
	~BoundingLNode() {}
23
 
24
	bool intersect(const CGLA::Vec3f&,const CGLA::Vec3f&,float&) const;
25
	int intersect_cnt(const CGLA::Vec3f&,const CGLA::Vec3f&) const;
26
 
27
	void sq_distance(const CGLA::Vec3f&, float&, float&, float&) const;
28
 
29
	void draw(int l, int lmax) const
30
		{
31
#if USE_LEAF_BOXES
32
 			gl_draw(); 
33
#endif
34
		}
35
 
36
	virtual bool is_leaf() const {return true;}
37
 
38
	const Triangle& get_tri() const {return tri;}
39
};
40
 
41
template<class BoxType>
42
inline bool BoundingLNode<BoxType>::intersect(const CGLA::Vec3f& p, 
43
																							const CGLA::Vec3f& dir,
44
																							float& tmin) const
45
{
46
#if USE_LEAF_BOXES
47
	if(BoxType::intersect(p,dir))
48
 		return tri.intersect(p,dir,tmin);
49
 	return false;
50
#else
51
	return tri.intersect(p,dir,tmin);
52
#endif
53
 
54
}
55
 
56
template<class BoxType>
57
inline int BoundingLNode<BoxType>::intersect_cnt(const CGLA::Vec3f& p, 
58
																								 const CGLA::Vec3f& dir) const
59
{
60
#if USE_LEAF_BOXES
61
	float tmin=1e33;
62
	if(BoxType::intersect(p,dir) && 
63
		 tri.intersect(p,dir,tmin) &&
64
		 tmin > 0)
65
		return 1;
66
	return 0;
67
#else
68
	float tmin=1e33;
69
	if(tri.intersect(p,dir,tmin) &&
70
		 tmin > 0)
71
		return 1;
72
	return 0;
73
#endif
74
}
75
 
76
template<class BoxType>
77
inline void BoundingLNode<BoxType>::sq_distance(const CGLA::Vec3f& p, 
78
																								float& dmin, 
79
																								float& dmax, float& s) const
80
{
81
 	bool did_work = tri.signed_distance(p,dmax,s);
82
	if(!did_work) std::cout << dmax << std::endl;
83
	assert(did_work);
84
 	dmin = dmax; 
85
}
86
 
87
 
88
#endif