aboutsummaryrefslogtreecommitdiff
path: root/servers/physics/body_sw.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'servers/physics/body_sw.cpp')
-rw-r--r--servers/physics/body_sw.cpp394
1 files changed, 175 insertions, 219 deletions
diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp
index 7fcd76726..a4fc694f6 100644
--- a/servers/physics/body_sw.cpp
+++ b/servers/physics/body_sw.cpp
@@ -27,18 +27,17 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "body_sw.h"
-#include "space_sw.h"
#include "area_sw.h"
+#include "space_sw.h"
void BodySW::_update_inertia() {
if (get_space() && !inertia_update_list.in_list())
get_space()->body_add_to_inertia_update_list(&inertia_update_list);
-
}
void BodySW::_update_transform_dependant() {
-
+
center_of_mass = get_transform().basis.xform(center_of_mass_local);
principal_inertia_axes = get_transform().basis * principal_inertia_axes_local;
@@ -47,30 +46,29 @@ void BodySW::_update_transform_dependant() {
Basis tbt = tb.transposed();
tb.scale(_inv_inertia);
_inv_inertia_tensor = tb * tbt;
-
}
void BodySW::update_inertias() {
//update shapes and motions
- switch(mode) {
+ switch (mode) {
case PhysicsServer::BODY_MODE_RIGID: {
//update tensor for all shapes, not the best way but should be somehow OK. (inspired from bullet)
- real_t total_area=0;
+ real_t total_area = 0;
- for (int i=0;i<get_shape_count();i++) {
+ for (int i = 0; i < get_shape_count(); i++) {
- total_area+=get_shape_area(i);
+ total_area += get_shape_area(i);
}
// We have to recompute the center of mass
center_of_mass_local.zero();
- for (int i=0; i<get_shape_count(); i++) {
- real_t area=get_shape_area(i);
+ for (int i = 0; i < get_shape_count(); i++) {
+ real_t area = get_shape_area(i);
real_t mass = area * this->mass / total_area;
@@ -84,25 +82,23 @@ void BodySW::update_inertias() {
Basis inertia_tensor;
inertia_tensor.set_zero();
- for (int i=0;i<get_shape_count();i++) {
+ for (int i = 0; i < get_shape_count(); i++) {
- const ShapeSW* shape=get_shape(i);
+ const ShapeSW *shape = get_shape(i);
- real_t area=get_shape_area(i);
+ real_t area = get_shape_area(i);
real_t mass = area * this->mass / total_area;
- Basis shape_inertia_tensor=shape->get_moment_of_inertia(mass).to_diagonal_matrix();
- Transform shape_transform=get_shape_transform(i);
+ Basis shape_inertia_tensor = shape->get_moment_of_inertia(mass).to_diagonal_matrix();
+ Transform shape_transform = get_shape_transform(i);
Basis shape_basis = shape_transform.basis.orthonormalized();
// NOTE: we don't take the scale of collision shapes into account when computing the inertia tensor!
shape_inertia_tensor = shape_basis * shape_inertia_tensor * shape_basis.transposed();
Vector3 shape_origin = shape_transform.origin - center_of_mass_local;
- inertia_tensor += shape_inertia_tensor + (Basis()*shape_origin.dot(shape_origin)-shape_origin.outer(shape_origin))*mass;
-
-
+ inertia_tensor += shape_inertia_tensor + (Basis() * shape_origin.dot(shape_origin) - shape_origin.outer(shape_origin)) * mass;
}
// Compute the principal axes of inertia
@@ -110,9 +106,9 @@ void BodySW::update_inertias() {
_inv_inertia = inertia_tensor.get_main_diagonal().inverse();
if (mass)
- _inv_mass=1.0/mass;
+ _inv_mass = 1.0 / mass;
else
- _inv_mass=0;
+ _inv_mass = 0;
} break;
@@ -120,42 +116,39 @@ void BodySW::update_inertias() {
case PhysicsServer::BODY_MODE_STATIC: {
_inv_inertia_tensor.set_zero();
- _inv_mass=0;
+ _inv_mass = 0;
} break;
case PhysicsServer::BODY_MODE_CHARACTER: {
_inv_inertia_tensor.set_zero();
- _inv_mass=1.0/mass;
+ _inv_mass = 1.0 / mass;
} break;
}
-
//_update_shapes();
_update_transform_dependant();
}
-
-
void BodySW::set_active(bool p_active) {
- if (active==p_active)
+ if (active == p_active)
return;
- active=p_active;
+ active = p_active;
if (!p_active) {
if (get_space())
get_space()->body_remove_from_active_list(&active_list);
} else {
- if (mode==PhysicsServer::BODY_MODE_STATIC)
+ if (mode == PhysicsServer::BODY_MODE_STATIC)
return; //static bodies can't become active
if (get_space())
get_space()->body_add_to_active_list(&active_list);
//still_time=0;
}
-/*
+ /*
if (!space)
return;
@@ -168,43 +161,41 @@ void BodySW::set_active(bool p_active) {
*/
}
-
-
void BodySW::set_param(PhysicsServer::BodyParameter p_param, real_t p_value) {
- switch(p_param) {
+ switch (p_param) {
case PhysicsServer::BODY_PARAM_BOUNCE: {
- bounce=p_value;
+ bounce = p_value;
} break;
case PhysicsServer::BODY_PARAM_FRICTION: {
- friction=p_value;
+ friction = p_value;
} break;
case PhysicsServer::BODY_PARAM_MASS: {
- ERR_FAIL_COND(p_value<=0);
- mass=p_value;
+ ERR_FAIL_COND(p_value <= 0);
+ mass = p_value;
_update_inertia();
} break;
case PhysicsServer::BODY_PARAM_GRAVITY_SCALE: {
- gravity_scale=p_value;
+ gravity_scale = p_value;
} break;
case PhysicsServer::BODY_PARAM_LINEAR_DAMP: {
- linear_damp=p_value;
+ linear_damp = p_value;
} break;
case PhysicsServer::BODY_PARAM_ANGULAR_DAMP: {
- angular_damp=p_value;
+ angular_damp = p_value;
} break;
- default:{}
+ default: {}
}
}
real_t BodySW::get_param(PhysicsServer::BodyParameter p_param) const {
- switch(p_param) {
+ switch (p_param) {
case PhysicsServer::BODY_PARAM_BOUNCE: {
return bounce;
@@ -228,7 +219,7 @@ real_t BodySW::get_param(PhysicsServer::BodyParameter p_param) const {
return angular_damp;
} break;
- default:{}
+ default: {}
}
return 0;
@@ -236,35 +227,35 @@ real_t BodySW::get_param(PhysicsServer::BodyParameter p_param) const {
void BodySW::set_mode(PhysicsServer::BodyMode p_mode) {
- PhysicsServer::BodyMode prev=mode;
- mode=p_mode;
+ PhysicsServer::BodyMode prev = mode;
+ mode = p_mode;
- switch(p_mode) {
+ switch (p_mode) {
//CLEAR UP EVERYTHING IN CASE IT NOT WORKS!
case PhysicsServer::BODY_MODE_STATIC:
case PhysicsServer::BODY_MODE_KINEMATIC: {
_set_inv_transform(get_transform().affine_inverse());
- _inv_mass=0;
- _set_static(p_mode==PhysicsServer::BODY_MODE_STATIC);
+ _inv_mass = 0;
+ _set_static(p_mode == PhysicsServer::BODY_MODE_STATIC);
//set_active(p_mode==PhysicsServer::BODY_MODE_KINEMATIC);
- set_active(p_mode==PhysicsServer::BODY_MODE_KINEMATIC && contacts.size());
- linear_velocity=Vector3();
- angular_velocity=Vector3();
- if (mode==PhysicsServer::BODY_MODE_KINEMATIC && prev!=mode) {
- first_time_kinematic=true;
+ set_active(p_mode == PhysicsServer::BODY_MODE_KINEMATIC && contacts.size());
+ linear_velocity = Vector3();
+ angular_velocity = Vector3();
+ if (mode == PhysicsServer::BODY_MODE_KINEMATIC && prev != mode) {
+ first_time_kinematic = true;
}
} break;
case PhysicsServer::BODY_MODE_RIGID: {
- _inv_mass=mass>0?(1.0/mass):0;
+ _inv_mass = mass > 0 ? (1.0 / mass) : 0;
_set_static(false);
} break;
case PhysicsServer::BODY_MODE_CHARACTER: {
- _inv_mass=mass>0?(1.0/mass):0;
+ _inv_mass = mass > 0 ? (1.0 / mass) : 0;
_set_static(false);
} break;
}
@@ -274,7 +265,6 @@ void BodySW::set_mode(PhysicsServer::BodyMode p_mode) {
if (get_space())
_update_queries();
*/
-
}
PhysicsServer::BodyMode BodySW::get_mode() const {
@@ -286,35 +276,33 @@ void BodySW::_shapes_changed() {
_update_inertia();
}
-void BodySW::set_state(PhysicsServer::BodyState p_state, const Variant& p_variant) {
+void BodySW::set_state(PhysicsServer::BodyState p_state, const Variant &p_variant) {
- switch(p_state) {
+ switch (p_state) {
case PhysicsServer::BODY_STATE_TRANSFORM: {
-
- if (mode==PhysicsServer::BODY_MODE_KINEMATIC) {
- new_transform=p_variant;
+ if (mode == PhysicsServer::BODY_MODE_KINEMATIC) {
+ new_transform = p_variant;
//wakeup_neighbours();
set_active(true);
if (first_time_kinematic) {
_set_transform(p_variant);
_set_inv_transform(get_transform().affine_inverse());
- first_time_kinematic=false;
+ first_time_kinematic = false;
}
- } else if (mode==PhysicsServer::BODY_MODE_STATIC) {
+ } else if (mode == PhysicsServer::BODY_MODE_STATIC) {
_set_transform(p_variant);
_set_inv_transform(get_transform().affine_inverse());
wakeup_neighbours();
} else {
Transform t = p_variant;
t.orthonormalize();
- new_transform=get_transform(); //used as old to compute motion
- if (new_transform==t)
+ new_transform = get_transform(); //used as old to compute motion
+ if (new_transform == t)
break;
_set_transform(t);
_set_inv_transform(get_transform().inverse());
-
}
wakeup();
@@ -325,7 +313,7 @@ void BodySW::set_state(PhysicsServer::BodyState p_state, const Variant& p_varian
if (mode==PhysicsServer::BODY_MODE_STATIC)
break;
*/
- linear_velocity=p_variant;
+ linear_velocity = p_variant;
wakeup();
} break;
case PhysicsServer::BODY_STATE_ANGULAR_VELOCITY: {
@@ -333,38 +321,37 @@ void BodySW::set_state(PhysicsServer::BodyState p_state, const Variant& p_varian
if (mode!=PhysicsServer::BODY_MODE_RIGID)
break;
*/
- angular_velocity=p_variant;
+ angular_velocity = p_variant;
wakeup();
} break;
case PhysicsServer::BODY_STATE_SLEEPING: {
//?
- if (mode==PhysicsServer::BODY_MODE_STATIC || mode==PhysicsServer::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer::BODY_MODE_STATIC || mode == PhysicsServer::BODY_MODE_KINEMATIC)
break;
- bool do_sleep=p_variant;
+ bool do_sleep = p_variant;
if (do_sleep) {
- linear_velocity=Vector3();
+ linear_velocity = Vector3();
//biased_linear_velocity=Vector3();
- angular_velocity=Vector3();
+ angular_velocity = Vector3();
//biased_angular_velocity=Vector3();
set_active(false);
} else {
- if (mode!=PhysicsServer::BODY_MODE_STATIC)
+ if (mode != PhysicsServer::BODY_MODE_STATIC)
set_active(true);
}
} break;
case PhysicsServer::BODY_STATE_CAN_SLEEP: {
- can_sleep=p_variant;
- if (mode==PhysicsServer::BODY_MODE_RIGID && !active && !can_sleep)
+ can_sleep = p_variant;
+ if (mode == PhysicsServer::BODY_MODE_RIGID && !active && !can_sleep)
set_active(true);
} break;
}
-
}
Variant BodySW::get_state(PhysicsServer::BodyState p_state) const {
- switch(p_state) {
+ switch (p_state) {
case PhysicsServer::BODY_STATE_TRANSFORM: {
return get_transform();
} break;
@@ -385,8 +372,7 @@ Variant BodySW::get_state(PhysicsServer::BodyState p_state) const {
return Variant();
}
-
-void BodySW::set_space(SpaceSW *p_space){
+void BodySW::set_space(SpaceSW *p_space) {
if (get_space()) {
@@ -396,7 +382,6 @@ void BodySW::set_space(SpaceSW *p_space){
get_space()->body_remove_from_active_list(&active_list);
if (direct_state_query_list.in_list())
get_space()->body_remove_from_state_query_list(&direct_state_query_list);
-
}
_set_space(p_space);
@@ -413,19 +398,17 @@ void BodySW::set_space(SpaceSW *p_space){
set_active(true);
}
*/
-
}
- first_integration=true;
-
+ first_integration = true;
}
void BodySW::_compute_area_gravity_and_dampenings(const AreaSW *p_area) {
if (p_area->is_gravity_point()) {
- if(p_area->get_gravity_distance_scale() > 0) {
+ if (p_area->get_gravity_distance_scale() > 0) {
Vector3 v = p_area->get_transform().xform(p_area->get_gravity_vector()) - get_transform().get_origin();
- gravity += v.normalized() * (p_area->get_gravity() / Math::pow(v.length() * p_area->get_gravity_distance_scale()+1, 2) );
+ gravity += v.normalized() * (p_area->get_gravity() / Math::pow(v.length() * p_area->get_gravity_distance_scale() + 1, 2));
} else {
gravity += (p_area->get_transform().xform(p_area->get_gravity_vector()) - get_transform().get_origin()).normalized() * p_area->get_gravity();
}
@@ -439,8 +422,7 @@ void BodySW::_compute_area_gravity_and_dampenings(const AreaSW *p_area) {
void BodySW::integrate_forces(real_t p_step) {
-
- if (mode==PhysicsServer::BODY_MODE_STATIC)
+ if (mode == PhysicsServer::BODY_MODE_STATIC)
return;
AreaSW *def_area = get_space()->get_default_area();
@@ -450,192 +432,179 @@ void BodySW::integrate_forces(real_t p_step) {
int ac = areas.size();
bool stopped = false;
- gravity = Vector3(0,0,0);
+ gravity = Vector3(0, 0, 0);
area_linear_damp = 0;
area_angular_damp = 0;
if (ac) {
areas.sort();
const AreaCMP *aa = &areas[0];
// damp_area = aa[ac-1].area;
- for(int i=ac-1;i>=0 && !stopped;i--) {
- PhysicsServer::AreaSpaceOverrideMode mode=aa[i].area->get_space_override_mode();
+ for (int i = ac - 1; i >= 0 && !stopped; i--) {
+ PhysicsServer::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode();
switch (mode) {
case PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE:
case PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
_compute_area_gravity_and_dampenings(aa[i].area);
- stopped = mode==PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
+ stopped = mode == PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
} break;
case PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE:
case PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
- gravity = Vector3(0,0,0);
+ gravity = Vector3(0, 0, 0);
area_angular_damp = 0;
area_linear_damp = 0;
_compute_area_gravity_and_dampenings(aa[i].area);
- stopped = mode==PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE;
+ stopped = mode == PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE;
} break;
default: {}
}
}
}
- if( !stopped ) {
+ if (!stopped) {
_compute_area_gravity_and_dampenings(def_area);
}
- gravity*=gravity_scale;
+ gravity *= gravity_scale;
// If less than 0, override dampenings with that of the Body
- if (angular_damp>=0)
- area_angular_damp=angular_damp;
+ if (angular_damp >= 0)
+ area_angular_damp = angular_damp;
/*
else
area_angular_damp=damp_area->get_angular_damp();
*/
- if (linear_damp>=0)
- area_linear_damp=linear_damp;
+ if (linear_damp >= 0)
+ area_linear_damp = linear_damp;
/*
else
area_linear_damp=damp_area->get_linear_damp();
*/
-
Vector3 motion;
- bool do_motion=false;
+ bool do_motion = false;
- if (mode==PhysicsServer::BODY_MODE_KINEMATIC) {
+ if (mode == PhysicsServer::BODY_MODE_KINEMATIC) {
//compute motion, angular and etc. velocities from prev transform
- linear_velocity = (new_transform.origin - get_transform().origin)/p_step;
+ linear_velocity = (new_transform.origin - get_transform().origin) / p_step;
//compute a FAKE angular velocity, not so easy
- Basis rot=new_transform.basis.orthonormalized().transposed() * get_transform().basis.orthonormalized();
+ Basis rot = new_transform.basis.orthonormalized().transposed() * get_transform().basis.orthonormalized();
Vector3 axis;
real_t angle;
- rot.get_axis_and_angle(axis,angle);
+ rot.get_axis_and_angle(axis, angle);
axis.normalize();
- angular_velocity=axis.normalized() * (angle/p_step);
+ angular_velocity = axis.normalized() * (angle / p_step);
motion = new_transform.origin - get_transform().origin;
- do_motion=true;
+ do_motion = true;
} else {
if (!omit_force_integration && !first_integration) {
//overriden by direct state query
- Vector3 force=gravity*mass;
- force+=applied_force;
- Vector3 torque=applied_torque;
+ Vector3 force = gravity * mass;
+ force += applied_force;
+ Vector3 torque = applied_torque;
real_t damp = 1.0 - p_step * area_linear_damp;
- if (damp<0) // reached zero in the given time
- damp=0;
+ if (damp < 0) // reached zero in the given time
+ damp = 0;
real_t angular_damp = 1.0 - p_step * area_angular_damp;
- if (angular_damp<0) // reached zero in the given time
- angular_damp=0;
+ if (angular_damp < 0) // reached zero in the given time
+ angular_damp = 0;
- linear_velocity*=damp;
- angular_velocity*=angular_damp;
+ linear_velocity *= damp;
+ angular_velocity *= angular_damp;
- linear_velocity+=_inv_mass * force * p_step;
- angular_velocity+=_inv_inertia_tensor.xform(torque)*p_step;
+ linear_velocity += _inv_mass * force * p_step;
+ angular_velocity += _inv_inertia_tensor.xform(torque) * p_step;
}
if (continuous_cd) {
- motion=linear_velocity*p_step;
- do_motion=true;
+ motion = linear_velocity * p_step;
+ do_motion = true;
}
-
}
- applied_force=Vector3();
- applied_torque=Vector3();
- first_integration=false;
+ applied_force = Vector3();
+ applied_torque = Vector3();
+ first_integration = false;
//motion=linear_velocity*p_step;
- biased_angular_velocity=Vector3();
- biased_linear_velocity=Vector3();
-
+ biased_angular_velocity = Vector3();
+ biased_linear_velocity = Vector3();
- if (do_motion) {//shapes temporarily extend for raycast
+ if (do_motion) { //shapes temporarily extend for raycast
_update_shapes_with_motion(motion);
}
-
- def_area=NULL; // clear the area, so it is set in the next frame
- contact_count=0;
-
+ def_area = NULL; // clear the area, so it is set in the next frame
+ contact_count = 0;
}
void BodySW::integrate_velocities(real_t p_step) {
- if (mode==PhysicsServer::BODY_MODE_STATIC)
+ if (mode == PhysicsServer::BODY_MODE_STATIC)
return;
if (fi_callback)
get_space()->body_add_to_state_query_list(&direct_state_query_list);
- if (mode==PhysicsServer::BODY_MODE_KINEMATIC) {
+ if (mode == PhysicsServer::BODY_MODE_KINEMATIC) {
- _set_transform(new_transform,false);
+ _set_transform(new_transform, false);
_set_inv_transform(new_transform.affine_inverse());
- if (contacts.size()==0 && linear_velocity==Vector3() && angular_velocity==Vector3())
+ if (contacts.size() == 0 && linear_velocity == Vector3() && angular_velocity == Vector3())
set_active(false); //stopped moving, deactivate
return;
}
-
-
//apply axis lock
- if (axis_lock!=PhysicsServer::BODY_AXIS_LOCK_DISABLED) {
+ if (axis_lock != PhysicsServer::BODY_AXIS_LOCK_DISABLED) {
-
- int axis=axis_lock-1;
- for(int i=0;i<3;i++) {
- if (i==axis) {
- linear_velocity[i]=0;
- biased_linear_velocity[i]=0;
+ int axis = axis_lock - 1;
+ for (int i = 0; i < 3; i++) {
+ if (i == axis) {
+ linear_velocity[i] = 0;
+ biased_linear_velocity[i] = 0;
} else {
- angular_velocity[i]=0;
- biased_angular_velocity[i]=0;
+ angular_velocity[i] = 0;
+ biased_angular_velocity[i] = 0;
}
}
-
}
-
- Vector3 total_angular_velocity = angular_velocity+biased_angular_velocity;
-
-
+ Vector3 total_angular_velocity = angular_velocity + biased_angular_velocity;
real_t ang_vel = total_angular_velocity.length();
Transform transform = get_transform();
-
- if (ang_vel!=0.0) {
+ if (ang_vel != 0.0) {
Vector3 ang_vel_axis = total_angular_velocity / ang_vel;
- Basis rot( ang_vel_axis, ang_vel*p_step );
+ Basis rot(ang_vel_axis, ang_vel * p_step);
Basis identity3(1, 0, 0, 0, 1, 0, 0, 0, 1);
transform.origin += ((identity3 - rot) * transform.basis).xform(center_of_mass_local);
transform.basis = rot * transform.basis;
transform.orthonormalize();
}
- Vector3 total_linear_velocity=linear_velocity+biased_linear_velocity;
+ Vector3 total_linear_velocity = linear_velocity + biased_linear_velocity;
/*for(int i=0;i<3;i++) {
if (axis_lock&(1<<i)) {
transform.origin[i]=0.0;
}
}*/
- transform.origin+=total_linear_velocity * p_step;
+ transform.origin += total_linear_velocity * p_step;
_set_transform(transform);
_set_inv_transform(get_transform().inverse());
@@ -684,18 +653,18 @@ void BodySW::simulate_motion(const Transform& p_xform,real_t p_step) {
void BodySW::wakeup_neighbours() {
- for(Map<ConstraintSW*,int>::Element *E=constraint_map.front();E;E=E->next()) {
+ for (Map<ConstraintSW *, int>::Element *E = constraint_map.front(); E; E = E->next()) {
- const ConstraintSW *c=E->key();
+ const ConstraintSW *c = E->key();
BodySW **n = c->get_body_ptr();
- int bc=c->get_body_count();
+ int bc = c->get_body_count();
- for(int i=0;i<bc;i++) {
+ for (int i = 0; i < bc; i++) {
- if (i==E->get())
+ if (i == E->get())
continue;
BodySW *b = n[i];
- if (b->mode!=PhysicsServer::BODY_MODE_RIGID)
+ if (b->mode != PhysicsServer::BODY_MODE_RIGID)
continue;
if (!b->is_active())
@@ -706,109 +675,96 @@ void BodySW::wakeup_neighbours() {
void BodySW::call_queries() {
-
if (fi_callback) {
PhysicsDirectBodyStateSW *dbs = PhysicsDirectBodyStateSW::singleton;
- dbs->body=this;
+ dbs->body = this;
- Variant v=dbs;
+ Variant v = dbs;
Object *obj = ObjectDB::get_instance(fi_callback->id);
if (!obj) {
- set_force_integration_callback(0,StringName());
+ set_force_integration_callback(0, StringName());
} else {
- const Variant *vp[2]={&v,&fi_callback->udata};
+ const Variant *vp[2] = { &v, &fi_callback->udata };
Variant::CallError ce;
- int argc=(fi_callback->udata.get_type()==Variant::NIL)?1:2;
- obj->call(fi_callback->method,vp,argc,ce);
+ int argc = (fi_callback->udata.get_type() == Variant::NIL) ? 1 : 2;
+ obj->call(fi_callback->method, vp, argc, ce);
}
-
-
}
-
-
}
+bool BodySW::sleep_test(real_t p_step) {
-bool BodySW::sleep_test(real_t p_step) {
-
- if (mode==PhysicsServer::BODY_MODE_STATIC || mode==PhysicsServer::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer::BODY_MODE_STATIC || mode == PhysicsServer::BODY_MODE_KINEMATIC)
return true; //
- else if (mode==PhysicsServer::BODY_MODE_CHARACTER)
+ else if (mode == PhysicsServer::BODY_MODE_CHARACTER)
return !active; // characters don't sleep unless asked to sleep
else if (!can_sleep)
return false;
+ if (Math::abs(angular_velocity.length()) < get_space()->get_body_angular_velocity_sleep_treshold() && Math::abs(linear_velocity.length_squared()) < get_space()->get_body_linear_velocity_sleep_treshold() * get_space()->get_body_linear_velocity_sleep_treshold()) {
-
-
- if (Math::abs(angular_velocity.length())<get_space()->get_body_angular_velocity_sleep_treshold() && Math::abs(linear_velocity.length_squared()) < get_space()->get_body_linear_velocity_sleep_treshold()*get_space()->get_body_linear_velocity_sleep_treshold()) {
-
- still_time+=p_step;
+ still_time += p_step;
return still_time > get_space()->get_body_time_to_sleep();
} else {
- still_time=0; //maybe this should be set to 0 on set_active?
+ still_time = 0; //maybe this should be set to 0 on set_active?
return false;
}
}
-
-void BodySW::set_force_integration_callback(ObjectID p_id,const StringName& p_method,const Variant& p_udata) {
+void BodySW::set_force_integration_callback(ObjectID p_id, const StringName &p_method, const Variant &p_udata) {
if (fi_callback) {
memdelete(fi_callback);
- fi_callback=NULL;
+ fi_callback = NULL;
}
+ if (p_id != 0) {
- if (p_id!=0) {
-
- fi_callback=memnew(ForceIntegrationCallback);
- fi_callback->id=p_id;
- fi_callback->method=p_method;
- fi_callback->udata=p_udata;
+ fi_callback = memnew(ForceIntegrationCallback);
+ fi_callback->id = p_id;
+ fi_callback->method = p_method;
+ fi_callback->udata = p_udata;
}
-
}
-BodySW::BodySW() : CollisionObjectSW(TYPE_BODY), active_list(this), inertia_update_list(this), direct_state_query_list(this) {
-
+BodySW::BodySW()
+ : CollisionObjectSW(TYPE_BODY), active_list(this), inertia_update_list(this), direct_state_query_list(this) {
- mode=PhysicsServer::BODY_MODE_RIGID;
- active=true;
+ mode = PhysicsServer::BODY_MODE_RIGID;
+ active = true;
- mass=1;
+ mass = 1;
//_inv_inertia=Transform();
- _inv_mass=1;
- bounce=0;
- friction=1;
- omit_force_integration=false;
+ _inv_mass = 1;
+ bounce = 0;
+ friction = 1;
+ omit_force_integration = false;
//applied_torque=0;
- island_step=0;
- island_next=NULL;
- island_list_next=NULL;
- first_time_kinematic=false;
- first_integration=false;
+ island_step = 0;
+ island_next = NULL;
+ island_list_next = NULL;
+ first_time_kinematic = false;
+ first_integration = false;
_set_static(false);
- contact_count=0;
- gravity_scale=1.0;
+ contact_count = 0;
+ gravity_scale = 1.0;
- area_angular_damp=0;
- area_linear_damp=0;
-
- still_time=0;
- continuous_cd=false;
- can_sleep=false;
- fi_callback=NULL;
- axis_lock=PhysicsServer::BODY_AXIS_LOCK_DISABLED;
+ area_angular_damp = 0;
+ area_linear_damp = 0;
+ still_time = 0;
+ continuous_cd = false;
+ can_sleep = false;
+ fi_callback = NULL;
+ axis_lock = PhysicsServer::BODY_AXIS_LOCK_DISABLED;
}
BodySW::~BodySW() {
@@ -817,9 +773,9 @@ BodySW::~BodySW() {
memdelete(fi_callback);
}
-PhysicsDirectBodyStateSW *PhysicsDirectBodyStateSW::singleton=NULL;
+PhysicsDirectBodyStateSW *PhysicsDirectBodyStateSW::singleton = NULL;
-PhysicsDirectSpaceState* PhysicsDirectBodyStateSW::get_space_state() {
+PhysicsDirectSpaceState *PhysicsDirectBodyStateSW::get_space_state() {
return body->get_space()->get_direct_state();
}