diff options
Diffstat (limited to 'servers/physics/space_sw.cpp')
-rw-r--r-- | servers/physics/space_sw.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index 7077146420..0bc11041de 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,7 +26,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "globals.h" +#include "global_config.h" #include "space_sw.h" #include "collision_solver_sw.h" #include "physics_server_sw.h" @@ -138,7 +138,7 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3& p_from, const Vecto } -int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transform& p_xform,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { +int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transform& p_xform,real_t p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { if (p_result_max<=0) return 0; @@ -146,7 +146,7 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transfo ShapeSW *shape = static_cast<PhysicsServerSW*>(PhysicsServer::get_singleton())->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape,0); - AABB aabb = p_xform.xform(shape->get_aabb()); + Rect3 aabb = p_xform.xform(shape->get_aabb()); int amount = space->broadphase->cull_aabb(aabb,space->intersection_query_results,SpaceSW::INTERSECTION_QUERY_MAX,space->intersection_query_subindex_results); @@ -193,24 +193,26 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transfo } -bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& p_xform,const Vector3& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask,ShapeRestInfo *r_info) { +bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& p_xform,const Vector3& p_motion,real_t p_margin,real_t &p_closest_safe,real_t &p_closest_unsafe, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask,ShapeRestInfo *r_info) { ShapeSW *shape = static_cast<PhysicsServerSW*>(PhysicsServer::get_singleton())->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape,false); - AABB aabb = p_xform.xform(shape->get_aabb()); - aabb=aabb.merge(AABB(aabb.pos+p_motion,aabb.size)); //motion + Rect3 aabb = p_xform.xform(shape->get_aabb()); + aabb=aabb.merge(Rect3(aabb.pos+p_motion,aabb.size)); //motion aabb=aabb.grow(p_margin); - //if (p_motion!=Vector3()) - // print_line(p_motion); + /* + if (p_motion!=Vector3()) + print_line(p_motion); + */ int amount = space->broadphase->cull_aabb(aabb,space->intersection_query_results,SpaceSW::INTERSECTION_QUERY_MAX,space->intersection_query_subindex_results); - float best_safe=1; - float best_unsafe=1; + real_t best_safe=1; + real_t best_unsafe=1; Transform xform_inv = p_xform.affine_inverse(); MotionShapeSW mshape; @@ -262,13 +264,13 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& //just do kinematic solving - float low=0; - float hi=1; + real_t low=0; + real_t hi=1; Vector3 mnormal=p_motion.normalized(); for(int i=0;i<8;i++) { //steps should be customizable.. - float ofs = (low+hi)*0.5; + real_t ofs = (low+hi)*0.5; Vector3 sep=mnormal; //important optimization for this to work fast enough @@ -321,7 +323,7 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& return true; } -bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform& p_shape_xform,float p_margin,Vector3 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask){ +bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform& p_shape_xform,real_t p_margin,Vector3 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask){ if (p_result_max<=0) return 0; @@ -329,7 +331,7 @@ bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform& p_sh ShapeSW *shape = static_cast<PhysicsServerSW*>(PhysicsServer::get_singleton())->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape,0); - AABB aabb = p_shape_xform.xform(shape->get_aabb()); + Rect3 aabb = p_shape_xform.xform(shape->get_aabb()); aabb=aabb.grow(p_margin); int amount = space->broadphase->cull_aabb(aabb,space->intersection_query_results,SpaceSW::INTERSECTION_QUERY_MAX,space->intersection_query_subindex_results); @@ -386,7 +388,7 @@ struct _RestCallbackData { int best_shape; Vector3 best_contact; Vector3 best_normal; - float best_len; + real_t best_len; }; static void _rest_cbk_result(const Vector3& p_point_A,const Vector3& p_point_B,void *p_userdata) { @@ -395,7 +397,7 @@ static void _rest_cbk_result(const Vector3& p_point_A,const Vector3& p_point_B,v _RestCallbackData *rd=(_RestCallbackData*)p_userdata; Vector3 contact_rel = p_point_B - p_point_A; - float len = contact_rel.length(); + real_t len = contact_rel.length(); if (len <= rd->best_len) return; @@ -406,13 +408,13 @@ static void _rest_cbk_result(const Vector3& p_point_A,const Vector3& p_point_B,v rd->best_shape=rd->shape; } -bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform& p_shape_xform,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { +bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform& p_shape_xform,real_t p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { ShapeSW *shape = static_cast<PhysicsServerSW*>(PhysicsServer::get_singleton())->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape,0); - AABB aabb = p_shape_xform.xform(shape->get_aabb()); + Rect3 aabb = p_shape_xform.xform(shape->get_aabb()); aabb=aabb.grow(p_margin); int amount = space->broadphase->cull_aabb(aabb,space->intersection_query_results,SpaceSW::INTERSECTION_QUERY_MAX,space->intersection_query_subindex_results); @@ -719,9 +721,9 @@ SpaceSW::SpaceSW() { contact_max_allowed_penetration= 0.01; constraint_bias = 0.01; - body_linear_velocity_sleep_threshold=GLOBAL_DEF("physics/sleep_threshold_linear",0.1); - body_angular_velocity_sleep_threshold=GLOBAL_DEF("physics/sleep_threshold_angular", (8.0 / 180.0 * Math_PI) ); - body_time_to_sleep=0.5; + body_linear_velocity_sleep_threshold=GLOBAL_DEF("physics/3d/sleep_threshold_linear",0.1); + body_angular_velocity_sleep_threshold=GLOBAL_DEF("physics/3d/sleep_threshold_angular", (8.0 / 180.0 * Math_PI) ); + body_time_to_sleep=GLOBAL_DEF("physics/3d/time_before_sleep",0.5); body_angular_velocity_damp_ratio=10; |