summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/aabb.cpp4
-rw-r--r--core/math/bsp_tree.cpp32
-rw-r--r--core/math/delaunay.h6
-rw-r--r--core/math/geometry.cpp22
-rw-r--r--core/math/geometry.h4
-rw-r--r--core/math/matrix3.cpp9
-rw-r--r--core/math/matrix3.h6
-rw-r--r--core/math/quick_hull.cpp8
-rw-r--r--core/math/transform.cpp9
-rw-r--r--core/math/triangulate.cpp6
10 files changed, 46 insertions, 60 deletions
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp
index cff19f990c..e2e71dda92 100644
--- a/core/math/aabb.cpp
+++ b/core/math/aabb.cpp
@@ -245,7 +245,6 @@ Vector3 AABB::get_longest_axis() const {
if (size.z > max_size) {
axis = Vector3(0, 0, 1);
- max_size = size.z;
}
return axis;
@@ -262,7 +261,6 @@ int AABB::get_longest_axis_index() const {
if (size.z > max_size) {
axis = 2;
- max_size = size.z;
}
return axis;
@@ -280,7 +278,6 @@ Vector3 AABB::get_shortest_axis() const {
if (size.z < max_size) {
axis = Vector3(0, 0, 1);
- max_size = size.z;
}
return axis;
@@ -297,7 +294,6 @@ int AABB::get_shortest_axis_index() const {
if (size.z < max_size) {
axis = 2;
- max_size = size.z;
}
return axis;
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index b1424e1d78..24096de551 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -244,10 +244,8 @@ bool BSP_Tree::point_is_inside(const Vector3 &p_point) const {
const Node *nodesptr = &nodes[0];
const Plane *planesptr = &planes[0];
- int plane_count = planes.size();
int idx = node_count - 1;
- int steps = 0;
while (true) {
@@ -259,21 +257,19 @@ bool BSP_Tree::point_is_inside(const Vector3 &p_point) const {
return true;
}
- uint16_t plane = nodesptr[idx].plane;
#ifdef DEBUG_ENABLED
-
+ int plane_count = planes.size();
+ uint16_t plane = nodesptr[idx].plane;
ERR_FAIL_INDEX_V(plane, plane_count, false);
#endif
+
bool over = planesptr[nodesptr[idx].plane].is_point_over(p_point);
idx = over ? nodes[idx].over : nodes[idx].under;
#ifdef DEBUG_ENABLED
-
ERR_FAIL_COND_V(idx < MAX_NODES && idx >= node_count, false);
#endif
-
- steps++;
}
return false;
@@ -453,10 +449,10 @@ BSP_Tree::operator Variant() const {
for (int i = 0; i < planes.size(); i++) {
- plane_values[i * 4 + 0] = planes[i].normal.x;
- plane_values[i * 4 + 1] = planes[i].normal.y;
- plane_values[i * 4 + 2] = planes[i].normal.z;
- plane_values[i * 4 + 3] = planes[i].d;
+ plane_values.write[i * 4 + 0] = planes[i].normal.x;
+ plane_values.write[i * 4 + 1] = planes[i].normal.y;
+ plane_values.write[i * 4 + 2] = planes[i].normal.z;
+ plane_values.write[i * 4 + 3] = planes[i].d;
}
d["planes"] = plane_values;
@@ -502,10 +498,10 @@ BSP_Tree::BSP_Tree(const Variant &p_variant) {
PoolVector<real_t>::Read r = src_planes.read();
for (int i = 0; i < plane_count / 4; i++) {
- planes[i].normal.x = r[i * 4 + 0];
- planes[i].normal.y = r[i * 4 + 1];
- planes[i].normal.z = r[i * 4 + 2];
- planes[i].d = r[i * 4 + 3];
+ planes.write[i].normal.x = r[i * 4 + 0];
+ planes.write[i].normal.y = r[i * 4 + 1];
+ planes.write[i].normal.z = r[i * 4 + 2];
+ planes.write[i].d = r[i * 4 + 3];
}
}
@@ -524,9 +520,9 @@ BSP_Tree::BSP_Tree(const Variant &p_variant) {
for (int i = 0; i < nodes.size(); i++) {
- nodes[i].over = r[i * 3 + 0];
- nodes[i].under = r[i * 3 + 1];
- nodes[i].plane = r[i * 3 + 2];
+ nodes.write[i].over = r[i * 3 + 0];
+ nodes.write[i].under = r[i * 3 + 1];
+ nodes.write[i].plane = r[i * 3 + 2];
}
}
diff --git a/core/math/delaunay.h b/core/math/delaunay.h
index 09aebc773f..13fbc0c6ae 100644
--- a/core/math/delaunay.h
+++ b/core/math/delaunay.h
@@ -92,7 +92,7 @@ public:
for (int j = 0; j < triangles.size(); j++) {
if (circum_circle_contains(points, triangles[j], i)) {
- triangles[j].bad = true;
+ triangles.write[j].bad = true;
polygon.push_back(Edge(triangles[j].points[0], triangles[j].points[1]));
polygon.push_back(Edge(triangles[j].points[1], triangles[j].points[2]));
polygon.push_back(Edge(triangles[j].points[2], triangles[j].points[0]));
@@ -109,8 +109,8 @@ public:
for (int j = 0; j < polygon.size(); j++) {
for (int k = j + 1; k < polygon.size(); k++) {
if (edge_compare(points, polygon[j], polygon[k])) {
- polygon[j].bad = true;
- polygon[k].bad = true;
+ polygon.write[j].bad = true;
+ polygon.write[k].bad = true;
}
}
}
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index 24f077a4ca..7ab28daf20 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -56,7 +56,7 @@ void Geometry::MeshData::optimize_vertices() {
vtx_remap[idx] = ni;
}
- faces[i].indices[j] = vtx_remap[idx];
+ faces.write[i].indices.write[j] = vtx_remap[idx];
}
}
@@ -74,8 +74,8 @@ void Geometry::MeshData::optimize_vertices() {
vtx_remap[b] = ni;
}
- edges[i].a = vtx_remap[a];
- edges[i].b = vtx_remap[b];
+ edges.write[i].a = vtx_remap[a];
+ edges.write[i].b = vtx_remap[b];
}
Vector<Vector3> new_vertices;
@@ -84,7 +84,7 @@ void Geometry::MeshData::optimize_vertices() {
for (int i = 0; i < vertices.size(); i++) {
if (vtx_remap.has(i))
- new_vertices[vtx_remap[i]] = vertices[i];
+ new_vertices.write[vtx_remap[i]] = vertices[i];
}
vertices = new_vertices;
}
@@ -1014,8 +1014,8 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
Vector<_AtlasWorkRect> wrects;
wrects.resize(p_rects.size());
for (int i = 0; i < p_rects.size(); i++) {
- wrects[i].s = p_rects[i];
- wrects[i].idx = i;
+ wrects.write[i].s = p_rects[i];
+ wrects.write[i].idx = i;
}
wrects.sort();
int widest = wrects[0].s.width;
@@ -1033,7 +1033,7 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
Vector<int> hmax;
hmax.resize(w);
for (int j = 0; j < w; j++)
- hmax[j] = 0;
+ hmax.write[j] = 0;
//place them
int ofs = 0;
@@ -1052,8 +1052,8 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
from_y = hmax[ofs + k];
}
- wrects[j].p.x = ofs;
- wrects[j].p.y = from_y;
+ wrects.write[j].p.x = ofs;
+ wrects.write[j].p.y = from_y;
int end_h = from_y + wrects[j].s.height;
int end_w = ofs + wrects[j].s.width;
if (ofs == 0)
@@ -1061,7 +1061,7 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
for (int k = 0; k < wrects[j].s.width; k++) {
- hmax[ofs + k] = end_h;
+ hmax.write[ofs + k] = end_h;
}
if (end_h > max_h)
@@ -1101,7 +1101,7 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
for (int i = 0; i < p_rects.size(); i++) {
- r_result[results[best].result[i].idx] = results[best].result[i].p;
+ r_result.write[results[best].result[i].idx] = results[best].result[i].p;
}
r_size = Size2(results[best].max_w, results[best].max_h);
diff --git a/core/math/geometry.h b/core/math/geometry.h
index be998aef0b..186a05fb37 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -890,14 +890,14 @@ public:
for (int i = 0; i < n; ++i) {
while (k >= 2 && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0)
k--;
- H[k++] = P[i];
+ H.write[k++] = P[i];
}
// Build upper hull
for (int i = n - 2, t = k + 1; i >= 0; i--) {
while (k >= t && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0)
k--;
- H[k++] = P[i];
+ H.write[k++] = P[i];
}
H.resize(k);
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index 2371f49561..7db41756ed 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -242,18 +242,11 @@ void Basis::scale_local(const Vector3 &p_scale) {
Basis Basis::scaled_local(const Vector3 &p_scale) const {
Basis b;
- b.set_scale(p_scale);
+ b.set_diagonal(p_scale);
return (*this) * b;
}
-void Basis::set_scale(const Vector3 &p_scale) {
-
- set_axis(0, get_axis(0).normalized() * p_scale.x);
- set_axis(1, get_axis(1).normalized() * p_scale.y);
- set_axis(2, get_axis(2).normalized() * p_scale.z);
-}
-
Vector3 Basis::get_scale_abs() const {
return Vector3(
diff --git a/core/math/matrix3.h b/core/math/matrix3.h
index cd1b51baa6..9ff1a97dc9 100644
--- a/core/math/matrix3.h
+++ b/core/math/matrix3.h
@@ -112,7 +112,6 @@ public:
void scale_local(const Vector3 &p_scale);
Basis scaled_local(const Vector3 &p_scale) const;
- void set_scale(const Vector3 &p_scale);
Vector3 get_scale() const;
Vector3 get_scale_abs() const;
Vector3 get_scale_local() const;
@@ -232,10 +231,13 @@ public:
operator Quat() const { return get_quat(); }
Basis(const Quat &p_quat) { set_quat(p_quat); };
+ Basis(const Quat &p_quat, const Vector3 &p_scale) { set_quat_scale(p_quat, p_scale); }
+
Basis(const Vector3 &p_euler) { set_euler(p_euler); }
+ Basis(const Vector3 &p_euler, const Vector3 &p_scale) { set_euler_scale(p_euler, p_scale); }
+
Basis(const Vector3 &p_axis, real_t p_phi) { set_axis_angle(p_axis, p_phi); }
Basis(const Vector3 &p_axis, real_t p_phi, const Vector3 &p_scale) { set_axis_angle_scale(p_axis, p_phi, p_scale); }
- Basis(const Quat &p_quat, const Vector3 &p_scale) { set_quat_scale(p_quat, p_scale); }
_FORCE_INLINE_ Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) {
elements[0] = row0;
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index fc90417413..cb923d264e 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -61,10 +61,10 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Vector3 sp = p_points[i].snapped(Vector3(0.0001, 0.0001, 0.0001));
if (valid_cache.has(sp)) {
- valid_points[i] = false;
+ valid_points.write[i] = false;
//print_line("INVALIDATED: "+itos(i));
} else {
- valid_points[i] = true;
+ valid_points.write[i] = true;
valid_cache.insert(sp);
}
}
@@ -452,7 +452,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
int idx = 0;
for (List<Geometry::MeshData::Face>::Element *E = ret_faces.front(); E; E = E->next()) {
- r_mesh.faces[idx++] = E->get();
+ r_mesh.faces.write[idx++] = E->get();
}
r_mesh.edges.resize(ret_edges.size());
idx = 0;
@@ -461,7 +461,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Geometry::MeshData::Edge e;
e.a = E->key().vertices[0];
e.b = E->key().vertices[1];
- r_mesh.edges[idx++] = e;
+ r_mesh.edges.write[idx++] = e;
}
r_mesh.vertices = p_points;
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index d1e190f4b9..976e0f174e 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -127,12 +127,11 @@ Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c)
Quat dst_rot = p_transform.basis.get_rotation_quat();
Vector3 dst_loc = p_transform.origin;
- Transform dst; //this could be made faster by using a single function in Basis..
- dst.basis = src_rot.slerp(dst_rot, p_c).normalized();
- dst.basis.set_scale(src_scale.linear_interpolate(dst_scale, p_c));
- dst.origin = src_loc.linear_interpolate(dst_loc, p_c);
+ Transform interp;
+ interp.basis.set_quat_scale(src_rot.slerp(dst_rot, p_c).normalized(), src_scale.linear_interpolate(dst_scale, p_c));
+ interp.origin = src_loc.linear_interpolate(dst_loc, p_c);
- return dst;
+ return interp;
}
void Transform::scale(const Vector3 &p_scale) {
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index 563ba7268f..0edc0ea039 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -128,10 +128,10 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
if (0.0 < get_area(contour))
for (int v = 0; v < n; v++)
- V[v] = v;
+ V.write[v] = v;
else
for (int v = 0; v < n; v++)
- V[v] = (n - 1) - v;
+ V.write[v] = (n - 1) - v;
bool relaxed = false;
@@ -182,7 +182,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
/* remove v from remaining polygon */
for (s = v, t = v + 1; t < nv; s++, t++)
- V[s] = V[t];
+ V.write[s] = V[t];
nv--;