From 606729fa2d2741ba7abbc14bc25b80f7ee58dc64 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 3 Jan 2016 20:23:44 -0300 Subject: physics state properly returns contact metadata, closes #1979 --- servers/physics_2d/body_2d_sw.cpp | 22 ++++++++++++++++++++++ servers/physics_2d/body_2d_sw.h | 2 +- servers/physics_2d/physics_2d_server_sw.cpp | 3 +++ servers/physics_2d/physics_2d_server_sw.h | 3 ++- 4 files changed, 28 insertions(+), 2 deletions(-) (limited to 'servers') diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index 6721e188d2..f1f94f3485 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -29,6 +29,7 @@ #include "body_2d_sw.h" #include "space_2d_sw.h" #include "area_2d_sw.h" +#include "physics_2d_server_sw.h" void Body2DSW::_update_inertia() { @@ -704,3 +705,24 @@ Physics2DDirectSpaceState* Physics2DDirectBodyStateSW::get_space_state() { return body->get_space()->get_direct_state(); } + + +Variant Physics2DDirectBodyStateSW::get_contact_collider_shape_metadata(int p_contact_idx) const { + + ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Variant()); + + if (!Physics2DServerSW::singletonsw->body_owner.owns(body->contacts[p_contact_idx].collider)) { + + return Variant(); + } + Body2DSW *other = Physics2DServerSW::singletonsw->body_owner.get(body->contacts[p_contact_idx].collider); + + int sidx = body->contacts[p_contact_idx].collider_shape; + if (sidx<0 || sidx>=other->get_shape_count()) { + + return Variant(); + } + + + return other->get_shape_metadata(sidx); +} diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h index 97a0a312e7..4bd462ac00 100644 --- a/servers/physics_2d/body_2d_sw.h +++ b/servers/physics_2d/body_2d_sw.h @@ -370,7 +370,7 @@ public: virtual Vector2 get_contact_collider_pos(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector2()); return body->contacts[p_contact_idx].collider_pos; } virtual ObjectID get_contact_collider_id(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,0); return body->contacts[p_contact_idx].collider_instance_id; } virtual int get_contact_collider_shape(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,0); return body->contacts[p_contact_idx].collider_shape; } - virtual Variant get_contact_collider_shape_metadata(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Variant()); return body->get_shape_metadata(body->contacts[p_contact_idx].collider_shape); } + virtual Variant get_contact_collider_shape_metadata(int p_contact_idx) const; virtual Vector2 get_contact_collider_velocity_at_pos(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector2()); return body->contacts[p_contact_idx].collider_velocity_at_pos; } diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index d17d499723..c571331498 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -1322,8 +1322,11 @@ int Physics2DServerSW::get_process_info(ProcessInfo p_info) { } +Physics2DServerSW *Physics2DServerSW::singletonsw=NULL; + Physics2DServerSW::Physics2DServerSW() { + singletonsw=this; BroadPhase2DSW::create_func=BroadPhase2DHashGrid::_create; // BroadPhase2DSW::create_func=BroadPhase2DBasic::_create; diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index 5cdcf9225a..28acf4e2d1 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -42,6 +42,7 @@ class Physics2DServerSW : public Physics2DServer { OBJ_TYPE( Physics2DServerSW, Physics2DServer ); friend class Physics2DDirectSpaceStateSW; +friend class Physics2DDirectBodyStateSW; bool active; int iterations; bool doing_sync; @@ -65,7 +66,7 @@ friend class Physics2DDirectSpaceStateSW; mutable RID_Owner body_owner; mutable RID_Owner joint_owner; - + static Physics2DServerSW *singletonsw; // void _clear_query(Query2DSW *p_query); -- cgit v1.2.3