2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* aabb.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:11:45 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:45:00 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef AABB_H
|
|
|
|
#define AABB_H
|
|
|
|
|
|
|
|
#include "plane.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "vector3.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
/**
|
|
|
|
* AABB / AABB (Axis Aligned Bounding Box)
|
|
|
|
* This is implemented by a point (pos) and the box size
|
|
|
|
*/
|
|
|
|
|
|
|
|
class AABB {
|
|
|
|
public:
|
|
|
|
Vector3 pos;
|
|
|
|
Vector3 size;
|
|
|
|
|
|
|
|
float get_area() const; /// get area
|
|
|
|
_FORCE_INLINE_ bool has_no_area() const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return (size.x <= CMP_EPSILON || size.y <= CMP_EPSILON || size.z <= CMP_EPSILON);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ bool has_no_surface() const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return (size.x <= CMP_EPSILON && size.y <= CMP_EPSILON && size.z <= CMP_EPSILON);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Vector3 &get_pos() const { return pos; }
|
|
|
|
void set_pos(const Vector3 &p_pos) { pos = p_pos; }
|
|
|
|
const Vector3 &get_size() const { return size; }
|
|
|
|
void set_size(const Vector3 &p_size) { size = p_size; }
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool operator==(const AABB &p_rval) const;
|
|
|
|
bool operator!=(const AABB &p_rval) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_FORCE_INLINE_ bool intersects(const AABB &p_aabb) const; /// Both AABBs overlap
|
|
|
|
_FORCE_INLINE_ bool intersects_inclusive(const AABB &p_aabb) const; /// Both AABBs (or their faces) overlap
|
|
|
|
_FORCE_INLINE_ bool encloses(const AABB &p_aabb) const; /// p_aabb is completely inside this
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
AABB merge(const AABB &p_with) const;
|
|
|
|
void merge_with(const AABB &p_aabb); ///merge with another AABB
|
|
|
|
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;
|
2014-06-11 13:41:03 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
_FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
|
|
|
|
bool intersects_plane(const Plane &p_plane) const;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_FORCE_INLINE_ bool has_point(const Vector3 &p_point) const;
|
|
|
|
_FORCE_INLINE_ Vector3 get_support(const Vector3 &p_normal) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector3 get_longest_axis() const;
|
|
|
|
int get_longest_axis_index() const;
|
|
|
|
_FORCE_INLINE_ real_t get_longest_axis_size() const;
|
|
|
|
|
|
|
|
Vector3 get_shortest_axis() const;
|
|
|
|
int get_shortest_axis_index() const;
|
|
|
|
_FORCE_INLINE_ real_t get_shortest_axis_size() const;
|
|
|
|
|
|
|
|
AABB grow(real_t p_by) const;
|
2014-06-11 13:41:03 +00:00
|
|
|
_FORCE_INLINE_ void grow_by(real_t p_amount);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
_FORCE_INLINE_ Vector3 get_endpoint(int p_point) const;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
AABB expand(const Vector3 &p_vector) const;
|
|
|
|
_FORCE_INLINE_ void project_range_in_plane(const Plane &p_plane, float &r_min, float &r_max) const;
|
|
|
|
_FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necesary */
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
operator String() const;
|
|
|
|
|
|
|
|
_FORCE_INLINE_ AABB() {}
|
2017-03-18 23:36:26 +00:00
|
|
|
inline AABB(const Vector3 &p_pos, const Vector3 &p_size) {
|
|
|
|
pos = p_pos;
|
|
|
|
size = p_size;
|
|
|
|
}
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
inline bool AABB::intersects(const AABB &p_aabb) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (pos.x >= (p_aabb.pos.x + p_aabb.size.x))
|
|
|
|
return false;
|
|
|
|
if ((pos.x + size.x) <= p_aabb.pos.x)
|
|
|
|
return false;
|
|
|
|
if (pos.y >= (p_aabb.pos.y + p_aabb.size.y))
|
|
|
|
return false;
|
|
|
|
if ((pos.y + size.y) <= p_aabb.pos.y)
|
|
|
|
return false;
|
|
|
|
if (pos.z >= (p_aabb.pos.z + p_aabb.size.z))
|
|
|
|
return false;
|
|
|
|
if ((pos.z + size.z) <= p_aabb.pos.z)
|
|
|
|
return false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
inline bool AABB::intersects_inclusive(const AABB &p_aabb) const {
|
|
|
|
|
|
|
|
if (pos.x > (p_aabb.pos.x + p_aabb.size.x))
|
|
|
|
return false;
|
|
|
|
if ((pos.x + size.x) < p_aabb.pos.x)
|
|
|
|
return false;
|
|
|
|
if (pos.y > (p_aabb.pos.y + p_aabb.size.y))
|
|
|
|
return false;
|
|
|
|
if ((pos.y + size.y) < p_aabb.pos.y)
|
|
|
|
return false;
|
|
|
|
if (pos.z > (p_aabb.pos.z + p_aabb.size.z))
|
|
|
|
return false;
|
|
|
|
if ((pos.z + size.z) < p_aabb.pos.z)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2016-02-17 19:06:40 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
inline bool AABB::encloses(const AABB &p_aabb) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector3 src_min = pos;
|
|
|
|
Vector3 src_max = pos + size;
|
|
|
|
Vector3 dst_min = p_aabb.pos;
|
|
|
|
Vector3 dst_max = p_aabb.pos + p_aabb.size;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return (
|
|
|
|
(src_min.x <= dst_min.x) &&
|
2014-02-10 01:10:30 +00:00
|
|
|
(src_max.x > dst_max.x) &&
|
|
|
|
(src_min.y <= dst_min.y) &&
|
|
|
|
(src_max.y > dst_max.y) &&
|
|
|
|
(src_min.z <= dst_min.z) &&
|
2017-03-18 23:36:26 +00:00
|
|
|
(src_max.z > dst_max.z));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector3 AABB::get_support(const Vector3 &p_normal) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector3 half_extents = size * 0.5;
|
|
|
|
Vector3 ofs = pos + half_extents;
|
|
|
|
|
|
|
|
return Vector3(
|
2017-03-18 23:36:26 +00:00
|
|
|
(p_normal.x > 0) ? -half_extents.x : half_extents.x,
|
|
|
|
(p_normal.y > 0) ? -half_extents.y : half_extents.y,
|
|
|
|
(p_normal.z > 0) ? -half_extents.z : half_extents.z) +
|
|
|
|
ofs;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 AABB::get_endpoint(int p_point) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_point) {
|
|
|
|
case 0: return Vector3(pos.x, pos.y, pos.z);
|
|
|
|
case 1: return Vector3(pos.x, pos.y, pos.z + size.z);
|
|
|
|
case 2: return Vector3(pos.x, pos.y + size.y, pos.z);
|
|
|
|
case 3: return Vector3(pos.x, pos.y + size.y, pos.z + size.z);
|
|
|
|
case 4: return Vector3(pos.x + size.x, pos.y, pos.z);
|
|
|
|
case 5: return Vector3(pos.x + size.x, pos.y, pos.z + size.z);
|
|
|
|
case 6: return Vector3(pos.x + size.x, pos.y + size.y, pos.z);
|
|
|
|
case 7: return Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z);
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ERR_FAIL_V(Vector3());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const {
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
|
|
|
Vector3 half_extents = size * 0.5;
|
|
|
|
Vector3 ofs = pos + half_extents;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_plane_count; i++) {
|
|
|
|
const Plane &p = p_planes[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 point(
|
2017-03-18 23:36:26 +00:00
|
|
|
(p.normal.x > 0) ? -half_extents.x : half_extents.x,
|
|
|
|
(p.normal.y > 0) ? -half_extents.y : half_extents.y,
|
|
|
|
(p.normal.z > 0) ? -half_extents.z : half_extents.z);
|
|
|
|
point += ofs;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (p.is_point_over(point))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
//cache all points to check against!
|
2017-03-18 23:36:26 +00:00
|
|
|
// #warning should be easy to optimize, just use the same as when taking the support and use only that point
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 points[8] = {
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector3(pos.x, pos.y, pos.z),
|
|
|
|
Vector3(pos.x, pos.y, pos.z + size.z),
|
|
|
|
Vector3(pos.x, pos.y + size.y, pos.z),
|
|
|
|
Vector3(pos.x, pos.y + size.y, pos.z + size.z),
|
|
|
|
Vector3(pos.x + size.x, pos.y, pos.z),
|
|
|
|
Vector3(pos.x + size.x, pos.y, pos.z + size.z),
|
|
|
|
Vector3(pos.x + size.x, pos.y + size.y, pos.z),
|
|
|
|
Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z),
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_plane_count; i++) { //for each plane
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Plane &plane = p_planes[i];
|
|
|
|
bool all_points_over = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
//test if it has all points over!
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int j = 0; j < 8; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!plane.is_point_over(points[j])) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
all_points_over = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all_points_over) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool AABB::has_point(const Vector3 &p_point) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_point.x < pos.x)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_point.y < pos.y)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_point.z < pos.z)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_point.x > pos.x + size.x)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_point.y > pos.y + size.y)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_point.z > pos.z + size.z)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
inline void AABB::expand_to(const Vector3 &p_vector) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector3 begin = pos;
|
|
|
|
Vector3 end = pos + size;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_vector.x < begin.x)
|
|
|
|
begin.x = p_vector.x;
|
|
|
|
if (p_vector.y < begin.y)
|
|
|
|
begin.y = p_vector.y;
|
|
|
|
if (p_vector.z < begin.z)
|
|
|
|
begin.z = p_vector.z;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_vector.x > end.x)
|
|
|
|
end.x = p_vector.x;
|
|
|
|
if (p_vector.y > end.y)
|
|
|
|
end.y = p_vector.y;
|
|
|
|
if (p_vector.z > end.z)
|
|
|
|
end.z = p_vector.z;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
pos = begin;
|
|
|
|
size = end - begin;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void AABB::project_range_in_plane(const Plane &p_plane, float &r_min, float &r_max) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5);
|
|
|
|
Vector3 center(pos.x + half_extents.x, pos.y + half_extents.y, pos.z + half_extents.z);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
float length = p_plane.normal.abs().dot(half_extents);
|
2017-03-18 23:36:26 +00:00
|
|
|
float distance = p_plane.distance_to(center);
|
2014-02-10 01:10:30 +00:00
|
|
|
r_min = distance - length;
|
2016-03-08 23:00:52 +00:00
|
|
|
r_max = distance + length;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline real_t AABB::get_longest_axis_size() const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
real_t max_size = size.x;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (size.y > max_size) {
|
|
|
|
max_size = size.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (size.z > max_size) {
|
|
|
|
max_size = size.z;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return max_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline real_t AABB::get_shortest_axis_size() const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
real_t max_size = size.x;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (size.y < max_size) {
|
|
|
|
max_size = size.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (size.z < max_size) {
|
|
|
|
max_size = size.z;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return max_size;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, float t0, float t1) const {
|
2014-06-11 13:41:03 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
float divx = 1.0 / dir.x;
|
|
|
|
float divy = 1.0 / dir.y;
|
|
|
|
float divz = 1.0 / dir.z;
|
2014-06-11 13:41:03 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector3 upbound = pos + size;
|
2014-06-11 13:41:03 +00:00
|
|
|
float tmin, tmax, tymin, tymax, tzmin, tzmax;
|
|
|
|
if (dir.x >= 0) {
|
|
|
|
tmin = (pos.x - from.x) * divx;
|
|
|
|
tmax = (upbound.x - from.x) * divx;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else {
|
2014-06-11 13:41:03 +00:00
|
|
|
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;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else {
|
2014-06-11 13:41:03 +00:00
|
|
|
tymin = (upbound.y - from.y) * divy;
|
|
|
|
tymax = (pos.y - from.y) * divy;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if ((tmin > tymax) || (tymin > tmax))
|
2014-06-11 13:41:03 +00:00
|
|
|
return false;
|
|
|
|
if (tymin > tmin)
|
2017-03-18 23:36:26 +00:00
|
|
|
tmin = tymin;
|
2014-06-11 13:41:03 +00:00
|
|
|
if (tymax < tmax)
|
|
|
|
tmax = tymax;
|
|
|
|
if (dir.z >= 0) {
|
|
|
|
tzmin = (pos.z - from.z) * divz;
|
|
|
|
tzmax = (upbound.z - from.z) * divz;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else {
|
2014-06-11 13:41:03 +00:00
|
|
|
tzmin = (upbound.z - from.z) * divz;
|
|
|
|
tzmax = (pos.z - from.z) * divz;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if ((tmin > tzmax) || (tzmin > tmax))
|
2014-06-11 13:41:03 +00:00
|
|
|
return false;
|
|
|
|
if (tzmin > tmin)
|
|
|
|
tmin = tzmin;
|
|
|
|
if (tzmax < tmax)
|
|
|
|
tmax = tzmax;
|
2017-03-18 23:36:26 +00:00
|
|
|
return ((tmin < t1) && (tmax > t0));
|
2014-06-11 13:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AABB::grow_by(real_t p_amount) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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;
|
2014-06-11 13:41:03 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
typedef AABB Rect3;
|
|
|
|
|
|
|
|
#endif // AABB_H
|