yoshinoToylogic / bulletsharp

Automatically exported from code.google.com/p/bulletsharp
MIT License
0 stars 0 forks source link

ConeTwistConstraint trouble #71

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I try to use 'ConeTwistConstraint' in my simulation. It's a sand bag hanging 
from the ceiling but when my sandbag touch the cone of my constraint with 
enougth speed, its speed increases. I helped me with Example 
'ConstraintDemo.cpp' to produce my code and i don't understand why i have this 
trouble (i use Mogre).

This is my code

      collisionConfiguration = new DefaultCollisionConfiguration();
      collisionDispatcher = new CollisionDispatcher(collisionConfiguration);
      dbvtBroadphase = new DbvtBroadphase();
      constraintSolver = new SequentialImpulseConstraintSolver();
      dynamicsWorld = new DiscreteDynamicsWorld(collisionDispatcher, dbvtBroadphase, constraintSolver, collisionConfiguration) { Gravity = new Vector3(0, -10, 0) };
....

  #region Sac

      SceneNode sceneNodePunchBag = SceneManager.GetSceneNode("sac_boxe");
      Vector3 v3HalfSize = sceneNodePunchBag.GetWorldAABB().HalfSize;
      CollisionShape colShapePunchBag = new CapsuleShape(v3HalfSize.x, v3HalfSize.y * 2);

      Matrix4 matrix4PunchBag = new Matrix4(Matrix4.IDENTITY);
      matrix4PunchBag.SetTrans(new Vector3(sceneNodePunchBag.Position.x, sceneNodePunchBag.Position.y, sceneNodePunchBag.Position.z));

      DefaultMotionState defaultMotionState=new DefaultMotionState();
      Vector3 v3LocalInertiaPunchBag = colShapePunchBag.CalculateLocalInertia(2000f);
      RigidBodyConstructionInfo rbInfoPunchBag = new RigidBodyConstructionInfo(2000, defaultMotionState, colShapePunchBag, v3LocalInertiaPunchBag);

      rigidBodyPunchBag = new RigidBody(rbInfoPunchBag)
                           {
                             ContactProcessingThreshold = 0,
                             ActivationState = ActivationState.DisableDeactivation,
                            };

      dynamicsWorld.AddRigidBody(rigidBodyPunchBag);

      #endregion

      #region contrainte
      CollisionShape colShapeConstraint = new SphereShape(0.5f);

      Matrix4 m4Constraint = new Matrix4(Matrix4.IDENTITY);
      m4Constraint.MakeTrans(sceneNodePunchBag.Position.x, sceneNodePunchBag.Position.y + v3HalfSize.y, sceneNodePunchBag.Position.z);
      DefaultMotionState motionStateConstraint = new DefaultMotionState(m4Constraint);
      RigidBodyConstructionInfo rbInfoConstraint = new RigidBodyConstructionInfo(0, motionStateConstraint, colShapeConstraint, Vector3.ZERO);

      RigidBody rigidBodyConstraint = new RigidBody(rbInfoConstraint)
      {
        ContactProcessingThreshold = 0,
        ActivationState = ActivationState.DisableDeactivation,
      };
      rigidBodyConstraint.CollisionFlags = rigidBodyConstraint.CollisionFlags | CollisionFlags.KinematicObject | CollisionFlags.NoContactResponse;
      rigidBodyConstraint.ActivationState = ActivationState.DisableDeactivation;
      dynamicsWorld.AddRigidBody(rigidBodyConstraint);
      Matrix4 matrix4A = new Matrix4(Matrix4.IDENTITY);
      matrix4A.SetTrans(new Vector3(0, v3HalfSize.y, 0));
      Matrix4 matrix4B = new Matrix4(Matrix4.IDENTITY);
      ConeTwistConstraint coneTwistConstraint = new ConeTwistConstraint(rigidBodyPunchBag, rigidBodyConstraint, matrix4A, matrix4B)
                                                  {
                                                    DebugDrawSize = 5f
                                                  };
      coneTwistConstraint.SetLimit(Math.PI / 32, 10 * Math.TWO_PI, Math.PI / 32, 0.5f);
      dynamicsWorld.AddConstraint(coneTwistConstraint, true);

      #endregion

In my render loop
dynamicsWorld.StepSimulation(_frameEvent.timeSinceLastFrame,10);

I push my bag like this
          rigidBodyPunchBag.CollisionFlags = rigidBodyPunchBag.CollisionFlags | CollisionFlags.KinematicObject; //On bouge l'objet manuellement
          rigidBodyPunchBag.ActivationState = ActivationState.DisableDeactivation; //On désactive toute les forec appliquées à l'objet
          rigidBodyPunchBag.LinearVelocity = new Vector3(-1000, 0, -1000);//, new Vector3(0, 7, -5.4f));
          rigidBodyPunchBag.AngularVelocity = new Vector3(60, 0, 0);//, new Vector3(0, 7, -5.4f));
          rigidBodyPunchBag.CollisionFlags = rigidBodyPunchBag.CollisionFlags ^ CollisionFlags.KinematicObject; //L'objet n'est plus géré manuellement
          rigidBodyPunchBag.Activate(true);

And now, my bag hurts and hurts the cone constraint border.

Can you help me ?

Thanks

Original issue reported on code.google.com by patrick....@rminformatique.com on 24 Jun 2014 at 12:20