diff options
Diffstat (limited to 'core/math/rect3.h')
-rw-r--r-- | core/math/rect3.h | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/core/math/rect3.h b/core/math/rect3.h index 136a156151..b7c94ad9f7 100644 --- a/core/math/rect3.h +++ b/core/math/rect3.h @@ -36,12 +36,12 @@ /** * AABB / AABB (Axis Aligned Bounding Box) - * This is implemented by a point (pos) and the box size + * This is implemented by a point (position) and the box size */ class Rect3 { public: - Vector3 pos; + Vector3 position; Vector3 size; real_t get_area() const; /// get area @@ -55,8 +55,8 @@ public: return (size.x <= CMP_EPSILON && size.y <= CMP_EPSILON && size.z <= CMP_EPSILON); } - const Vector3 &get_pos() const { return pos; } - void set_pos(const Vector3 &p_pos) { pos = p_pos; } + const Vector3 &get_position() const { return position; } + void set_position(const Vector3 &p_pos) { position = p_pos; } const Vector3 &get_size() const { return size; } void set_size(const Vector3 &p_size) { size = p_size; } @@ -102,24 +102,24 @@ public: _FORCE_INLINE_ Rect3() {} inline Rect3(const Vector3 &p_pos, const Vector3 &p_size) { - pos = p_pos; + position = p_pos; size = p_size; } }; inline bool Rect3::intersects(const Rect3 &p_aabb) const { - if (pos.x >= (p_aabb.pos.x + p_aabb.size.x)) + if (position.x >= (p_aabb.position.x + p_aabb.size.x)) return false; - if ((pos.x + size.x) <= p_aabb.pos.x) + if ((position.x + size.x) <= p_aabb.position.x) return false; - if (pos.y >= (p_aabb.pos.y + p_aabb.size.y)) + if (position.y >= (p_aabb.position.y + p_aabb.size.y)) return false; - if ((pos.y + size.y) <= p_aabb.pos.y) + if ((position.y + size.y) <= p_aabb.position.y) return false; - if (pos.z >= (p_aabb.pos.z + p_aabb.size.z)) + if (position.z >= (p_aabb.position.z + p_aabb.size.z)) return false; - if ((pos.z + size.z) <= p_aabb.pos.z) + if ((position.z + size.z) <= p_aabb.position.z) return false; return true; @@ -127,17 +127,17 @@ inline bool Rect3::intersects(const Rect3 &p_aabb) const { inline bool Rect3::intersects_inclusive(const Rect3 &p_aabb) const { - if (pos.x > (p_aabb.pos.x + p_aabb.size.x)) + if (position.x > (p_aabb.position.x + p_aabb.size.x)) return false; - if ((pos.x + size.x) < p_aabb.pos.x) + if ((position.x + size.x) < p_aabb.position.x) return false; - if (pos.y > (p_aabb.pos.y + p_aabb.size.y)) + if (position.y > (p_aabb.position.y + p_aabb.size.y)) return false; - if ((pos.y + size.y) < p_aabb.pos.y) + if ((position.y + size.y) < p_aabb.position.y) return false; - if (pos.z > (p_aabb.pos.z + p_aabb.size.z)) + if (position.z > (p_aabb.position.z + p_aabb.size.z)) return false; - if ((pos.z + size.z) < p_aabb.pos.z) + if ((position.z + size.z) < p_aabb.position.z) return false; return true; @@ -145,10 +145,10 @@ inline bool Rect3::intersects_inclusive(const Rect3 &p_aabb) const { inline bool Rect3::encloses(const Rect3 &p_aabb) const { - Vector3 src_min = pos; - Vector3 src_max = pos + size; - Vector3 dst_min = p_aabb.pos; - Vector3 dst_max = p_aabb.pos + p_aabb.size; + Vector3 src_min = position; + Vector3 src_max = position + size; + Vector3 dst_min = p_aabb.position; + Vector3 dst_max = p_aabb.position + p_aabb.size; return ( (src_min.x <= dst_min.x) && @@ -162,7 +162,7 @@ inline bool Rect3::encloses(const Rect3 &p_aabb) const { Vector3 Rect3::get_support(const Vector3 &p_normal) const { Vector3 half_extents = size * 0.5; - Vector3 ofs = pos + half_extents; + Vector3 ofs = position + half_extents; return Vector3( (p_normal.x > 0) ? -half_extents.x : half_extents.x, @@ -174,14 +174,14 @@ Vector3 Rect3::get_support(const Vector3 &p_normal) const { Vector3 Rect3::get_endpoint(int p_point) const { 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); + case 0: return Vector3(position.x, position.y, position.z); + case 1: return Vector3(position.x, position.y, position.z + size.z); + case 2: return Vector3(position.x, position.y + size.y, position.z); + case 3: return Vector3(position.x, position.y + size.y, position.z + size.z); + case 4: return Vector3(position.x + size.x, position.y, position.z); + case 5: return Vector3(position.x + size.x, position.y, position.z + size.z); + case 6: return Vector3(position.x + size.x, position.y + size.y, position.z); + case 7: return Vector3(position.x + size.x, position.y + size.y, position.z + size.z); }; ERR_FAIL_V(Vector3()); @@ -192,7 +192,7 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co #if 1 Vector3 half_extents = size * 0.5; - Vector3 ofs = pos + half_extents; + Vector3 ofs = position + half_extents; for (int i = 0; i < p_plane_count; i++) { const Plane &p = p_planes[i]; @@ -210,14 +210,14 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co //cache all points to check against! // #warning should be easy to optimize, just use the same as when taking the support and use only that point Vector3 points[8] = { - 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), + Vector3(position.x, position.y, position.z), + Vector3(position.x, position.y, position.z + size.z), + Vector3(position.x, position.y + size.y, position.z), + Vector3(position.x, position.y + size.y, position.z + size.z), + Vector3(position.x + size.x, position.y, position.z), + Vector3(position.x + size.x, position.y, position.z + size.z), + Vector3(position.x + size.x, position.y + size.y, position.z), + Vector3(position.x + size.x, position.y + size.y, position.z + size.z), }; for (int i = 0; i < p_plane_count; i++) { //for each plane @@ -246,17 +246,17 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co bool Rect3::has_point(const Vector3 &p_point) const { - if (p_point.x < pos.x) + if (p_point.x < position.x) return false; - if (p_point.y < pos.y) + if (p_point.y < position.y) return false; - if (p_point.z < pos.z) + if (p_point.z < position.z) return false; - if (p_point.x > pos.x + size.x) + if (p_point.x > position.x + size.x) return false; - if (p_point.y > pos.y + size.y) + if (p_point.y > position.y + size.y) return false; - if (p_point.z > pos.z + size.z) + if (p_point.z > position.z + size.z) return false; return true; @@ -264,8 +264,8 @@ bool Rect3::has_point(const Vector3 &p_point) const { inline void Rect3::expand_to(const Vector3 &p_vector) { - Vector3 begin = pos; - Vector3 end = pos + size; + Vector3 begin = position; + Vector3 end = position + size; if (p_vector.x < begin.x) begin.x = p_vector.x; @@ -281,14 +281,14 @@ inline void Rect3::expand_to(const Vector3 &p_vector) { if (p_vector.z > end.z) end.z = p_vector.z; - pos = begin; + position = begin; size = end - begin; } void Rect3::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const { 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); + Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z); real_t length = p_plane.normal.abs().dot(half_extents); real_t distance = p_plane.distance_to(center); @@ -332,21 +332,21 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t real_t divy = 1.0 / dir.y; real_t divz = 1.0 / dir.z; - Vector3 upbound = pos + size; + Vector3 upbound = position + size; real_t tmin, tmax, tymin, tymax, tzmin, tzmax; if (dir.x >= 0) { - tmin = (pos.x - from.x) * divx; + tmin = (position.x - from.x) * divx; tmax = (upbound.x - from.x) * divx; } else { tmin = (upbound.x - from.x) * divx; - tmax = (pos.x - from.x) * divx; + tmax = (position.x - from.x) * divx; } if (dir.y >= 0) { - tymin = (pos.y - from.y) * divy; + tymin = (position.y - from.y) * divy; tymax = (upbound.y - from.y) * divy; } else { tymin = (upbound.y - from.y) * divy; - tymax = (pos.y - from.y) * divy; + tymax = (position.y - from.y) * divy; } if ((tmin > tymax) || (tymin > tmax)) return false; @@ -355,11 +355,11 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t if (tymax < tmax) tmax = tymax; if (dir.z >= 0) { - tzmin = (pos.z - from.z) * divz; + tzmin = (position.z - from.z) * divz; tzmax = (upbound.z - from.z) * divz; } else { tzmin = (upbound.z - from.z) * divz; - tzmax = (pos.z - from.z) * divz; + tzmax = (position.z - from.z) * divz; } if ((tmin > tzmax) || (tzmin > tmax)) return false; @@ -372,9 +372,9 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t void Rect3::grow_by(real_t p_amount) { - pos.x -= p_amount; - pos.y -= p_amount; - pos.z -= p_amount; + position.x -= p_amount; + position.y -= p_amount; + position.z -= p_amount; size.x += 2.0 * p_amount; size.y += 2.0 * p_amount; size.z += 2.0 * p_amount; |