diff options
author | Silc Renew <tokage.it.lab@gmail.com> | 2022-06-20 16:54:28 +0900 |
---|---|---|
committer | Silc Renew <tokage.it.lab@gmail.com> | 2022-06-23 16:55:16 +0900 |
commit | 51c884f7acd276e86bb43a6f5856c3401c02adfe (patch) | |
tree | d58943312ef9b3102de5cd4326e4e43e117d9f97 /scene/3d/node_3d.cpp | |
parent | 747ff071cd68f3411b49f8af5590575aaf9f7218 (diff) |
fix method when rotation_mode changed
Diffstat (limited to 'scene/3d/node_3d.cpp')
-rw-r--r-- | scene/3d/node_3d.cpp | 70 |
1 files changed, 49 insertions, 21 deletions
diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index 6e36815f2b..78d53439e8 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -85,10 +85,13 @@ void Node3D::_notify_dirty() { } void Node3D::_update_local_transform() const { - if (this->get_rotation_edit_mode() != ROTATION_EDIT_MODE_BASIS) { - data.local_transform = data.local_transform.orthogonalized(); + if (this->get_rotation_edit_mode() == ROTATION_EDIT_MODE_EULER) { + data.local_transform.basis.set_euler(data.rotation, data.rotation_order); + data.local_transform.basis.scale_local(data.scale); + } else if (this->get_rotation_edit_mode() == ROTATION_EDIT_MODE_QUATERNION) { + data.local_transform.basis = Basis(data.quaternion); + data.local_transform.basis.scale_local(data.scale); } - data.local_transform.basis.set_euler_scale(data.rotation, data.scale); data.dirty &= ~DIRTY_LOCAL; } @@ -212,7 +215,18 @@ void Node3D::set_basis(const Basis &p_basis) { set_transform(Transform3D(p_basis, data.local_transform.origin)); } void Node3D::set_quaternion(const Quaternion &p_quaternion) { - set_transform(Transform3D(Basis(p_quaternion), data.local_transform.origin)); + if (data.dirty & DIRTY_VECTORS) { + data.rotation = get_transform().basis.get_euler_normalized(data.rotation_order); + data.scale = get_transform().basis.get_scale(); + data.dirty &= ~DIRTY_VECTORS; + } + + data.quaternion = p_quaternion; + data.dirty |= DIRTY_LOCAL; + _propagate_transform_changed(this); + if (data.notify_local_transform) { + notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); + } } void Node3D::set_transform(const Transform3D &p_transform) { @@ -228,7 +242,14 @@ Basis Node3D::get_basis() const { return get_transform().basis; } Quaternion Node3D::get_quaternion() const { - return Quaternion(get_transform().basis); + if (data.dirty & DIRTY_VECTORS) { + data.quaternion = get_transform().basis.get_rotation_quaternion(); + data.rotation = get_transform().basis.get_euler_normalized(data.rotation_order); + data.scale = get_transform().basis.get_scale(); + data.dirty &= ~DIRTY_VECTORS; + } + + return data.quaternion; } void Node3D::set_global_transform(const Transform3D &p_transform) { @@ -255,9 +276,9 @@ Transform3D Node3D::get_global_transform() const { } if (data.parent && !data.top_level_active) { - data.global_transform = data.parent->get_global_transform() * data.local_transform; + data.global_transform = data.parent->get_global_transform() * get_transform(); } else { - data.global_transform = data.local_transform; + data.global_transform = get_transform(); } if (data.disable_scale) { @@ -303,7 +324,7 @@ Transform3D Node3D::get_relative_transform(const Node *p_parent) const { } void Node3D::set_position(const Vector3 &p_position) { - data.local_transform.origin = p_position; + get_transform().origin = p_position; _propagate_transform_changed(this); if (data.notify_local_transform) { notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); @@ -314,9 +335,13 @@ void Node3D::set_rotation_edit_mode(RotationEditMode p_mode) { if (data.rotation_edit_mode == p_mode) { return; } + + data.quaternion = get_transform().basis.get_rotation_quaternion(); + data.rotation = get_transform().basis.get_euler_normalized(data.rotation_order); + data.scale = get_transform().basis.get_scale(); data.rotation_edit_mode = p_mode; - // Shearing is not allowed except in ROTATION_EDIT_MODE_BASIS. + // Shearing is not allowed except in ROTATION_EDIT_MODE_BASIS, so validate local_transform. data.dirty |= DIRTY_LOCAL; _propagate_transform_changed(this); if (data.notify_local_transform) { @@ -340,8 +365,9 @@ void Node3D::set_rotation_order(RotationOrder p_order) { ERR_FAIL_INDEX(int32_t(order), 6); if (data.dirty & DIRTY_VECTORS) { - data.rotation = data.local_transform.basis.get_euler_normalized(order); - data.scale = data.local_transform.basis.get_scale(); + data.quaternion = get_transform().basis.get_rotation_quaternion(); + data.rotation = get_transform().basis.get_euler_normalized(order); + data.scale = get_transform().basis.get_scale(); data.dirty &= ~DIRTY_VECTORS; } else { data.rotation = Basis::from_euler(data.rotation, data.rotation_order).get_euler_normalized(order); @@ -359,7 +385,8 @@ Node3D::RotationOrder Node3D::get_rotation_order() const { void Node3D::set_rotation(const Vector3 &p_euler_rad) { if (data.dirty & DIRTY_VECTORS) { - data.scale = data.local_transform.basis.get_scale(); + data.quaternion = get_transform().basis.get_rotation_quaternion(); + data.scale = get_transform().basis.get_scale(); data.dirty &= ~DIRTY_VECTORS; } @@ -373,7 +400,8 @@ void Node3D::set_rotation(const Vector3 &p_euler_rad) { void Node3D::set_scale(const Vector3 &p_scale) { if (data.dirty & DIRTY_VECTORS) { - data.rotation = data.local_transform.basis.get_euler_normalized(data.rotation_order); + data.quaternion = get_transform().basis.get_rotation_quaternion(); + data.rotation = get_transform().basis.get_euler_normalized(data.rotation_order); data.dirty &= ~DIRTY_VECTORS; } @@ -386,14 +414,14 @@ void Node3D::set_scale(const Vector3 &p_scale) { } Vector3 Node3D::get_position() const { - return data.local_transform.origin; + return get_transform().origin; } Vector3 Node3D::get_rotation() const { if (data.dirty & DIRTY_VECTORS) { - data.scale = data.local_transform.basis.get_scale(); - data.rotation = data.local_transform.basis.get_euler_normalized(data.rotation_order); - + data.quaternion = get_transform().basis.get_rotation_quaternion(); + data.rotation = get_transform().basis.get_euler_normalized(data.rotation_order); + data.scale = get_transform().basis.get_scale(); data.dirty &= ~DIRTY_VECTORS; } @@ -402,9 +430,9 @@ Vector3 Node3D::get_rotation() const { Vector3 Node3D::get_scale() const { if (data.dirty & DIRTY_VECTORS) { - data.scale = data.local_transform.basis.get_scale(); - data.rotation = data.local_transform.basis.get_euler_normalized(data.rotation_order); - + data.quaternion = get_transform().basis.get_rotation_quaternion(); + data.rotation = get_transform().basis.get_euler_normalized(data.rotation_order); + data.scale = get_transform().basis.get_scale(); data.dirty &= ~DIRTY_VECTORS; } @@ -865,7 +893,7 @@ Variant Node3D::property_get_revert(const String &p_name) { } else if (p_name == "quaternion") { Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) { - r_ret = Quaternion(Transform3D(variant).get_basis()); + r_ret = Transform3D(variant).get_basis().get_rotation_quaternion(); } else { return Quaternion(); } |