Browse Source

Implemented Bullet method omit forces

Andrea Catania 7 years ago
parent
commit
e1e78a51aa

+ 14 - 9
modules/bullet/bullet_physics_server.cpp

@@ -619,11 +619,11 @@ uint32_t BulletPhysicsServer::body_get_collision_mask(RID p_body) const {
 }
 }
 
 
 void BulletPhysicsServer::body_set_user_flags(RID p_body, uint32_t p_flags) {
 void BulletPhysicsServer::body_set_user_flags(RID p_body, uint32_t p_flags) {
-	WARN_PRINT("This function si not currently supported by bullet and Godot");
+	// This function si not currently supported
 }
 }
 
 
 uint32_t BulletPhysicsServer::body_get_user_flags(RID p_body) const {
 uint32_t BulletPhysicsServer::body_get_user_flags(RID p_body) const {
-	WARN_PRINT("This function si not currently supported by bullet and Godot");
+	// This function si not currently supported
 	return 0;
 	return 0;
 }
 }
 
 
@@ -784,21 +784,26 @@ int BulletPhysicsServer::body_get_max_contacts_reported(RID p_body) const {
 }
 }
 
 
 void BulletPhysicsServer::body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold) {
 void BulletPhysicsServer::body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold) {
-	WARN_PRINT("Not supported by bullet and even Godot");
+	// Not supported by bullet and even Godot
 }
 }
 
 
 float BulletPhysicsServer::body_get_contacts_reported_depth_threshold(RID p_body) const {
 float BulletPhysicsServer::body_get_contacts_reported_depth_threshold(RID p_body) const {
-	WARN_PRINT("Not supported by bullet and even Godot");
+	// Not supported by bullet and even Godot
 	return 0.;
 	return 0.;
 }
 }
 
 
 void BulletPhysicsServer::body_set_omit_force_integration(RID p_body, bool p_omit) {
 void BulletPhysicsServer::body_set_omit_force_integration(RID p_body, bool p_omit) {
-	WARN_PRINT("Not supported by bullet");
+	RigidBodyBullet *body = rigid_body_owner.get(p_body);
+	ERR_FAIL_COND(!body);
+
+	body->set_omit_forces_integration(p_omit);
 }
 }
 
 
 bool BulletPhysicsServer::body_is_omitting_force_integration(RID p_body) const {
 bool BulletPhysicsServer::body_is_omitting_force_integration(RID p_body) const {
-	WARN_PRINT("Not supported by bullet");
-	return false;
+	RigidBodyBullet *body = rigid_body_owner.get(p_body);
+	ERR_FAIL_COND_V(!body, false);
+
+	return body->get_omit_forces_integration();
 }
 }
 
 
 void BulletPhysicsServer::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) {
 void BulletPhysicsServer::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) {
@@ -979,11 +984,11 @@ PhysicsServer::JointType BulletPhysicsServer::joint_get_type(RID p_joint) const
 }
 }
 
 
 void BulletPhysicsServer::joint_set_solver_priority(RID p_joint, int p_priority) {
 void BulletPhysicsServer::joint_set_solver_priority(RID p_joint, int p_priority) {
-	//WARN_PRINTS("Joint priority not supported by bullet");
+	// Joint priority not supported by bullet
 }
 }
 
 
 int BulletPhysicsServer::joint_get_solver_priority(RID p_joint) const {
 int BulletPhysicsServer::joint_get_solver_priority(RID p_joint) const {
-	//WARN_PRINTS("Joint priority not supported by bullet");
+	// Joint priority not supported by bullet
 	return 0;
 	return 0;
 }
 }
 
 

+ 8 - 0
modules/bullet/rigid_body_bullet.cpp

@@ -255,6 +255,7 @@ RigidBodyBullet::RigidBodyBullet() :
 		linearDamp(0),
 		linearDamp(0),
 		angularDamp(0),
 		angularDamp(0),
 		can_sleep(true),
 		can_sleep(true),
+		omit_forces_integration(false),
 		force_integration_callback(NULL),
 		force_integration_callback(NULL),
 		isTransformChanged(false),
 		isTransformChanged(false),
 		previousActiveState(true),
 		previousActiveState(true),
@@ -334,6 +335,9 @@ void RigidBodyBullet::dispatch_callbacks() {
 	/// The check isTransformChanged is necessary in order to call integrated forces only when the first transform is sent
 	/// The check isTransformChanged is necessary in order to call integrated forces only when the first transform is sent
 	if ((btBody->isActive() || previousActiveState != btBody->isActive()) && force_integration_callback && isTransformChanged) {
 	if ((btBody->isActive() || previousActiveState != btBody->isActive()) && force_integration_callback && isTransformChanged) {
 
 
+		if (omit_forces_integration)
+			btBody->clearForces();
+
 		BulletPhysicsDirectBodyState *bodyDirect = BulletPhysicsDirectBodyState::get_singleton(this);
 		BulletPhysicsDirectBodyState *bodyDirect = BulletPhysicsDirectBodyState::get_singleton(this);
 
 
 		Variant variantBodyDirect = bodyDirect;
 		Variant variantBodyDirect = bodyDirect;
@@ -437,6 +441,10 @@ bool RigidBodyBullet::is_active() const {
 	return btBody->isActive();
 	return btBody->isActive();
 }
 }
 
 
+void RigidBodyBullet::set_omit_forces_integration(bool p_omit) {
+	omit_forces_integration = p_omit;
+}
+
 void RigidBodyBullet::set_param(PhysicsServer::BodyParameter p_param, real_t p_value) {
 void RigidBodyBullet::set_param(PhysicsServer::BodyParameter p_param, real_t p_value) {
 	switch (p_param) {
 	switch (p_param) {
 		case PhysicsServer::BODY_PARAM_BOUNCE:
 		case PhysicsServer::BODY_PARAM_BOUNCE:

+ 4 - 0
modules/bullet/rigid_body_bullet.h

@@ -198,6 +198,7 @@ private:
 	real_t linearDamp;
 	real_t linearDamp;
 	real_t angularDamp;
 	real_t angularDamp;
 	bool can_sleep;
 	bool can_sleep;
+	bool omit_forces_integration;
 
 
 	Vector<CollisionData> collisions;
 	Vector<CollisionData> collisions;
 	// these parameters are used to avoid vector resize
 	// these parameters are used to avoid vector resize
@@ -254,6 +255,9 @@ public:
 	void set_activation_state(bool p_active);
 	void set_activation_state(bool p_active);
 	bool is_active() const;
 	bool is_active() const;
 
 
+	void set_omit_forces_integration(bool p_omit);
+	_FORCE_INLINE_ bool get_omit_forces_integration() const { return omit_forces_integration; }
+
 	void set_param(PhysicsServer::BodyParameter p_param, real_t);
 	void set_param(PhysicsServer::BodyParameter p_param, real_t);
 	real_t get_param(PhysicsServer::BodyParameter p_param) const;
 	real_t get_param(PhysicsServer::BodyParameter p_param) const;