diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/io/resource.cpp | 36 | ||||
-rw-r--r-- | core/math/transform_2d.cpp | 39 |
2 files changed, 34 insertions, 41 deletions
diff --git a/core/io/resource.cpp b/core/io/resource.cpp index e44bbc246b..4abcbffb61 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -260,15 +260,35 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const { } Variant p = get(E.name); - if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) { - r->set(E.name, p.duplicate(p_subresources)); - } else if (p.get_type() == Variant::OBJECT && !(E.usage & PROPERTY_USAGE_NEVER_DUPLICATE) && (p_subresources || (E.usage & PROPERTY_USAGE_ALWAYS_DUPLICATE))) { - Ref<Resource> sr = p; - if (sr.is_valid()) { - r->set(E.name, sr->duplicate(p_subresources)); + switch (p.get_type()) { + case Variant::Type::DICTIONARY: + case Variant::Type::ARRAY: + case Variant::Type::PACKED_BYTE_ARRAY: + case Variant::Type::PACKED_COLOR_ARRAY: + case Variant::Type::PACKED_INT32_ARRAY: + case Variant::Type::PACKED_INT64_ARRAY: + case Variant::Type::PACKED_FLOAT32_ARRAY: + case Variant::Type::PACKED_FLOAT64_ARRAY: + case Variant::Type::PACKED_STRING_ARRAY: + case Variant::Type::PACKED_VECTOR2_ARRAY: + case Variant::Type::PACKED_VECTOR3_ARRAY: { + r->set(E.name, p.duplicate(p_subresources)); + } break; + + case Variant::Type::OBJECT: { + if (!(E.usage & PROPERTY_USAGE_NEVER_DUPLICATE) && (p_subresources || (E.usage & PROPERTY_USAGE_ALWAYS_DUPLICATE))) { + Ref<Resource> sr = p; + if (sr.is_valid()) { + r->set(E.name, sr->duplicate(p_subresources)); + } + } else { + r->set(E.name, p); + } + } break; + + default: { + r->set(E.name, p); } - } else { - r->set(E.name, p); } } diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 910995d717..96010b4096 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -263,39 +263,12 @@ real_t Transform2D::basis_determinant() const { return columns[0].x * columns[1].y - columns[0].y * columns[1].x; } -Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, const real_t p_c) const { - //extract parameters - Vector2 p1 = get_origin(); - Vector2 p2 = p_transform.get_origin(); - - real_t r1 = get_rotation(); - real_t r2 = p_transform.get_rotation(); - - Size2 s1 = get_scale(); - Size2 s2 = p_transform.get_scale(); - - //slerp rotation - Vector2 v1(Math::cos(r1), Math::sin(r1)); - Vector2 v2(Math::cos(r2), Math::sin(r2)); - - real_t dot = v1.dot(v2); - - dot = CLAMP(dot, (real_t)-1.0, (real_t)1.0); - - Vector2 v; - - if (dot > 0.9995f) { - v = v1.lerp(v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues - } else { - real_t angle = p_c * Math::acos(dot); - Vector2 v3 = (v2 - v1 * dot).normalized(); - v = v1 * Math::cos(angle) + v3 * Math::sin(angle); - } - - //construct matrix - Transform2D res(v.angle(), p1.lerp(p2, p_c)); - res.scale_basis(s1.lerp(s2, p_c)); - return res; +Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, const real_t p_weight) const { + return Transform2D( + Math::lerp_angle(get_rotation(), p_transform.get_rotation(), p_weight), + get_scale().lerp(p_transform.get_scale(), p_weight), + Math::lerp_angle(get_skew(), p_transform.get_skew(), p_weight), + get_origin().lerp(p_transform.get_origin(), p_weight)); } void Transform2D::operator*=(const real_t p_val) { |