From d7d65fa2f2b51d03f7bdfcbceedca99188ce979c Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 19 Feb 2014 11:57:14 -0300 Subject: -improved physics ccd -html5 exporter works again -disable repeat on image loader by default -can change shape offset en tileset, texture offset was broken --- scene/resources/shape_2d.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++ scene/resources/shape_2d.h | 6 +++++ scene/resources/tile_set.cpp | 39 +++++++++++++++++++++------- scene/resources/tile_set.h | 8 ++++-- 4 files changed, 104 insertions(+), 11 deletions(-) (limited to 'scene/resources') diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index d876454954..ca891920da 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -47,20 +47,82 @@ real_t Shape2D::get_custom_solver_bias() const{ } +bool Shape2D::collide_with_motion(const Matrix32& p_local_xform, const Vector2& p_local_motion, const Ref& p_shape, const Matrix32& p_shape_xform, const Vector2 &p_shape_motion) { + + ERR_FAIL_COND_V(p_shape.is_null(),false); + int r; + return Physics2DServer::get_singleton()->shape_collide(get_rid(),p_local_xform,p_local_motion,p_shape->get_rid(),p_shape_xform,p_shape_motion,NULL,0,r); +} + +bool Shape2D::collide(const Matrix32& p_local_xform, const Ref& p_shape, const Matrix32& p_shape_xform){ + ERR_FAIL_COND_V(p_shape.is_null(),false); + int r; + return Physics2DServer::get_singleton()->shape_collide(get_rid(),p_local_xform,Vector2(),p_shape->get_rid(),p_shape_xform,Vector2(),NULL,0,r); + + +} + +Variant Shape2D::collide_with_motion_and_get_contacts(const Matrix32& p_local_xform, const Vector2& p_local_motion, const Ref& p_shape, const Matrix32& p_shape_xform, const Vector2 &p_shape_motion){ + + ERR_FAIL_COND_V(p_shape.is_null(),Variant()); + const int max_contacts = 16; + Vector2 result[max_contacts*2]; + int contacts=0; + + if (!Physics2DServer::get_singleton()->shape_collide(get_rid(),p_local_xform,p_local_motion,p_shape->get_rid(),p_shape_xform,p_shape_motion,result,max_contacts,contacts)) + return Variant(); + + Array results; + results.resize(contacts*2); + for(int i=0;i& p_shape, const Matrix32& p_shape_xform){ + + ERR_FAIL_COND_V(p_shape.is_null(),Variant()); + const int max_contacts = 16; + Vector2 result[max_contacts*2]; + int contacts=0; + + if (!Physics2DServer::get_singleton()->shape_collide(get_rid(),p_local_xform,Vector2(),p_shape->get_rid(),p_shape_xform,Vector2(),result,max_contacts,contacts)) + return Variant(); + + Array results; + results.resize(contacts*2); + for(int i=0;ifree(shape); diff --git a/scene/resources/shape_2d.h b/scene/resources/shape_2d.h index b01820c22c..5f254a1572 100644 --- a/scene/resources/shape_2d.h +++ b/scene/resources/shape_2d.h @@ -47,6 +47,12 @@ public: void set_custom_solver_bias(real_t p_bias); real_t get_custom_solver_bias() const; + bool collide_with_motion(const Matrix32& p_local_xform, const Vector2& p_local_motion, const Ref& p_shape, const Matrix32& p_shape_xform, const Vector2 &p_p_shape_motion); + bool collide(const Matrix32& p_local_xform, const Ref& p_shape, const Matrix32& p_shape_xform); + + Variant collide_with_motion_and_get_contacts(const Matrix32& p_local_xform, const Vector2& p_local_motion, const Ref& p_shape, const Matrix32& p_shape_xform, const Vector2 &p_p_shape_motion); + Variant collide_and_get_contacts(const Matrix32& p_local_xform, const Ref& p_shape, const Matrix32& p_shape_xform); + virtual RID get_rid() const; Shape2D(); ~Shape2D(); diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index e3c27b0c0c..c85b470325 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -44,8 +44,10 @@ bool TileSet::_set(const StringName& p_name, const Variant& p_value) { tile_set_name(id,p_value); else if (what=="texture") tile_set_texture(id,p_value); - else if (what=="offset") - tile_set_offset(id,p_value); + else if (what=="tex_offset") + tile_set_texture_offset(id,p_value); + else if (what=="shape_offset") + tile_set_shape_offset(id,p_value); else if (what=="region") tile_set_region(id,p_value); else if (what=="shape") @@ -75,8 +77,10 @@ bool TileSet::_get(const StringName& p_name,Variant &r_ret) const{ r_ret=tile_get_name(id); else if (what=="texture") r_ret=tile_get_texture(id); - else if (what=="offset") - r_ret=tile_get_offset(id); + else if (what=="tex_offset") + r_ret=tile_get_texture_offset(id); + else if (what=="shape_offset") + r_ret=tile_get_shape_offset(id); else if (what=="region") r_ret=tile_get_region(id); else if (what=="shape") @@ -98,7 +102,8 @@ void TileSet::_get_property_list( List *p_list) const{ String pre = itos(id)+"/"; p_list->push_back(PropertyInfo(Variant::STRING,pre+"name")); p_list->push_back(PropertyInfo(Variant::OBJECT,pre+"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture")); - p_list->push_back(PropertyInfo(Variant::VECTOR2,pre+"offset")); + p_list->push_back(PropertyInfo(Variant::VECTOR2,pre+"tex_offset")); + p_list->push_back(PropertyInfo(Variant::VECTOR2,pre+"shape_offset")); p_list->push_back(PropertyInfo(Variant::RECT2,pre+"region")); p_list->push_back(PropertyInfo(Variant::OBJECT,pre+"shape",PROPERTY_HINT_RESOURCE_TYPE,"Shape2D",PROPERTY_USAGE_EDITOR)); p_list->push_back(PropertyInfo(Variant::ARRAY,pre+"shapes",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); @@ -129,20 +134,34 @@ Ref TileSet::tile_get_texture(int p_id) const { } -void TileSet::tile_set_offset(int p_id,const Vector2 &p_offset) { +void TileSet::tile_set_texture_offset(int p_id,const Vector2 &p_offset) { ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].offset=p_offset; emit_changed(); } -Vector2 TileSet::tile_get_offset(int p_id) const { +Vector2 TileSet::tile_get_texture_offset(int p_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id),Vector2()); return tile_map[p_id].offset; } +void TileSet::tile_set_shape_offset(int p_id,const Vector2 &p_offset) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + tile_map[p_id].shape_offset=p_offset; + emit_changed(); +} + +Vector2 TileSet::tile_get_shape_offset(int p_id) const { + + ERR_FAIL_COND_V(!tile_map.has(p_id),Vector2()); + return tile_map[p_id].shape_offset; + +} + void TileSet::tile_set_region(int p_id,const Rect2 &p_region) { ERR_FAIL_COND(!tile_map.has(p_id)); @@ -289,8 +308,10 @@ void TileSet::_bind_methods() { ObjectTypeDB::bind_method(_MD("tile_get_name","id"),&TileSet::tile_get_name); ObjectTypeDB::bind_method(_MD("tile_set_texture","id","texture:Texture"),&TileSet::tile_set_texture); ObjectTypeDB::bind_method(_MD("tile_get_texture:Texture","id"),&TileSet::tile_get_texture); - ObjectTypeDB::bind_method(_MD("tile_set_offset","id","offset"),&TileSet::tile_set_offset); - ObjectTypeDB::bind_method(_MD("tile_get_offset","id"),&TileSet::tile_get_offset); + ObjectTypeDB::bind_method(_MD("tile_set_texture_offset","id","texture_offset"),&TileSet::tile_set_texture_offset); + ObjectTypeDB::bind_method(_MD("tile_get_texture_offset","id"),&TileSet::tile_get_texture_offset); + ObjectTypeDB::bind_method(_MD("tile_set_shape_offset","id","shape_offset"),&TileSet::tile_set_shape_offset); + ObjectTypeDB::bind_method(_MD("tile_get_shape_offset","id"),&TileSet::tile_get_shape_offset); ObjectTypeDB::bind_method(_MD("tile_set_region","id","region"),&TileSet::tile_set_region); ObjectTypeDB::bind_method(_MD("tile_get_region","id"),&TileSet::tile_get_region); ObjectTypeDB::bind_method(_MD("tile_set_shape","id","shape:Shape2D"),&TileSet::tile_set_shape); diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index e674316519..0550962362 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -42,6 +42,7 @@ class TileSet : public Resource { String name; Ref texture; Vector2 offset; + Vector2 shape_offset; Rect2i region; Vector > shapes; }; @@ -70,8 +71,11 @@ public: void tile_set_texture(int p_id, const Ref &p_texture); Ref tile_get_texture(int p_id) const; - void tile_set_offset(int p_id,const Vector2 &p_offset); - Vector2 tile_get_offset(int p_id) const; + void tile_set_texture_offset(int p_id,const Vector2 &p_offset); + Vector2 tile_get_texture_offset(int p_id) const; + + void tile_set_shape_offset(int p_id,const Vector2 &p_offset); + Vector2 tile_get_shape_offset(int p_id) const; void tile_set_region(int p_id,const Rect2 &p_region); Rect2 tile_get_region(int p_id) const; -- cgit v1.2.3