diff options
Diffstat (limited to 'servers/physics_2d')
| -rw-r--r-- | servers/physics_2d/body_2d_sw.cpp | 27 | ||||
| -rw-r--r-- | servers/physics_2d/body_2d_sw.h | 3 | ||||
| -rw-r--r-- | servers/physics_2d/physics_2d_server_sw.cpp | 3 | ||||
| -rw-r--r-- | servers/physics_2d/physics_2d_server_sw.h | 3 | ||||
| -rw-r--r-- | servers/physics_2d/space_2d_sw.cpp | 8 |
5 files changed, 37 insertions, 7 deletions
diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index 129ce708d7..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() { @@ -378,6 +379,7 @@ void Body2DSW::set_space(Space2DSW *p_space){ } + first_integration=false; } void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) { @@ -471,7 +473,7 @@ void Body2DSW::integrate_forces(real_t p_step) { //} } else { - if (!omit_force_integration) { + if (!omit_force_integration && !first_integration) { //overriden by direct state query Vector2 force=gravity*mass; @@ -506,6 +508,7 @@ void Body2DSW::integrate_forces(real_t p_step) { //motion=linear_velocity*p_step; + first_integration=false; biased_angular_velocity=0; biased_linear_velocity=Vector2(); @@ -681,6 +684,7 @@ Body2DSW::Body2DSW() : CollisionObject2DSW(TYPE_BODY), active_list(this), inerti gravity_scale=1.0; using_one_way_cache=false; one_way_collision_max_depth=0.1; + first_integration=false; still_time=0; continuous_cd_mode=Physics2DServer::CCD_MODE_DISABLED; @@ -701,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 ae64875567..4bd462ac00 100644 --- a/servers/physics_2d/body_2d_sw.h +++ b/servers/physics_2d/body_2d_sw.h @@ -81,6 +81,7 @@ class Body2DSW : public CollisionObject2DSW { bool active; bool can_sleep; bool first_time_kinematic; + bool first_integration; bool using_one_way_cache; void _update_inertia(); virtual void _shapes_changed(); @@ -369,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<Body2DSW> body_owner; mutable RID_Owner<Joint2DSW> joint_owner; - + static Physics2DServerSW *singletonsw; // void _clear_query(Query2DSW *p_query); diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 90174d48ee..9ba6bdd5ba 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -192,7 +192,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Matri if (p_result_max<=0) return 0; - Shape2DSW *shape = static_cast<Physics2DServerSW*>(Physics2DServer::get_singleton())->shape_owner.get(p_shape); + Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape,0); Rect2 aabb = p_xform.xform(shape->get_aabb()); @@ -239,7 +239,7 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32 - Shape2DSW *shape = static_cast<Physics2DServerSW*>(Physics2DServer::get_singleton())->shape_owner.get(p_shape); + Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape,false); Rect2 aabb = p_xform.xform(shape->get_aabb()); @@ -367,7 +367,7 @@ bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Matrix32& p_s if (p_result_max<=0) return 0; - Shape2DSW *shape = static_cast<Physics2DServerSW*>(Physics2DServer::get_singleton())->shape_owner.get(p_shape); + Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape,0); Rect2 aabb = p_shape_xform.xform(shape->get_aabb()); @@ -474,7 +474,7 @@ static void _rest_cbk_result(const Vector2& p_point_A,const Vector2& p_point_B,v bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { - Shape2DSW *shape = static_cast<Physics2DServerSW*>(Physics2DServer::get_singleton())->shape_owner.get(p_shape); + Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape,0); Rect2 aabb = p_shape_xform.xform(shape->get_aabb()); |