Browse Source

Improved 6DOF joint implementation, and removed useless function from cone joint

Andrea Catania 7 years ago
parent
commit
a12e3bab23

+ 1 - 1
modules/bullet/bullet_physics_server.cpp

@@ -1419,7 +1419,7 @@ RID BulletPhysicsServer::joint_create_generic_6dof(RID p_body_A, const Transform
 
 	ERR_FAIL_COND_V(body_A == body_B, RID());
 
-	JointBullet *joint = bulletnew(Generic6DOFJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B, true));
+	JointBullet *joint = bulletnew(Generic6DOFJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
 	AddJointToSpace(body_A, joint);
 
 	CreateThenReturnRID(joint_owner, joint);

+ 0 - 20
modules/bullet/cone_twist_joint_bullet.cpp

@@ -64,26 +64,6 @@ ConeTwistJointBullet::ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet
 	setup(coneConstraint);
 }
 
-void ConeTwistJointBullet::set_angular_only(bool angularOnly) {
-	coneConstraint->setAngularOnly(angularOnly);
-}
-
-void ConeTwistJointBullet::set_limit(real_t _swingSpan1, real_t _swingSpan2, real_t _twistSpan, real_t _softness, real_t _biasFactor, real_t _relaxationFactor) {
-	coneConstraint->setLimit(_swingSpan1, _swingSpan2, _twistSpan, _softness, _biasFactor, _relaxationFactor);
-}
-
-int ConeTwistJointBullet::get_solve_twist_limit() {
-	return coneConstraint->getSolveTwistLimit();
-}
-
-int ConeTwistJointBullet::get_solve_swing_limit() {
-	return coneConstraint->getSolveSwingLimit();
-}
-
-real_t ConeTwistJointBullet::get_twist_limit_sign() {
-	return coneConstraint->getTwistLimitSign();
-}
-
 void ConeTwistJointBullet::set_param(PhysicsServer::ConeTwistJointParam p_param, real_t p_value) {
 	switch (p_param) {
 		case PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN:

+ 0 - 8
modules/bullet/cone_twist_joint_bullet.h

@@ -47,14 +47,6 @@ public:
 
 	virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_CONE_TWIST; }
 
-	void set_angular_only(bool angularOnly);
-
-	void set_limit(real_t _swingSpan1, real_t _swingSpan2, real_t _twistSpan, real_t _softness = 0.8f, real_t _biasFactor = 0.3f, real_t _relaxationFactor = 1.0f);
-	int get_solve_twist_limit();
-
-	int get_solve_swing_limit();
-	real_t get_twist_limit_sign();
-
 	void set_param(PhysicsServer::ConeTwistJointParam p_param, real_t p_value);
 	real_t get_param(PhysicsServer::ConeTwistJointParam p_param) const;
 };

+ 10 - 43
modules/bullet/generic_6dof_joint_bullet.cpp

@@ -34,13 +34,13 @@
 #include "bullet_utilities.h"
 #include "rigid_body_bullet.h"
 
-#include <BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h>
+#include <BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h>
 
 /**
 	@author AndreaCatania
 */
 
-Generic6DOFJointBullet::Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB, bool useLinearReferenceFrameA) :
+Generic6DOFJointBullet::Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB) :
 		JointBullet() {
 
 	Transform scaled_AFrame(frameInA.scaled(rbA->get_body_scale()));
@@ -58,9 +58,9 @@ Generic6DOFJointBullet::Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBu
 		btTransform btFrameB;
 		G_TO_B(scaled_BFrame, btFrameB);
 
-		sixDOFConstraint = bulletnew(btGeneric6DofConstraint(*rbA->get_bt_rigid_body(), *rbB->get_bt_rigid_body(), btFrameA, btFrameB, useLinearReferenceFrameA));
+		sixDOFConstraint = bulletnew(btGeneric6DofSpring2Constraint(*rbA->get_bt_rigid_body(), *rbB->get_bt_rigid_body(), btFrameA, btFrameB));
 	} else {
-		sixDOFConstraint = bulletnew(btGeneric6DofConstraint(*rbA->get_bt_rigid_body(), btFrameA, useLinearReferenceFrameA));
+		sixDOFConstraint = bulletnew(btGeneric6DofSpring2Constraint(*rbA->get_bt_rigid_body(), btFrameA));
 	}
 
 	setup(sixDOFConstraint);
@@ -123,20 +123,11 @@ void Generic6DOFJointBullet::set_param(Vector3::Axis p_axis, PhysicsServer::G6DO
 	switch (p_param) {
 		case PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT:
 			limits_lower[0][p_axis] = p_value;
-			set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, flags[p_axis][p_param]); // Reload bullet parameter
+			set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, flags[p_axis][PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT]); // Reload bullet parameter
 			break;
 		case PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT:
 			limits_upper[0][p_axis] = p_value;
-			set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, flags[p_axis][p_param]); // Reload bullet parameter
-			break;
-		case PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS:
-			sixDOFConstraint->getTranslationalLimitMotor()->m_limitSoftness = p_value;
-			break;
-		case PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION:
-			sixDOFConstraint->getTranslationalLimitMotor()->m_restitution = p_value;
-			break;
-		case PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING:
-			sixDOFConstraint->getTranslationalLimitMotor()->m_damping = p_value;
+			set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, flags[p_axis][PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT]); // Reload bullet parameter
 			break;
 		case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY:
 			sixDOFConstraint->getTranslationalLimitMotor()->m_targetVelocity.m_floats[p_axis] = p_value;
@@ -146,23 +137,11 @@ void Generic6DOFJointBullet::set_param(Vector3::Axis p_axis, PhysicsServer::G6DO
 			break;
 		case PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT:
 			limits_lower[1][p_axis] = p_value;
-			set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, flags[p_axis][p_param]); // Reload bullet parameter
+			set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, flags[p_axis][PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT]); // Reload bullet parameter
 			break;
 		case PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT:
 			limits_upper[1][p_axis] = p_value;
-			set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, flags[p_axis][p_param]); // Reload bullet parameter
-			break;
-		case PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS:
-			sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_limitSoftness = p_value;
-			break;
-		case PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING:
-			sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_damping = p_value;
-			break;
-		case PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION:
-			sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_bounce = p_value;
-			break;
-		case PhysicsServer::G6DOF_JOINT_ANGULAR_FORCE_LIMIT:
-			sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_maxLimitForce = p_value;
+			set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, flags[p_axis][PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT]); // Reload bullet parameter
 			break;
 		case PhysicsServer::G6DOF_JOINT_ANGULAR_ERP:
 			sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_stopERP = p_value;
@@ -171,7 +150,7 @@ void Generic6DOFJointBullet::set_param(Vector3::Axis p_axis, PhysicsServer::G6DO
 			sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_targetVelocity = p_value;
 			break;
 		case PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT:
-			sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_maxLimitForce = p_value;
+			sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_maxMotorForce = p_value;
 			break;
 		default:
 			WARN_PRINT("This parameter is not supported");
@@ -185,12 +164,6 @@ real_t Generic6DOFJointBullet::get_param(Vector3::Axis p_axis, PhysicsServer::G6
 			return limits_lower[0][p_axis];
 		case PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT:
 			return limits_upper[0][p_axis];
-		case PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS:
-			return sixDOFConstraint->getTranslationalLimitMotor()->m_limitSoftness;
-		case PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION:
-			return sixDOFConstraint->getTranslationalLimitMotor()->m_restitution;
-		case PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING:
-			return sixDOFConstraint->getTranslationalLimitMotor()->m_damping;
 		case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY:
 			return sixDOFConstraint->getTranslationalLimitMotor()->m_targetVelocity.m_floats[p_axis];
 		case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT:
@@ -199,20 +172,14 @@ real_t Generic6DOFJointBullet::get_param(Vector3::Axis p_axis, PhysicsServer::G6
 			return limits_lower[1][p_axis];
 		case PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT:
 			return limits_upper[1][p_axis];
-		case PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS:
-			return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_limitSoftness;
-		case PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING:
-			return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_damping;
 		case PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION:
 			return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_bounce;
-		case PhysicsServer::G6DOF_JOINT_ANGULAR_FORCE_LIMIT:
-			return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_maxLimitForce;
 		case PhysicsServer::G6DOF_JOINT_ANGULAR_ERP:
 			return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_stopERP;
 		case PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY:
 			return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_targetVelocity;
 		case PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT:
-			return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_maxLimitForce;
+			return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_maxMotorForce;
 		default:
 			WARN_PRINT("This parameter is not supported");
 			return 0.;

+ 2 - 2
modules/bullet/generic_6dof_joint_bullet.h

@@ -40,7 +40,7 @@
 class RigidBodyBullet;
 
 class Generic6DOFJointBullet : public JointBullet {
-	class btGeneric6DofConstraint *sixDOFConstraint;
+	class btGeneric6DofSpring2Constraint *sixDOFConstraint;
 
 	// First is linear second is angular
 	Vector3 limits_lower[2];
@@ -48,7 +48,7 @@ class Generic6DOFJointBullet : public JointBullet {
 	bool flags[3][PhysicsServer::G6DOF_JOINT_FLAG_MAX];
 
 public:
-	Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB, bool useLinearReferenceFrameA);
+	Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB);
 
 	virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_6DOF; }