From aa5ade834c8646b81e2320089314393c00ee8020 Mon Sep 17 00:00:00 2001 From: anneomcl Date: Mon, 19 Sep 2016 21:36:24 -0700 Subject: [PATCH] Fix for #6158. Converting Vector2 to Size2 for scaling functions. --- core/math/math_2d.cpp | 22 ++++++++-------------- core/math/math_2d.h | 15 +++++---------- scene/2d/node_2d.cpp | 2 +- scene/2d/node_2d.h | 4 +--- scene/2d/polygon_2d.cpp | 4 ++-- scene/2d/polygon_2d.h | 6 +++--- scene/main/canvas_layer.h | 6 +++--- servers/physics_2d/shape_2d_sw.cpp | 14 +++++++------- servers/physics_2d/shape_2d_sw.h | 18 +++++++++--------- 9 files changed, 39 insertions(+), 52 deletions(-) diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 0e2060008c5..2cc11aa7387 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -475,18 +475,18 @@ Matrix32::Matrix32(real_t p_rot, const Vector2& p_pos) { elements[2]=p_pos; } -Vector2 Matrix32::get_scale() const { +Size2 Matrix32::get_scale() const { - return Vector2( elements[0].length(), elements[1].length() ); + return Size2( elements[0].length(), elements[1].length() ); } -void Matrix32::scale(const Vector2& p_scale) { +void Matrix32::scale(const Size2& p_scale) { elements[0]*=p_scale; elements[1]*=p_scale; elements[2]*=p_scale; } -void Matrix32::scale_basis(const Vector2& p_scale) { +void Matrix32::scale_basis(const Size2& p_scale) { elements[0]*=p_scale; elements[1]*=p_scale; @@ -501,7 +501,6 @@ void Matrix32::translate( const Vector2& p_translation ) { elements[2]+=basis_xform(p_translation); } - void Matrix32::orthonormalize() { // Gram-Schmidt Process @@ -550,11 +549,6 @@ void Matrix32::operator*=(const Matrix32& p_transform) { elements[2] = xform(p_transform.elements[2]); float x0,x1,y0,y1; -/* - x0 = p_transform.tdotx(elements[0]); - x1 = p_transform.tdoty(elements[0]); - y0 = p_transform.tdotx(elements[1]); - y1 = p_transform.tdoty(elements[1]);*/ x0 = tdotx(p_transform.elements[0]); x1 = tdoty(p_transform.elements[0]); @@ -576,7 +570,7 @@ Matrix32 Matrix32::operator*(const Matrix32& p_transform) const { } -Matrix32 Matrix32::scaled(const Vector2& p_scale) const { +Matrix32 Matrix32::scaled(const Size2& p_scale) const { Matrix32 copy=*this; copy.scale(p_scale); @@ -584,7 +578,7 @@ Matrix32 Matrix32::scaled(const Vector2& p_scale) const { } -Matrix32 Matrix32::basis_scaled(const Vector2& p_scale) const { +Matrix32 Matrix32::basis_scaled(const Size2& p_scale) const { Matrix32 copy=*this; copy.scale_basis(p_scale); @@ -629,8 +623,8 @@ Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) cons real_t r1 = get_rotation(); real_t r2 = p_transform.get_rotation(); - Vector2 s1 = get_scale(); - Vector2 s2 = p_transform.get_scale(); + Size2 s1 = get_scale(); + Size2 s2 = p_transform.get_scale(); //slerp rotation Vector2 v1(Math::cos(r1), Math::sin(r1)); diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 90aae9fe500..38c1ac96560 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -553,10 +553,8 @@ struct Rect2i { struct Matrix32 { - Vector2 elements[3]; - _FORCE_INLINE_ float tdotx(const Vector2& v) const { return elements[0][0] * v.x + elements[1][0] * v.y; } _FORCE_INLINE_ float tdoty(const Vector2& v) const { return elements[0][1] * v.x + elements[1][1] * v.y; } @@ -577,26 +575,25 @@ struct Matrix32 { _FORCE_INLINE_ void set_rotation_and_scale(real_t p_phi,const Size2& p_scale); void rotate(real_t p_phi); - void scale(const Vector2& p_scale); - void scale_basis(const Vector2& p_scale); + void scale(const Size2& p_scale); + void scale_basis(const Size2& p_scale); void translate( real_t p_tx, real_t p_ty); void translate( const Vector2& p_translation ); float basis_determinant() const; - Vector2 get_scale() const; + Size2 get_scale() const; _FORCE_INLINE_ const Vector2& get_origin() const { return elements[2]; } _FORCE_INLINE_ void set_origin(const Vector2& p_origin) { elements[2]=p_origin; } - Matrix32 scaled(const Vector2& p_scale) const; - Matrix32 basis_scaled(const Vector2& p_scale) const; + Matrix32 scaled(const Size2& p_scale) const; + Matrix32 basis_scaled(const Size2& p_scale) const; Matrix32 translated(const Vector2& p_offset) const; Matrix32 rotated(float p_phi) const; Matrix32 untranslated() const; - void orthonormalize(); Matrix32 orthonormalized() const; @@ -615,7 +612,6 @@ struct Matrix32 { _FORCE_INLINE_ Rect2 xform(const Rect2& p_vec) const; _FORCE_INLINE_ Rect2 xform_inv(const Rect2& p_vec) const; - operator String() const; Matrix32(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) { @@ -630,7 +626,6 @@ struct Matrix32 { Matrix32(real_t p_rot, const Vector2& p_pos); Matrix32() { elements[0][0]=1.0; elements[1][1]=1.0; } - }; bool Rect2::intersects_transformed(const Matrix32& p_xform, const Rect2& p_rect) const { diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index df43e8e3736..b3f925cb14e 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -253,7 +253,7 @@ void Node2D::global_translate(const Vector2& p_amount) { set_global_pos( get_global_pos() + p_amount ); } -void Node2D::scale(const Vector2& p_amount) { +void Node2D::scale(const Size2& p_amount) { set_scale( get_scale() * p_amount ); } diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index aa8d0ef33c7..b31ee08af68 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -79,7 +79,7 @@ public: void move_y(float p_delta,bool p_scaled=false); void translate(const Vector2& p_amount); void global_translate(const Vector2& p_amount); - void scale(const Vector2& p_amount); + void scale(const Size2& p_amount); Point2 get_pos() const; float get_rot() const; @@ -110,8 +110,6 @@ public: Matrix32 get_relative_transform_to_parent(const Node *p_parent) const; - - Matrix32 get_transform() const; Node2D(); diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index cfb87fb998f..12893524d1d 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -288,12 +288,12 @@ float Polygon2D::_get_texture_rotationd() const{ } -void Polygon2D::set_texture_scale(const Vector2& p_scale){ +void Polygon2D::set_texture_scale(const Size2& p_scale){ tex_scale=p_scale; update(); } -Vector2 Polygon2D::get_texture_scale() const{ +Size2 Polygon2D::get_texture_scale() const{ return tex_scale; } diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h index 04e8aeb6fd8..cecb9081f76 100644 --- a/scene/2d/polygon_2d.h +++ b/scene/2d/polygon_2d.h @@ -40,7 +40,7 @@ class Polygon2D : public Node2D { DVector vertex_colors; Color color; Ref texture; - Vector2 tex_scale; + Size2 tex_scale; Vector2 tex_ofs; bool tex_tile; float tex_rot; @@ -81,8 +81,8 @@ public: void set_texture_rotation(float p_rot); float get_texture_rotation() const; - void set_texture_scale(const Vector2& p_scale); - Vector2 get_texture_scale() const; + void set_texture_scale(const Size2& p_scale); + Size2 get_texture_scale() const; void set_invert(bool p_rot); bool get_invert() const; diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h index 6aad90a09d5..a1311390be4 100644 --- a/scene/main/canvas_layer.h +++ b/scene/main/canvas_layer.h @@ -40,7 +40,7 @@ class CanvasLayer : public Node { bool locrotscale_dirty; Vector2 ofs; - Vector2 scale; + Size2 scale; real_t rot; int layer; Matrix32 transform; @@ -81,8 +81,8 @@ public: void set_rotationd(real_t p_degrees); real_t get_rotationd() const; - void set_scale(const Vector2& p_scale); - Vector2 get_scale() const; + void set_scale(const Size2& p_scale); + Size2 get_scale() const; Ref get_world_2d() const; diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index 9291aa6c171..77245c687db 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -136,7 +136,7 @@ bool LineShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_en return true; } -real_t LineShape2DSW::get_moment_of_inertia(float p_mass, const Vector2 &p_scale) const { +real_t LineShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { return 0; } @@ -191,7 +191,7 @@ bool RayShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end } -real_t RayShape2DSW::get_moment_of_inertia(float p_mass, const Vector2 &p_scale) const { +real_t RayShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { return 0; //rays are mass-less } @@ -252,7 +252,7 @@ bool SegmentShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p return true; } -real_t SegmentShape2DSW::get_moment_of_inertia(float p_mass, const Vector2 &p_scale) const { +real_t SegmentShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { Vector2 s[2]={a*p_scale,b*p_scale}; @@ -336,7 +336,7 @@ bool CircleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_ return true; } -real_t CircleShape2DSW::get_moment_of_inertia(float p_mass, const Vector2 &p_scale) const { +real_t CircleShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { return (radius*radius)*(p_scale.x*0.5+p_scale.y*0.5); @@ -407,7 +407,7 @@ bool RectangleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& return get_aabb().intersects_segment(p_begin,p_end,&r_point,&r_normal); } -real_t RectangleShape2DSW::get_moment_of_inertia(float p_mass,const Vector2& p_scale) const { +real_t RectangleShape2DSW::get_moment_of_inertia(float p_mass,const Size2& p_scale) const { Vector2 he2=half_extents*2*p_scale; return p_mass*he2.dot(he2)/12.0f; @@ -540,7 +540,7 @@ bool CapsuleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p return collided; //todo } -real_t CapsuleShape2DSW::get_moment_of_inertia(float p_mass, const Vector2 &p_scale) const { +real_t CapsuleShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { Vector2 he2=Vector2(radius*2,height+radius*2)*p_scale; return p_mass*he2.dot(he2)/12.0f; @@ -670,7 +670,7 @@ bool ConvexPolygonShape2DSW::intersect_segment(const Vector2& p_begin,const Vect return inters; //todo } -real_t ConvexPolygonShape2DSW::get_moment_of_inertia(float p_mass,const Vector2& p_scale) const { +real_t ConvexPolygonShape2DSW::get_moment_of_inertia(float p_mass,const Size2& p_scale) const { Rect2 aabb; aabb.pos=points[0].pos*p_scale; diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h index 41648966960..b90c36bc04f 100644 --- a/servers/physics_2d/shape_2d_sw.h +++ b/servers/physics_2d/shape_2d_sw.h @@ -86,7 +86,7 @@ public: virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const=0; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const=0; - virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const=0; + virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const=0; virtual void set_data(const Variant& p_data)=0; virtual Variant get_data() const=0; @@ -175,7 +175,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; + virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -218,7 +218,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; + virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -266,7 +266,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; + virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -304,7 +304,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; + virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -344,7 +344,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; + virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -432,7 +432,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; + virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -495,7 +495,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; + virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -584,7 +584,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const { return 0; } + virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const { return 0; } virtual void set_data(const Variant& p_data); virtual Variant get_data() const;