summaryrefslogtreecommitdiff
path: root/core/math/aabb.h
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-06-11 10:41:03 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-06-11 10:41:03 -0300
commit9b8696d3dd92e2ed6f310ad0f0bf3c2182c9c6ae (patch)
treeb2ed0515196bb774504b54aab0bf242992ac3d9f /core/math/aabb.h
parent6f0b4678e26c04abfc88c0226c803e78a108de98 (diff)
Light Baker!
-=-=-=-=-=-= -Support for lightmap baker, have fun figuring out how it works before tutorial is published.
Diffstat (limited to 'core/math/aabb.h')
-rw-r--r--core/math/aabb.h61
1 files changed, 60 insertions, 1 deletions
diff --git a/core/math/aabb.h b/core/math/aabb.h
index 87be03cf16..089d5d15f7 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -73,6 +73,8 @@ public:
AABB intersection(const AABB& p_aabb) const; ///get box where two intersect, empty if no intersection occurs
bool intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
+ _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, float t0, float t1) const;
+
_FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
bool intersects_plane(const Plane &p_plane) const;
@@ -89,7 +91,7 @@ public:
_FORCE_INLINE_ real_t get_shortest_axis_size() const;
AABB grow(real_t p_by) const;
- void grow_by(real_t p_amount);
+ _FORCE_INLINE_ void grow_by(real_t p_amount);
void get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const;
_FORCE_INLINE_ Vector3 get_endpoint(int p_point) const;
@@ -314,6 +316,63 @@ inline real_t AABB::get_shortest_axis_size() const {
return max_size;
}
+bool AABB::smits_intersect_ray(const Vector3 &from,const Vector3& dir, float t0, float t1) const {
+
+ float divx=1.0/dir.x;
+ float divy=1.0/dir.y;
+ float divz=1.0/dir.z;
+
+ Vector3 upbound=pos+size;
+ float tmin, tmax, tymin, tymax, tzmin, tzmax;
+ if (dir.x >= 0) {
+ tmin = (pos.x - from.x) * divx;
+ tmax = (upbound.x - from.x) * divx;
+ }
+ else {
+ tmin = (upbound.x - from.x) * divx;
+ tmax = (pos.x - from.x) * divx;
+ }
+ if (dir.y >= 0) {
+ tymin = (pos.y - from.y) * divy;
+ tymax = (upbound.y - from.y) * divy;
+ }
+ else {
+ tymin = (upbound.y - from.y) * divy;
+ tymax = (pos.y - from.y) * divy;
+ }
+ if ( (tmin > tymax) || (tymin > tmax) )
+ return false;
+ if (tymin > tmin)
+ tmin = tymin;
+ if (tymax < tmax)
+ tmax = tymax;
+ if (dir.z >= 0) {
+ tzmin = (pos.z - from.z) * divz;
+ tzmax = (upbound.z - from.z) * divz;
+ }
+ else {
+ tzmin = (upbound.z - from.z) * divz;
+ tzmax = (pos.z - from.z) * divz;
+ }
+ if ( (tmin > tzmax) || (tzmin > tmax) )
+ return false;
+ if (tzmin > tmin)
+ tmin = tzmin;
+ if (tzmax < tmax)
+ tmax = tzmax;
+ return ( (tmin < t1) && (tmax > t0) );
+}
+
+void AABB::grow_by(real_t p_amount) {
+
+ pos.x-=p_amount;
+ pos.y-=p_amount;
+ pos.z-=p_amount;
+ size.x+=2.0*p_amount;
+ size.y+=2.0*p_amount;
+ size.z+=2.0*p_amount;
+}
+
typedef AABB Rect3;
#endif // AABB_H