summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2020-01-21 14:24:22 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-02-11 12:15:27 +0100
commitee1e89f8c0dc4659a2ed4b5afd5e7c1c596f7af1 (patch)
tree474fcea808580b5937b37d17f5feba741f8a0bb8 /core
parentf8b5c5f0631ac629c00795b5f3f8775c32a0368b (diff)
Modified rendering to use cluster instead of foward
Diffstat (limited to 'core')
-rw-r--r--core/math/basis.cpp12
-rw-r--r--core/math/basis.h3
-rw-r--r--core/math/camera_matrix.cpp30
-rw-r--r--core/math/camera_matrix.h16
4 files changed, 61 insertions, 0 deletions
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index ddf5f13d55..14079f811d 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -244,6 +244,18 @@ void Basis::scale_local(const Vector3 &p_scale) {
*this = scaled_local(p_scale);
}
+float Basis::get_uniform_scale() const {
+ return (elements[0].length() + elements[1].length() + elements[2].length()) / 3.0;
+}
+
+void Basis::make_scale_uniform() {
+ float l = (elements[0].length() + elements[1].length() + elements[2].length()) / 3.0;
+ for (int i = 0; i < 3; i++) {
+ elements[i].normalize();
+ elements[i] *= l;
+ }
+}
+
Basis Basis::scaled_local(const Vector3 &p_scale) const {
Basis b;
b.set_diagonal(p_scale);
diff --git a/core/math/basis.h b/core/math/basis.h
index 6c3a939d70..0261cf67c6 100644
--- a/core/math/basis.h
+++ b/core/math/basis.h
@@ -108,6 +108,9 @@ public:
void scale_local(const Vector3 &p_scale);
Basis scaled_local(const Vector3 &p_scale) const;
+ void make_scale_uniform();
+ float get_uniform_scale() const;
+
Vector3 get_scale() const;
Vector3 get_scale_abs() const;
Vector3 get_scale_local() const;
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 9e2d10c1f6..c4981b954b 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -276,6 +276,36 @@ Vector2 CameraMatrix::get_viewport_half_extents() const {
return Vector2(res.x, res.y);
}
+void CameraMatrix::get_far_plane_size(real_t &r_width, real_t &r_height) const {
+
+ const real_t *matrix = (const real_t *)this->matrix;
+ ///////--- Far Plane ---///////
+ Plane far_plane = Plane(matrix[3] - matrix[2],
+ matrix[7] - matrix[6],
+ matrix[11] - matrix[10],
+ -matrix[15] + matrix[14]);
+ far_plane.normalize();
+
+ ///////--- Right Plane ---///////
+ Plane right_plane = Plane(matrix[3] - matrix[0],
+ matrix[7] - matrix[4],
+ matrix[11] - matrix[8],
+ -matrix[15] + matrix[12]);
+ right_plane.normalize();
+
+ Plane top_plane = Plane(matrix[3] - matrix[1],
+ matrix[7] - matrix[5],
+ matrix[11] - matrix[9],
+ -matrix[15] + matrix[13]);
+ top_plane.normalize();
+
+ Vector3 res;
+ far_plane.intersect_3(right_plane, top_plane, &res);
+
+ r_width = res.x;
+ r_height = res.y;
+}
+
bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const {
Vector<Plane> planes = get_projection_planes(Transform());
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index b5c75ca562..60f7d15974 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -75,6 +75,7 @@ struct CameraMatrix {
bool get_endpoints(const Transform &p_transform, Vector3 *p_8points) const;
Vector2 get_viewport_half_extents() const;
+ void get_far_plane_size(real_t &r_width, real_t &r_height) const;
void invert();
CameraMatrix inverse() const;
@@ -93,6 +94,21 @@ struct CameraMatrix {
void flip_y();
+ bool operator==(const CameraMatrix &p_cam) const {
+ for (uint32_t i = 0; i < 4; i++) {
+ for (uint32_t j = 0; j < 4; j++) {
+ if (matrix[i][j] != p_cam.matrix[i][j]) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ bool operator!=(const CameraMatrix &p_cam) const {
+ return !(*this == p_cam);
+ }
+
CameraMatrix();
CameraMatrix(const Transform &p_transform);
~CameraMatrix();