diff options
| author | Rémi Verschelde <remi@verschelde.fr> | 2021-08-10 11:28:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-10 11:28:12 +0200 |
| commit | 16d73fefdb0286f58b9cba86faeaf9155484d94b (patch) | |
| tree | c675943a2083cbde012e459f785c8c0c44e09392 /core/math/basis.cpp | |
| parent | 8b960a2d2b456b98efabd736e4db776580a5f846 (diff) | |
| parent | 9f3ae0adcd734a16c299cd0f023212478b3960d3 (diff) | |
| download | redot-engine-16d73fefdb0286f58b9cba86faeaf9155484d94b.tar.gz | |
Merge pull request #50682 from aaronfranke/basis-looking-at
Move code for looking_at to Basis
Diffstat (limited to 'core/math/basis.cpp')
| -rw-r--r-- | core/math/basis.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/core/math/basis.cpp b/core/math/basis.cpp index aa3831d4cf..b5e25fb837 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -1129,3 +1129,21 @@ void Basis::rotate_sh(real_t *p_values) { p_values[7] = -d3; p_values[8] = d4 * s_scale_dst4; } + +Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up) { +#ifdef MATH_CHECKS + ERR_FAIL_COND_V_MSG(p_target.is_equal_approx(Vector3()), Basis(), "The target vector can't be zero."); + ERR_FAIL_COND_V_MSG(p_up.is_equal_approx(Vector3()), Basis(), "The up vector can't be zero."); +#endif + Vector3 v_z = -p_target.normalized(); + Vector3 v_x = p_up.cross(v_z); +#ifdef MATH_CHECKS + ERR_FAIL_COND_V_MSG(v_x.is_equal_approx(Vector3()), Basis(), "The target vector and up vector can't be parallel to each other."); +#endif + v_x.normalize(); + Vector3 v_y = v_z.cross(v_x); + + Basis basis; + basis.set(v_x, v_y, v_z); + return basis; +} |
