physics state properly returns contact metadata, closes #1979

This commit is contained in:
Juan Linietsky 2016-01-03 20:23:44 -03:00
parent d5b8131f27
commit 606729fa2d
4 changed files with 28 additions and 2 deletions

View File

@ -29,6 +29,7 @@
#include "body_2d_sw.h" #include "body_2d_sw.h"
#include "space_2d_sw.h" #include "space_2d_sw.h"
#include "area_2d_sw.h" #include "area_2d_sw.h"
#include "physics_2d_server_sw.h"
void Body2DSW::_update_inertia() { void Body2DSW::_update_inertia() {
@ -704,3 +705,24 @@ Physics2DDirectSpaceState* Physics2DDirectBodyStateSW::get_space_state() {
return body->get_space()->get_direct_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);
}

View File

@ -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 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 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 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; } 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; }

View File

@ -1322,8 +1322,11 @@ int Physics2DServerSW::get_process_info(ProcessInfo p_info) {
} }
Physics2DServerSW *Physics2DServerSW::singletonsw=NULL;
Physics2DServerSW::Physics2DServerSW() { Physics2DServerSW::Physics2DServerSW() {
singletonsw=this;
BroadPhase2DSW::create_func=BroadPhase2DHashGrid::_create; BroadPhase2DSW::create_func=BroadPhase2DHashGrid::_create;
// BroadPhase2DSW::create_func=BroadPhase2DBasic::_create; // BroadPhase2DSW::create_func=BroadPhase2DBasic::_create;

View File

@ -42,6 +42,7 @@ class Physics2DServerSW : public Physics2DServer {
OBJ_TYPE( Physics2DServerSW, Physics2DServer ); OBJ_TYPE( Physics2DServerSW, Physics2DServer );
friend class Physics2DDirectSpaceStateSW; friend class Physics2DDirectSpaceStateSW;
friend class Physics2DDirectBodyStateSW;
bool active; bool active;
int iterations; int iterations;
bool doing_sync; bool doing_sync;
@ -65,7 +66,7 @@ friend class Physics2DDirectSpaceStateSW;
mutable RID_Owner<Body2DSW> body_owner; mutable RID_Owner<Body2DSW> body_owner;
mutable RID_Owner<Joint2DSW> joint_owner; mutable RID_Owner<Joint2DSW> joint_owner;
static Physics2DServerSW *singletonsw;
// void _clear_query(Query2DSW *p_query); // void _clear_query(Query2DSW *p_query);