summaryrefslogtreecommitdiffstats
path: root/core/math/basis.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2023-04-15 10:01:43 +0200
committerSilc Lizard (Tokage) Renew <61938263+TokageItLab@users.noreply.github.com>2023-05-24 10:10:24 +0900
commit5fdc1232eff45e31ee53f58e618de6c58d3f7203 (patch)
treeff8e6d4a7a3557d4d42c78294425c2604d35fd17 /core/math/basis.cpp
parentd5c1b9f883adbb54900c145eafcaa789d0fd563c (diff)
downloadredot-engine-5fdc1232eff45e31ee53f58e618de6c58d3f7203.tar.gz
Add the ability to look-at in model-space.
This is a much simpler attempt to solve the same problem as #76060, but without breaking any compatibility. * Adds a description of what model space is in the Vector3 enums (MODEL_* constants). This has the proper axes laid out for imported 3D assets. * Adds the option to `look_at` using model_space, which uses Vector3.MODEL_FRONT as forward vector. The attempt of this PR is to still break the assumption that there is a single direction of forward (which is not the case in Godot) and make it easier to understand where 3D models are facing, as well as orienting them via look_at.
Diffstat (limited to 'core/math/basis.cpp')
-rw-r--r--core/math/basis.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index bfd902c7e2..1481dbc32e 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -1016,12 +1016,15 @@ void Basis::rotate_sh(real_t *p_values) {
p_values[8] = d4 * s_scale_dst4;
}
-Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up) {
+Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up, bool p_use_model_front) {
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(p_target.is_zero_approx(), Basis(), "The target vector can't be zero.");
ERR_FAIL_COND_V_MSG(p_up.is_zero_approx(), Basis(), "The up vector can't be zero.");
#endif
- Vector3 v_z = -p_target.normalized();
+ Vector3 v_z = p_target.normalized();
+ if (!p_use_model_front) {
+ v_z = -v_z;
+ }
Vector3 v_x = p_up.cross(v_z);
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(v_x.is_zero_approx(), Basis(), "The target vector and up vector can't be parallel to each other.");