summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorRodolfo Ribeiro Gomes <rodolforg@gmail.com>2019-05-23 09:49:50 -0300
committerRodolfo Ribeiro Gomes <rodolforg@gmail.com>2019-05-23 09:49:50 -0300
commit48e4d62554d9bd3b1f8cae9e82f21b2f7519545d (patch)
treeebca4f00a9b66bb8f5354e57ab49f4909ae02406 /scene/3d
parent9742d0c323a441036ee7753b85737aa8051714b3 (diff)
fix un-scaling in Spatial::look_at_from_position
As mentioned in https://github.com/godotengine/godot/pull/26897#issuecomment-491178089 the look-at scaling issue solved by PR #26897 happens also in another look-at method. Spatial::look_at_from_position() also does not have same input checking Spatial::look_at() has. Therefore, I fixed it too at same time.
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/spatial.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp
index e9f9c9fc32..3fa4e1e64b 100644
--- a/scene/3d/spatial.cpp
+++ b/scene/3d/spatial.cpp
@@ -675,28 +675,29 @@ void Spatial::set_identity() {
void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) {
- Transform lookat(get_global_transform());
- if (lookat.origin == p_target) {
+ Vector3 origin(get_global_transform().origin);
+ look_at_from_position(origin, p_target, p_up);
+}
+
+void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) {
+
+ if (p_pos == p_target) {
ERR_EXPLAIN("Node origin and target are in the same position, look_at() failed");
ERR_FAIL();
}
- if (p_up.cross(p_target - lookat.origin) == Vector3()) {
+ if (p_up.cross(p_target - p_pos) == Vector3()) {
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);
-}
-
-void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) {
Transform lookat;
lookat.origin = p_pos;
+
+ Vector3 original_scale(get_global_transform().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);
}