diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 23:09:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-14 23:09:03 +0200 |
| commit | 00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8 (patch) | |
| tree | 2b1c31f45add24085b64425ce440f577424c16a1 /core/math/camera_matrix.cpp | |
| parent | 5046f666a1181675b39f156c38346525dc1c444e (diff) | |
| parent | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (diff) | |
| download | redot-engine-00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8.tar.gz | |
Merge pull request #38738 from akien-mga/cause-we-never-go-out-of-style
Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks
Diffstat (limited to 'core/math/camera_matrix.cpp')
| -rw-r--r-- | core/math/camera_matrix.cpp | 56 |
1 files changed, 15 insertions, 41 deletions
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 5d3ebc9f6d..81c602d8fe 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -34,7 +34,6 @@ #include "core/print_string.h" float CameraMatrix::determinant() const { - return matrix[0][3] * matrix[1][2] * matrix[2][1] * matrix[3][0] - matrix[0][2] * matrix[1][3] * matrix[2][1] * matrix[3][0] - matrix[0][3] * matrix[1][1] * matrix[2][2] * matrix[3][0] + matrix[0][1] * matrix[1][3] * matrix[2][2] * matrix[3][0] + matrix[0][2] * matrix[1][1] * matrix[2][3] * matrix[3][0] - matrix[0][1] * matrix[1][2] * matrix[2][3] * matrix[3][0] - @@ -50,29 +49,22 @@ float CameraMatrix::determinant() const { } void CameraMatrix::set_identity() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - matrix[i][j] = (i == j) ? 1 : 0; } } } void CameraMatrix::set_zero() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - matrix[i][j] = 0; } } } Plane CameraMatrix::xform4(const Plane &p_vec4) const { - Plane ret; ret.normal.x = matrix[0][0] * p_vec4.normal.x + matrix[1][0] * p_vec4.normal.y + matrix[2][0] * p_vec4.normal.z + matrix[3][0] * p_vec4.d; @@ -83,7 +75,6 @@ Plane CameraMatrix::xform4(const Plane &p_vec4) const { } void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) { - if (p_flip_fov) { p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect); } @@ -176,7 +167,6 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_ }; void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) { - set_identity(); matrix[0][0] = 2.0 / (p_right - p_left); @@ -189,7 +179,6 @@ void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom } void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) { - if (!p_flip_fov) { p_size *= p_aspect; } @@ -198,7 +187,6 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear } void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) { - ERR_FAIL_COND(p_right <= p_left); ERR_FAIL_COND(p_top <= p_bottom); ERR_FAIL_COND(p_far <= p_near); @@ -239,7 +227,6 @@ void CameraMatrix::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, } real_t CameraMatrix::get_z_far() const { - const real_t *matrix = (const real_t *)this->matrix; Plane new_plane = Plane(matrix[3] - matrix[2], matrix[7] - matrix[6], @@ -251,8 +238,8 @@ real_t CameraMatrix::get_z_far() const { return new_plane.d; } -real_t CameraMatrix::get_z_near() const { +real_t CameraMatrix::get_z_near() const { const real_t *matrix = (const real_t *)this->matrix; Plane new_plane = Plane(matrix[3] + matrix[2], matrix[7] + matrix[6], @@ -264,7 +251,6 @@ real_t CameraMatrix::get_z_near() const { } Vector2 CameraMatrix::get_viewport_half_extents() const { - const real_t *matrix = (const real_t *)this->matrix; ///////--- Near Plane ---/////// Plane near_plane = Plane(matrix[3] + matrix[2], @@ -293,7 +279,6 @@ Vector2 CameraMatrix::get_viewport_half_extents() const { } 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], @@ -323,7 +308,6 @@ void CameraMatrix::get_far_plane_size(real_t &r_width, real_t &r_height) const { } bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const { - Vector<Plane> planes = get_projection_planes(Transform()); const Planes intersections[8][3] = { { PLANE_FAR, PLANE_LEFT, PLANE_TOP }, @@ -337,7 +321,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point }; for (int i = 0; i < 8; i++) { - Vector3 point; bool res = planes[intersections[i][0]].intersect_3(planes[intersections[i][1]], planes[intersections[i][2]], &point); ERR_FAIL_COND_V(!res, false); @@ -348,7 +331,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point } Vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform) const { - /** Fast Plane Extraction from combined modelview/projection matrices. * References: * https://web.archive.org/web/20011221205252/http://www.markmorley.com/opengl/frustumculling.html @@ -431,14 +413,12 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform) } CameraMatrix CameraMatrix::inverse() const { - CameraMatrix cm = *this; cm.invert(); return cm; } void CameraMatrix::invert() { - int i, j, k; int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */ real_t pvt_val; /* Value of current pivot element */ @@ -489,23 +469,26 @@ void CameraMatrix::invert() { /** Divide column by minus pivot value **/ for (i = 0; i < 4; i++) { - if (i != k) + if (i != k) { matrix[i][k] /= (-pvt_val); + } } /** Reduce the matrix **/ for (i = 0; i < 4; i++) { hold = matrix[i][k]; for (j = 0; j < 4; j++) { - if (i != k && j != k) + if (i != k && j != k) { matrix[i][j] += hold * matrix[k][j]; + } } } /** Divide row by pivot **/ for (j = 0; j < 4; j++) { - if (j != k) + if (j != k) { matrix[k][j] /= pvt_val; + } } /** Replace pivot by reciprocal (at last we can touch it). **/ @@ -525,12 +508,13 @@ void CameraMatrix::invert() { } j = pvt_i[k]; /* Columns to swap correspond to pivot ROW */ - if (j != k) /* If columns are different */ + if (j != k) { /* If columns are different */ for (i = 0; i < 4; i++) { hold = matrix[i][k]; matrix[i][k] = -matrix[i][j]; matrix[i][j] = hold; } + } } } @@ -541,19 +525,18 @@ void CameraMatrix::flip_y() { } CameraMatrix::CameraMatrix() { - set_identity(); } CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const { - CameraMatrix new_matrix; for (int j = 0; j < 4; j++) { for (int i = 0; i < 4; i++) { real_t ab = 0; - for (int k = 0; k < 4; k++) + for (int k = 0; k < 4; k++) { ab += matrix[k][i] * p_matrix.matrix[j][k]; + } new_matrix.matrix[j][i] = ab; } } @@ -562,7 +545,6 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const { } void CameraMatrix::set_depth_correction(bool p_flip_y) { - real_t *m = &matrix[0][0]; m[0] = 1; @@ -584,7 +566,6 @@ void CameraMatrix::set_depth_correction(bool p_flip_y) { } void CameraMatrix::set_light_bias() { - real_t *m = &matrix[0][0]; m[0] = 0.5; @@ -606,7 +587,6 @@ void CameraMatrix::set_light_bias() { } void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) { - real_t *m = &matrix[0][0]; m[0] = p_rect.size.width; @@ -628,30 +608,28 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) { } CameraMatrix::operator String() const { - String str; - for (int i = 0; i < 4; i++) - for (int j = 0; j < 4; j++) + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { str += String((j > 0) ? ", " : "\n") + rtos(matrix[i][j]); + } + } return str; } real_t CameraMatrix::get_aspect() const { - Vector2 vp_he = get_viewport_half_extents(); return vp_he.x / vp_he.y; } int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const { - Vector3 result = xform(Vector3(1, 0, -1)); return int((result.x * 0.5 + 0.5) * p_for_pixel_width); } bool CameraMatrix::is_orthogonal() const { - return matrix[3][3] == 1.0; } @@ -679,7 +657,6 @@ real_t CameraMatrix::get_fov() const { } void CameraMatrix::make_scale(const Vector3 &p_scale) { - set_identity(); matrix[0][0] = p_scale.x; matrix[1][1] = p_scale.y; @@ -687,7 +664,6 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) { } void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) { - Vector3 min = p_aabb.position; Vector3 max = p_aabb.position + p_aabb.size; @@ -713,7 +689,6 @@ void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) { } CameraMatrix::operator Transform() const { - Transform tr; const real_t *m = &matrix[0][0]; @@ -737,7 +712,6 @@ CameraMatrix::operator Transform() const { } CameraMatrix::CameraMatrix(const Transform &p_transform) { - const Transform &tr = p_transform; real_t *m = &matrix[0][0]; |
