[JBULLET] Axes on BTGeneric6DofConstraint and lock/unlock ?

kingchurch
Posts: 28
Joined: Sun May 13, 2012 7:14 am

Re: [JBULLET] Axes on BTGeneric6DofConstraint and lock/unloc

Post by kingchurch »

Regarding to "lock" a DOF of a 6Dof joint shouldn't we actually add a constraint to remove that DOF from the joint instead of setting joint limits to 0/0? Joint limits only make sense if the allowed movement range is none zero. Otherwise we are stressing the system by putting on additional LCP constraints or spring force elements ( not sure whether bullet joint limits are implemented as springs or LCP)
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Post by Baune »

Thanks Basroil, but that doesnt make any difference. I assume the matrices represents the axes directions in local space so a simple identity matrix should do it ?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re:

Post by Basroil »

Baune wrote:Thanks Basroil, but that doesnt make any difference. I assume the matrices represents the axes directions in local space so a simple identity matrix should do it ?
That could work in some cases, but only if the two rigid bodies were initialized to a rotation where they both point (can't remember if it was x or z axis that need to intersecting in positive direction) to the joint location. If you defined the joints like in the dynamic control demo, they will NOT be identity (rather rotated transformation orthogonal to the identity basis)
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: [JBULLET] Axes on BTGeneric6DofConstraint and lock/unloc

Post by Baune »

So we have two axes that, defined local space, must point in the same global direction. Isnt that a recipe for disaster I mean who CAN figure this out ?
But your answer makes sense now I just have to find a way to fix it..
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: [JBULLET] Axes on BTGeneric6DofConstraint and lock/unloc

Post by Baune »

In this excerpt from the Ragdoll class lies the answer, I think, but damn if I understand the logic behind it.

Code: Select all


        transform.setIdentity();
	transform.setOrigin(btVector3(btScalar(0.), btScalar(scale_ragdoll*1.2), btScalar(0.)));
	m_bodies[BODYPART_SPINE] = localCreateRigidBody(btScalar(1.), offset*transform, m_shapes[BODYPART_SPINE]);

	transform.setIdentity();
	transform.setOrigin(btVector3(btScalar(-0.35*scale_ragdoll), btScalar(1.45*scale_ragdoll), btScalar(0.)));
	transform.getBasis().setEulerZYX(0,0,SIMD_HALF_PI); /// //******************THIS THIS THIS !!
	m_bodies[BODYPART_LEFT_UPPER_ARM] = localCreateRigidBody(btScalar(1.), offset*transform, m_shapes[BODYPART_LEFT_UPPER_ARM]);


/// ******* LEFT SHOULDER ******** ///
	{
		localA.setIdentity(); localB.setIdentity();

		localA.setOrigin(btVector3(btScalar(-0.2*scale_ragdoll), btScalar(0.15*scale_ragdoll), btScalar(0.)));

		localB.getBasis().setEulerZYX(SIMD_HALF_PI,0,-SIMD_HALF_PI); //******************AND THIS THIS THIS !!
		localB.setOrigin(btVector3(btScalar(0.), btScalar(-0.18*scale_ragdoll), btScalar(0.)));

		joint6DOF = new btGeneric6DofConstraint(*m_bodies[BODYPART_SPINE], *m_bodies[BODYPART_LEFT_UPPER_ARM], localA, localB,useLinearReferenceFrameA);

#ifdef RIGID
		joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
		joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
#else
		joint6DOF->setAngularLowerLimit(btVector3(-SIMD_PI*0.8f,-SIMD_EPSILON,-SIMD_PI*0.5f));
		joint6DOF->setAngularUpperLimit(btVector3(SIMD_PI*0.8f,SIMD_EPSILON,SIMD_PI*0.5f));
#endif
		m_joints[JOINT_LEFT_SHOULDER] = joint6DOF;
		m_ownerWorld->addConstraint(m_joints[JOINT_LEFT_SHOULDER], true);
	}
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: [JBULLET] Axes on BTGeneric6DofConstraint and lock/unloc

Post by c6burns »

Baune wrote:who CAN figure this out ?
I spent the better part of an afternoon before I fully grasped how to set up any of the various constraints in the constraint demo. I spent those few hours isolating constraints and changing their setups to understand what was happening. This wiki page helped: http://bulletphysics.org/mediawiki-1.5. ... onstraints
I then integrated various constraints into my platform, and was able to ragdollize game characters exported from a variety of different rigs. I do have 15 years experience working in C, but I have only a high school level of algebra. Still I feel like you are missing something fundamental in the maths.

The ragdoll code you posted uses rotations in the transforms when creating rigid bodies and also when creating the 6dof. Your java code before looked like it was rotating rigid bodies after creation and then constraining them with a 6dof constructor that didn't take frameInA and frameInB parameters. I've never used jbullet so I can't speak to that.
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: [JBULLET] Axes on BTGeneric6DofConstraint and lock/unloc

Post by Baune »

c6burns wrote:
Baune wrote:who CAN figure this out ?
I spent the better part of an afternoon before I fully grasped how to set up any of the various constraints in the constraint demo. I spent those few hours isolating constraints and changing their setups to understand what was happening. This wiki page helped: http://bulletphysics.org/mediawiki-1.5. ... onstraints
I then integrated various constraints into my platform, and was able to ragdollize game characters exported from a variety of different rigs. I do have 15 years experience working in C, but I have only a high school level of algebra. Still I feel like you are missing something fundamental in the maths.

The ragdoll code you posted uses rotations in the transforms when creating rigid bodies and also when creating the 6dof. Your java code before looked like it was rotating rigid bodies after creation and then constraining them with a 6dof constructor that didn't take frameInA and frameInB parameters. I've never used jbullet so I can't speak to that.
Well all I want is information on how to make and axis point in this or that direction from this and that pivot point. .. I'm just very confused. I know perfectly well what matrices and vectors are. But I dont know what they mean in bullet !? If that makes sense.

I could give you an example :

A have two global axes A and B, a global pivot point P and two bodies b1 and b2, rotated in whatever direction. How would you set this up ?

Also if you understood this in a afternoon your pretty good, so far I've spent 10 days on it. But I'm not giving up !

Edit : so does it mean that, if the body is rotated around its own axis Z clock wise then I must also counter rotate the joints axis on the same axis ? because the bodys rotation has rotated the joint axis with it ?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: [JBULLET] Axes on BTGeneric6DofConstraint and lock/unloc

Post by Basroil »

Baune wrote: Well all I want is information on how to make and axis point in this or that direction from this and that pivot point. .. I'm just very confused. I know perfectly well what matrices and vectors are. But I dont know what they mean in bullet !? If that makes sense.
I would highly recommend you check out "Introduction to Robotics: Mechanics & Control" by John J. Craig. You'll be better able to grasp how transformations on joints and rigid bodies work.
Baune wrote: I could give you an example :

A have two global axes A and B, a global pivot point P and two bodies b1 and b2, rotated in whatever direction. How would you set this up ?
So you have TgA (transformation of A in global coordinates), TgB and TgP (same of B and P), and want to get TaP and TbP (transforms of P in A and B coordinates).

TgP=TgA*TaP, so TaP=TgA^-1*TgP (and same for B)

The rotation is the first 3 columns of the transform, the position is the last column. That will be used by bullet as your rest position and rotation though, so if you want to start at a non-zero origin and non-identity rotation you'll have to transform the result accordingly.

Just a warning, I'm still pretty shot out from not sleeping during the world cup (Brazil just happens to literally be on the other side of the world ), so I might have the order backwards. A quick test should clear it out.
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: [JBULLET] Axes on BTGeneric6DofConstraint and lock/unloc

Post by Baune »

I'm not sure this is exactly what you had in mind but what you said led me in the right direction. Seems like it works now.

Thanks to all !

Code: Select all

  //b1 and b2 are bodies
  var r1 = b1.getPhysicsRotation().toRotationMatrix()
  r1 = r1.invert()
  var r2 = b2.getPhysicsRotation().toRotationMatrix()
  r2 = r2.invert()
  var axis1 = new Matrix3f();
  axis1.setIdentity()
  //convert global axis to local
  axis1.mul(r1);
  var axis2 = new Matrix3f();
  axis2.setIdentity()
  //convert global axis to local
  axis2.mul(r2)

  var pivot1 = convertGlobalVectorToLocal(b1, uj.anchor)
  var pivot2 = convertGlobalVectorToLocal(b2, uj.anchor)
  val joint = new SixDofJoint(b1, b2, pivot1, pivot2, axis1, axis2, true)
  var a = Math.toRadians(20).asInstanceOf[Float]; ;
  var lowerLimit = new Vector3f(0, 0, -a)
  var upperLimit = new Vector3f(0, 0, a)
  joint.setAngularLowerLimit(lowerLimit)
  joint.setAngularUpperLimit(upperLimit);
  joint.setCollisionBetweenLinkedBodys(false)
  world.add(joint)

 def convertGlobalVectorToLocal(actor: PhysicsRigidBody, _v: Vector3f) = {
    var globalAnchor: com.jme3.math.Vector3f = new com.jme3.math.Vector3f(_v)
    var rot = new Quaternion(actor.getPhysicsRotation())
    var translation = actor.getPhysicsLocation()
    var store = globalAnchor.subtract(translation, null);
    rot.inverse().mult(store, store);
    store
  }
Post Reply