diff options
author | Rodolfo Ribeiro Gomes <rodolforg@gmail.com> | 2019-03-11 01:31:13 -0300 |
---|---|---|
committer | Rodolfo Ribeiro Gomes <rodolforg@gmail.com> | 2019-04-26 20:10:32 -0300 |
commit | 9742d0c323a441036ee7753b85737aa8051714b3 (patch) | |
tree | 6071d0c2b833ccf6ca3affefe17f3dd6086c475d | |
parent | 91d3ea0d1f33af26328c741835a8ff72c58d34d7 (diff) | |
download | redot-engine-9742d0c323a441036ee7753b85737aa8051714b3.tar.gz |
Spatial::look_at() now preserves its scale values
It always normalized basis after look_at() computation.
Now it applies previous scale back, in order to avoid
distortions when global scale was different of (1,1,1).
fix #10003 and #19000
Related to #17924
-rw-r--r-- | scene/3d/spatial.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 83f99a2e3c..e9f9c9fc32 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -675,8 +675,7 @@ void Spatial::set_identity() { void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) { - Transform lookat; - lookat.origin = get_global_transform().origin; + Transform lookat(get_global_transform()); if (lookat.origin == p_target) { ERR_EXPLAIN("Node origin and target are in the same position, look_at() failed"); ERR_FAIL(); @@ -686,7 +685,10 @@ void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) { ERR_EXPLAIN("Up vector and direction between node origin and target are aligned, look_at() failed"); ERR_FAIL(); } + Vector3 original_scale(lookat.basis.get_scale()); lookat = lookat.looking_at(p_target, p_up); + // as basis was normalized, we just need to apply original scale back + lookat.basis.scale(original_scale); set_global_transform(lookat); } |