summaryrefslogtreecommitdiff
path: root/core/math/face3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/math/face3.cpp')
-rw-r--r--core/math/face3.cpp44
1 files changed, 28 insertions, 16 deletions
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index e1be4f0acf..6d76e116be 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -64,8 +64,9 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_
/* Check for Intersection between this and the next vertex*/
Vector3 inters;
- if (!p_plane.intersects_segment(vertex[i], vertex[(i + 1) % 3], &inters))
+ if (!p_plane.intersects_segment(vertex[i], vertex[(i + 1) % 3], &inters)) {
continue;
+ }
/* Intersection goes to both */
ERR_FAIL_COND_V(above_count >= 4, 0);
@@ -127,23 +128,26 @@ Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir)
for (int i = 0; i < 3; i++) {
const Vector3 &v = p_face.vertex[i];
- if (plane.has_point(v)) //coplanar, don't bother
+ if (plane.has_point(v)) { //coplanar, don't bother
continue;
+ }
- if (plane.is_point_over(v))
+ if (plane.is_point_over(v)) {
over++;
- else
+ } else {
under++;
+ }
}
- if (over > 0 && under == 0)
+ if (over > 0 && under == 0) {
return SIDE_OVER;
- else if (under > 0 && over == 0)
+ } else if (under > 0 && over == 0) {
return SIDE_UNDER;
- else if (under == 0 && over == 0)
+ } else if (under == 0 && over == 0) {
return SIDE_COPLANAR;
- else
+ } else {
return SIDE_SPANNING;
+ }
}
Vector3 Face3::get_random_point_inside() const {
@@ -176,8 +180,9 @@ ClockDirection Face3::get_clock_dir() const {
bool Face3::intersects_aabb(const AABB &p_aabb) const {
/** TEST PLANE **/
- if (!p_aabb.intersects_plane(get_plane()))
+ if (!p_aabb.intersects_plane(get_plane())) {
return false;
+ }
#define TEST_AXIS(m_ax) \
/** TEST FACE AXIS */ \
@@ -218,16 +223,18 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const {
Vector3 axis = vec3_cross(e1, e2);
- if (axis.length_squared() < 0.0001)
+ if (axis.length_squared() < 0.0001) {
continue; // coplanar
+ }
axis.normalize();
real_t minA, maxA, minB, maxB;
p_aabb.project_range_in_plane(Plane(axis, 0), minA, maxA);
project_range(axis, Transform(), minB, maxB);
- if (maxA < minB || maxB < minA)
+ if (maxA < minB || maxB < minA) {
return false;
+ }
}
}
return true;
@@ -242,11 +249,13 @@ void Face3::project_range(const Vector3 &p_normal, const Transform &p_transform,
Vector3 v = p_transform.xform(vertex[i]);
real_t d = p_normal.dot(v);
- if (i == 0 || d > r_max)
+ if (i == 0 || d > r_max) {
r_max = d;
+ }
- if (i == 0 || d < r_min)
+ if (i == 0 || d < r_min) {
r_min = d;
+ }
}
}
@@ -254,8 +263,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V
#define _FACE_IS_VALID_SUPPORT_THRESHOLD 0.98
#define _EDGE_IS_VALID_SUPPORT_THRESHOLD 0.05
- if (p_max <= 0)
+ if (p_max <= 0) {
return;
+ }
Vector3 n = p_transform.basis.xform_inv(p_normal);
@@ -287,8 +297,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V
/** TEST EDGES AS SUPPORT **/
for (int i = 0; i < 3; i++) {
- if (i != vert_support_idx && i + 1 != vert_support_idx)
+ if (i != vert_support_idx && i + 1 != vert_support_idx) {
continue;
+ }
// check if edge is valid as a support
real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n);
@@ -296,8 +307,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V
if (dot < _EDGE_IS_VALID_SUPPORT_THRESHOLD) {
*p_count = MIN(2, p_max);
- for (int j = 0; j < *p_count; j++)
+ for (int j = 0; j < *p_count; j++) {
p_vertices[j] = p_transform.xform(vertex[(j + i) % 3]);
+ }
return;
}