summaryrefslogtreecommitdiffstats
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/shape_2d.cpp62
-rw-r--r--scene/resources/shape_2d.h6
-rw-r--r--scene/resources/tile_set.cpp39
-rw-r--r--scene/resources/tile_set.h8
4 files changed, 104 insertions, 11 deletions
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<Shape2D>& 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<Shape2D>& 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<Shape2D>& 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<contacts;i++) {
+ results[i]=result[i];
+ }
+
+ return results;
+
+}
+Variant Shape2D::collide_and_get_contacts(const Matrix32& p_local_xform, const Ref<Shape2D>& 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;i<contacts;i++) {
+ results[i]=result[i];
+ }
+
+ return results;
+
+
+}
+
void Shape2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_custom_solver_bias","bias"),&Shape2D::set_custom_solver_bias);
ObjectTypeDB::bind_method(_MD("get_custom_solver_bias"),&Shape2D::get_custom_solver_bias);
+ ObjectTypeDB::bind_method(_MD("collide","local_xform","with_shape:Shape2D","shape_xform"),&Shape2D::collide);
+ ObjectTypeDB::bind_method(_MD("collide_with_motion","local_xform","local_motion","with_shape:Shape2D","shape_xform","shape_motion"),&Shape2D::collide_with_motion);
+ ObjectTypeDB::bind_method(_MD("collide_and_get_contacts:var","local_xform","with_shape:Shape2D","shape_xform"),&Shape2D::collide_and_get_contacts);
+ ObjectTypeDB::bind_method(_MD("collide_with_motion_and_get_contacts:var","local_xform","local_motion","with_shape:Shape2D","shape_xform","shape_motion"),&Shape2D::collide_and_get_contacts);
ADD_PROPERTY( PropertyInfo(Variant::REAL,"custom_solver_bias",PROPERTY_HINT_RANGE,"0,1,0.001"),_SCS("set_custom_solver_bias"),_SCS("get_custom_solver_bias"));
}
+
+
Shape2D::Shape2D(const RID& p_rid) {
shape=p_rid;
custom_bias=0;
}
+
Shape2D::~Shape2D() {
Physics2DServer::get_singleton()->free(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<Shape2D>& p_shape, const Matrix32& p_shape_xform, const Vector2 &p_p_shape_motion);
+ bool collide(const Matrix32& p_local_xform, const Ref<Shape2D>& 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<Shape2D>& 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<Shape2D>& 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<PropertyInfo> *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<Texture> 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> texture;
Vector2 offset;
+ Vector2 shape_offset;
Rect2i region;
Vector<Ref<Shape2D> > shapes;
};
@@ -70,8 +71,11 @@ public:
void tile_set_texture(int p_id, const Ref<Texture> &p_texture);
Ref<Texture> 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;