Examples of RigidBody


Examples of com.bulletphysics.dynamics.RigidBody

    // TODO: check modulo C vs Java mismatch
    return (int) Math.abs(r % un);
  }
 
  private void initSolverBody(SolverBody solverBody, CollisionObject collisionObject) {
    RigidBody rb = RigidBody.upcast(collisionObject);
    if (rb != null) {
      rb.getAngularVelocity(solverBody.angularVelocity);
      solverBody.centerOfMassPosition.set(collisionObject.getWorldTransform(Stack.alloc(Transform.class)).origin);
      solverBody.friction = collisionObject.getFriction();
      solverBody.invMass = rb.getInvMass();
      rb.getLinearVelocity(solverBody.linearVelocity);
      solverBody.originalBody = rb;
      solverBody.angularFactor = rb.getAngularFactor();
    }
    else {
      solverBody.angularVelocity.set(0f, 0f, 0f);
      solverBody.centerOfMassPosition.set(collisionObject.getWorldTransform(Stack.alloc(Transform.class)).origin);
      solverBody.friction = collisionObject.getFriction();
View Full Code Here

Examples of com.bulletphysics.dynamics.RigidBody

    return 0f;
  }
 
  @StaticAlloc
  protected void addFrictionConstraint(Vector3f normalAxis, int solverBodyIdA, int solverBodyIdB, int frictionIndex, ManifoldPoint cp, Vector3f rel_pos1, Vector3f rel_pos2, CollisionObject colObj0, CollisionObject colObj1, float relaxation) {
    RigidBody body0 = RigidBody.upcast(colObj0);
    RigidBody body1 = RigidBody.upcast(colObj1);

    SolverConstraint solverConstraint = constraintsPool.get();
    tmpSolverFrictionConstraintPool.add(solverConstraint);

    solverConstraint.contactNormal.set(normalAxis);

    solverConstraint.solverBodyIdA = solverBodyIdA;
    solverConstraint.solverBodyIdB = solverBodyIdB;
    solverConstraint.constraintType = SolverConstraintType.SOLVER_FRICTION_1D;
    solverConstraint.frictionIndex = frictionIndex;

    solverConstraint.friction = cp.combinedFriction;
    solverConstraint.originalContactPoint = null;

    solverConstraint.appliedImpulse = 0f;
    solverConstraint.appliedPushImpulse = 0f;
    solverConstraint.penetration = 0f;
   
    Vector3f ftorqueAxis1 = Stack.alloc(Vector3f.class);
    Matrix3f tmpMat = Stack.alloc(Matrix3f.class);
   
    {
      ftorqueAxis1.cross(rel_pos1, solverConstraint.contactNormal);
      solverConstraint.relpos1CrossNormal.set(ftorqueAxis1);
      if (body0 != null) {
        solverConstraint.angularComponentA.set(ftorqueAxis1);
        body0.getInvInertiaTensorWorld(tmpMat).transform(solverConstraint.angularComponentA);
      }
      else {
        solverConstraint.angularComponentA.set(0f, 0f, 0f);
      }
    }
    {
      ftorqueAxis1.cross(rel_pos2, solverConstraint.contactNormal);
      solverConstraint.relpos2CrossNormal.set(ftorqueAxis1);
      if (body1 != null) {
        solverConstraint.angularComponentB.set(ftorqueAxis1);
        body1.getInvInertiaTensorWorld(tmpMat).transform(solverConstraint.angularComponentB);
      }
      else {
        solverConstraint.angularComponentB.set(0f, 0f, 0f);
      }
    }

    //#ifdef COMPUTE_IMPULSE_DENOM
    //  btScalar denom0 = rb0->computeImpulseDenominator(pos1,solverConstraint.m_contactNormal);
    //  btScalar denom1 = rb1->computeImpulseDenominator(pos2,solverConstraint.m_contactNormal);
    //#else
    Vector3f vec = Stack.alloc(Vector3f.class);
    float denom0 = 0f;
    float denom1 = 0f;
    if (body0 != null) {
      vec.cross(solverConstraint.angularComponentA, rel_pos1);
      denom0 = body0.getInvMass() + normalAxis.dot(vec);
    }
    if (body1 != null) {
      vec.cross(solverConstraint.angularComponentB, rel_pos2);
      denom1 = body1.getInvMass() + normalAxis.dot(vec);
    }
    //#endif //COMPUTE_IMPULSE_DENOM

    float denom = relaxation / (denom0 + denom1);
    solverConstraint.jacDiagABInv = denom;
View Full Code Here

Examples of com.bulletphysics.dynamics.RigidBody

                int frictionIndex = tmpSolverConstraintPool.size();

                {
                  SolverConstraint solverConstraint = constraintsPool.get();
                  tmpSolverConstraintPool.add(solverConstraint);
                  RigidBody rb0 = RigidBody.upcast(colObj0);
                  RigidBody rb1 = RigidBody.upcast(colObj1);

                  solverConstraint.solverBodyIdA = solverBodyIdA;
                  solverConstraint.solverBodyIdB = solverBodyIdB;
                  solverConstraint.constraintType = SolverConstraintType.SOLVER_CONTACT_1D;
                 
                  solverConstraint.originalContactPoint = cp;

                  torqueAxis0.cross(rel_pos1, cp.normalWorldOnB);

                  if (rb0 != null) {
                    solverConstraint.angularComponentA.set(torqueAxis0);
                    rb0.getInvInertiaTensorWorld(tmpMat).transform(solverConstraint.angularComponentA);
                  }
                  else {
                    solverConstraint.angularComponentA.set(0f, 0f, 0f);
                  }

                  torqueAxis1.cross(rel_pos2, cp.normalWorldOnB);

                  if (rb1 != null) {
                    solverConstraint.angularComponentB.set(torqueAxis1);
                    rb1.getInvInertiaTensorWorld(tmpMat).transform(solverConstraint.angularComponentB);
                  }
                  else {
                    solverConstraint.angularComponentB.set(0f, 0f, 0f);
                  }

                  {
                    //#ifdef COMPUTE_IMPULSE_DENOM
                    //btScalar denom0 = rb0->computeImpulseDenominator(pos1,cp.m_normalWorldOnB);
                    //btScalar denom1 = rb1->computeImpulseDenominator(pos2,cp.m_normalWorldOnB);
                    //#else             
                    float denom0 = 0f;
                    float denom1 = 0f;
                    if (rb0 != null) {
                      vec.cross(solverConstraint.angularComponentA, rel_pos1);
                      denom0 = rb0.getInvMass() + cp.normalWorldOnB.dot(vec);
                    }
                    if (rb1 != null) {
                      vec.cross(solverConstraint.angularComponentB, rel_pos2);
                      denom1 = rb1.getInvMass() + cp.normalWorldOnB.dot(vec);
                    }
                    //#endif //COMPUTE_IMPULSE_DENOM   

                    float denom = relaxation / (denom0 + denom1);
                    solverConstraint.jacDiagABInv = denom;
                  }

                  solverConstraint.contactNormal.set(cp.normalWorldOnB);
                  solverConstraint.relpos1CrossNormal.cross(rel_pos1, cp.normalWorldOnB);
                  solverConstraint.relpos2CrossNormal.cross(rel_pos2, cp.normalWorldOnB);

                  if (rb0 != null) {
                    rb0.getVelocityInLocalPoint(rel_pos1, vel1);
                  }
                  else {
                    vel1.set(0f, 0f, 0f);
                  }
                 
                  if (rb1 != null) {
                    rb1.getVelocityInLocalPoint(rel_pos2, vel2);
                  }
                  else {
                    vel2.set(0f, 0f, 0f);
                  }

                  vel.sub(vel1, vel2);

                  rel_vel = cp.normalWorldOnB.dot(vel);

                  solverConstraint.penetration = Math.min(cp.getDistance() + infoGlobal.linearSlop, 0f);
                  //solverConstraint.m_penetration = cp.getDistance();
                 
                  solverConstraint.friction = cp.combinedFriction;
                  solverConstraint.restitution = restitutionCurve(rel_vel, cp.combinedRestitution);
                  if (solverConstraint.restitution <= 0f) {
                    solverConstraint.restitution = 0f;
                  }

                  float penVel = -solverConstraint.penetration / infoGlobal.timeStep;

                  if (solverConstraint.restitution > penVel) {
                    solverConstraint.penetration = 0f;
                  }
                 
                  Vector3f tmp = Stack.alloc(Vector3f.class);

                  // warm starting (or zero if disabled)
                  if ((infoGlobal.solverMode & SolverMode.SOLVER_USE_WARMSTARTING) != 0) {
                    solverConstraint.appliedImpulse = cp.appliedImpulse * infoGlobal.warmstartingFactor;
                    if (rb0 != null) {
                      tmp.scale(rb0.getInvMass(), solverConstraint.contactNormal);
                      tmpSolverBodyPool.getQuick(solverConstraint.solverBodyIdA).internalApplyImpulse(tmp, solverConstraint.angularComponentA, solverConstraint.appliedImpulse);
                    }
                    if (rb1 != null) {
                      tmp.scale(rb1.getInvMass(), solverConstraint.contactNormal);
                      tmpSolverBodyPool.getQuick(solverConstraint.solverBodyIdB).internalApplyImpulse(tmp, solverConstraint.angularComponentB, -solverConstraint.appliedImpulse);
                    }
                  }
                  else {
                    solverConstraint.appliedImpulse = 0f;
                  }

                  solverConstraint.appliedPushImpulse = 0f;

                  solverConstraint.frictionIndex = tmpSolverFrictionConstraintPool.size();
                  if (!cp.lateralFrictionInitialized) {
                    cp.lateralFrictionDir1.scale(rel_vel, cp.normalWorldOnB);
                    cp.lateralFrictionDir1.sub(vel, cp.lateralFrictionDir1);

                    float lat_rel_vel = cp.lateralFrictionDir1.lengthSquared();
                    if (lat_rel_vel > BulletGlobals.FLT_EPSILON)//0.0f)
                    {
                      cp.lateralFrictionDir1.scale(1f / (float) Math.sqrt(lat_rel_vel));
                      addFrictionConstraint(cp.lateralFrictionDir1, solverBodyIdA, solverBodyIdB, frictionIndex, cp, rel_pos1, rel_pos2, colObj0, colObj1, relaxation);
                      cp.lateralFrictionDir2.cross(cp.lateralFrictionDir1, cp.normalWorldOnB);
                      cp.lateralFrictionDir2.normalize(); //??
                      addFrictionConstraint(cp.lateralFrictionDir2, solverBodyIdA, solverBodyIdB, frictionIndex, cp, rel_pos1, rel_pos2, colObj0, colObj1, relaxation);
                    }
                    else {
                      // re-calculate friction direction every frame, todo: check if this is really needed

                      TransformUtil.planeSpace1(cp.normalWorldOnB, cp.lateralFrictionDir1, cp.lateralFrictionDir2);
                      addFrictionConstraint(cp.lateralFrictionDir1, solverBodyIdA, solverBodyIdB, frictionIndex, cp, rel_pos1, rel_pos2, colObj0, colObj1, relaxation);
                      addFrictionConstraint(cp.lateralFrictionDir2, solverBodyIdA, solverBodyIdB, frictionIndex, cp, rel_pos1, rel_pos2, colObj0, colObj1, relaxation);
                    }
                    cp.lateralFrictionInitialized = true;

                  }
                  else {
                    addFrictionConstraint(cp.lateralFrictionDir1, solverBodyIdA, solverBodyIdB, frictionIndex, cp, rel_pos1, rel_pos2, colObj0, colObj1, relaxation);
                    addFrictionConstraint(cp.lateralFrictionDir2, solverBodyIdA, solverBodyIdB, frictionIndex, cp, rel_pos1, rel_pos2, colObj0, colObj1, relaxation);
                  }

                  {
                    SolverConstraint frictionConstraint1 = tmpSolverFrictionConstraintPool.getQuick(solverConstraint.frictionIndex);
                    if ((infoGlobal.solverMode & SolverMode.SOLVER_USE_WARMSTARTING) != 0) {
                      frictionConstraint1.appliedImpulse = cp.appliedImpulseLateral1 * infoGlobal.warmstartingFactor;
                      if (rb0 != null) {
                        tmp.scale(rb0.getInvMass(), frictionConstraint1.contactNormal);
                        tmpSolverBodyPool.getQuick(solverConstraint.solverBodyIdA).internalApplyImpulse(tmp, frictionConstraint1.angularComponentA, frictionConstraint1.appliedImpulse);
                      }
                      if (rb1 != null) {
                        tmp.scale(rb1.getInvMass(), frictionConstraint1.contactNormal);
                        tmpSolverBodyPool.getQuick(solverConstraint.solverBodyIdB).internalApplyImpulse(tmp, frictionConstraint1.angularComponentB, -frictionConstraint1.appliedImpulse);
                      }
                    }
                    else {
                      frictionConstraint1.appliedImpulse = 0f;
                    }
                  }
                  {
                    SolverConstraint frictionConstraint2 = tmpSolverFrictionConstraintPool.getQuick(solverConstraint.frictionIndex + 1);
                    if ((infoGlobal.solverMode & SolverMode.SOLVER_USE_WARMSTARTING) != 0) {
                      frictionConstraint2.appliedImpulse = cp.appliedImpulseLateral2 * infoGlobal.warmstartingFactor;
                      if (rb0 != null) {
                        tmp.scale(rb0.getInvMass(), frictionConstraint2.contactNormal);
                        tmpSolverBodyPool.getQuick(solverConstraint.solverBodyIdA).internalApplyImpulse(tmp, frictionConstraint2.angularComponentA, frictionConstraint2.appliedImpulse);
                      }
                      if (rb1 != null) {
                        tmp.scale(rb1.getInvMass(), frictionConstraint2.contactNormal);
                        tmpSolverBodyPool.getQuick(solverConstraint.solverBodyIdB).internalApplyImpulse(tmp, frictionConstraint2.angularComponentB, -frictionConstraint2.appliedImpulse);
                      }
                    }
                    else {
                      frictionConstraint2.appliedImpulse = 0f;
View Full Code Here

Examples of com.bulletphysics.dynamics.RigidBody

      BulletStats.popProfile();
    }
  }
 
  protected void prepareConstraints(PersistentManifold manifoldPtr, ContactSolverInfo info, IDebugDraw debugDrawer) {
    RigidBody body0 = (RigidBody) manifoldPtr.getBody0();
    RigidBody body1 = (RigidBody) manifoldPtr.getBody1();

    // only necessary to refresh the manifold once (first iteration). The integration is done outside the loop
    {
      //#ifdef FORCE_REFESH_CONTACT_MANIFOLDS
      //manifoldPtr->refreshContactPoints(body0->getCenterOfMassTransform(),body1->getCenterOfMassTransform());
      //#endif //FORCE_REFESH_CONTACT_MANIFOLDS   
      int numpoints = manifoldPtr.getNumContacts();

      BulletStats.gTotalContactPoints += numpoints;
     
      Vector3f tmpVec = Stack.alloc(Vector3f.class);
      Matrix3f tmpMat3 = Stack.alloc(Matrix3f.class);

      Vector3f pos1 = Stack.alloc(Vector3f.class);
      Vector3f pos2 = Stack.alloc(Vector3f.class);
      Vector3f rel_pos1 = Stack.alloc(Vector3f.class);
      Vector3f rel_pos2 = Stack.alloc(Vector3f.class);
      Vector3f vel1 = Stack.alloc(Vector3f.class);
      Vector3f vel2 = Stack.alloc(Vector3f.class);
      Vector3f vel = Stack.alloc(Vector3f.class);
      Vector3f totalImpulse = Stack.alloc(Vector3f.class);
      Vector3f torqueAxis0 = Stack.alloc(Vector3f.class);
      Vector3f torqueAxis1 = Stack.alloc(Vector3f.class);
      Vector3f ftorqueAxis0 = Stack.alloc(Vector3f.class);
      Vector3f ftorqueAxis1 = Stack.alloc(Vector3f.class);
     
      for (int i = 0; i < numpoints; i++) {
        ManifoldPoint cp = manifoldPtr.getContactPoint(i);
        if (cp.getDistance() <= 0f) {
          cp.getPositionWorldOnA(pos1);
          cp.getPositionWorldOnB(pos2);

          rel_pos1.sub(pos1, body0.getCenterOfMassPosition(tmpVec));
          rel_pos2.sub(pos2, body1.getCenterOfMassPosition(tmpVec));

          // this jacobian entry is re-used for all iterations
          Matrix3f mat1 = body0.getCenterOfMassTransform(Stack.alloc(Transform.class)).basis;
          mat1.transpose();

          Matrix3f mat2 = body1.getCenterOfMassTransform(Stack.alloc(Transform.class)).basis;
          mat2.transpose();

          JacobianEntry jac = jacobiansPool.get();
          jac.init(mat1, mat2,
              rel_pos1, rel_pos2, cp.normalWorldOnB,
              body0.getInvInertiaDiagLocal(Stack.alloc(Vector3f.class)), body0.getInvMass(),
              body1.getInvInertiaDiagLocal(Stack.alloc(Vector3f.class)), body1.getInvMass());

          float jacDiagAB = jac.getDiagonal();
          jacobiansPool.release(jac);

          ConstraintPersistentData cpd = (ConstraintPersistentData) cp.userPersistentData;
          if (cpd != null) {
            // might be invalid
            cpd.persistentLifeTime++;
            if (cpd.persistentLifeTime != cp.getLifeTime()) {
              //printf("Invalid: cpd->m_persistentLifeTime = %i cp.getLifeTime() = %i\n",cpd->m_persistentLifeTime,cp.getLifeTime());
              //new (cpd) btConstraintPersistentData;
              cpd.reset();
              cpd.persistentLifeTime = cp.getLifeTime();

            }
            else {
            //printf("Persistent: cpd->m_persistentLifeTime = %i cp.getLifeTime() = %i\n",cpd->m_persistentLifeTime,cp.getLifeTime());
            }
          }
          else {
            // todo: should this be in a pool?
            //void* mem = btAlignedAlloc(sizeof(btConstraintPersistentData),16);
            //cpd = new (mem)btConstraintPersistentData;
            cpd = new ConstraintPersistentData();
            //assert(cpd != null);

            totalCpd++;
            //printf("totalCpd = %i Created Ptr %x\n",totalCpd,cpd);
            cp.userPersistentData = cpd;
            cpd.persistentLifeTime = cp.getLifeTime();
          //printf("CREATED: %x . cpd->m_persistentLifeTime = %i cp.getLifeTime() = %i\n",cpd,cpd->m_persistentLifeTime,cp.getLifeTime());
          }
          assert (cpd != null);

          cpd.jacDiagABInv = 1f / jacDiagAB;

          // Dependent on Rigidbody A and B types, fetch the contact/friction response func
          // perhaps do a similar thing for friction/restutution combiner funcs...

          cpd.frictionSolverFunc = frictionDispatch[body0.frictionSolverType][body1.frictionSolverType];
          cpd.contactSolverFunc = contactDispatch[body0.contactSolverType][body1.contactSolverType];

          body0.getVelocityInLocalPoint(rel_pos1, vel1);
          body1.getVelocityInLocalPoint(rel_pos2, vel2);
          vel.sub(vel1, vel2);

          float rel_vel;
          rel_vel = cp.normalWorldOnB.dot(vel);

          float combinedRestitution = cp.combinedRestitution;

          cpd.penetration = cp.getDistance(); ///btScalar(info.m_numIterations);
          cpd.friction = cp.combinedFriction;
          cpd.restitution = restitutionCurve(rel_vel, combinedRestitution);
          if (cpd.restitution <= 0f) {
            cpd.restitution = 0f;
          }

          // restitution and penetration work in same direction so
          // rel_vel

          float penVel = -cpd.penetration / info.timeStep;

          if (cpd.restitution > penVel) {
            cpd.penetration = 0f;
          }

          float relaxation = info.damping;
          if ((info.solverMode & SolverMode.SOLVER_USE_WARMSTARTING) != 0) {
            cpd.appliedImpulse *= relaxation;
          }
          else {
            cpd.appliedImpulse = 0f;
          }

          // for friction
          cpd.prevAppliedImpulse = cpd.appliedImpulse;

          // re-calculate friction direction every frame, todo: check if this is really needed
          TransformUtil.planeSpace1(cp.normalWorldOnB, cpd.frictionWorldTangential0, cpd.frictionWorldTangential1);

          //#define NO_FRICTION_WARMSTART 1
          //#ifdef NO_FRICTION_WARMSTART
          cpd.accumulatedTangentImpulse0 = 0f;
          cpd.accumulatedTangentImpulse1 = 0f;
          //#endif //NO_FRICTION_WARMSTART
          float denom0 = body0.computeImpulseDenominator(pos1, cpd.frictionWorldTangential0);
          float denom1 = body1.computeImpulseDenominator(pos2, cpd.frictionWorldTangential0);
          float denom = relaxation / (denom0 + denom1);
          cpd.jacDiagABInvTangent0 = denom;

          denom0 = body0.computeImpulseDenominator(pos1, cpd.frictionWorldTangential1);
          denom1 = body1.computeImpulseDenominator(pos2, cpd.frictionWorldTangential1);
          denom = relaxation / (denom0 + denom1);
          cpd.jacDiagABInvTangent1 = denom;

          //btVector3 totalImpulse =
          //  //#ifndef NO_FRICTION_WARMSTART
          //  //cpd->m_frictionWorldTangential0*cpd->m_accumulatedTangentImpulse0+
          //  //cpd->m_frictionWorldTangential1*cpd->m_accumulatedTangentImpulse1+
          //  //#endif //NO_FRICTION_WARMSTART
          //  cp.normalWorldOnB*cpd.appliedImpulse;
          totalImpulse.scale(cpd.appliedImpulse, cp.normalWorldOnB);

          ///
          {
            torqueAxis0.cross(rel_pos1, cp.normalWorldOnB);

            cpd.angularComponentA.set(torqueAxis0);
            body0.getInvInertiaTensorWorld(tmpMat3).transform(cpd.angularComponentA);

            torqueAxis1.cross(rel_pos2, cp.normalWorldOnB);

            cpd.angularComponentB.set(torqueAxis1);
            body1.getInvInertiaTensorWorld(tmpMat3).transform(cpd.angularComponentB);
          }
          {
            ftorqueAxis0.cross(rel_pos1, cpd.frictionWorldTangential0);

            cpd.frictionAngularComponent0A.set(ftorqueAxis0);
            body0.getInvInertiaTensorWorld(tmpMat3).transform(cpd.frictionAngularComponent0A);
          }
          {
            ftorqueAxis1.cross(rel_pos1, cpd.frictionWorldTangential1);

            cpd.frictionAngularComponent1A.set(ftorqueAxis1);
            body0.getInvInertiaTensorWorld(tmpMat3).transform(cpd.frictionAngularComponent1A);
          }
          {
            ftorqueAxis0.cross(rel_pos2, cpd.frictionWorldTangential0);

            cpd.frictionAngularComponent0B.set(ftorqueAxis0);
            body1.getInvInertiaTensorWorld(tmpMat3).transform(cpd.frictionAngularComponent0B);
          }
          {
            ftorqueAxis1.cross(rel_pos2, cpd.frictionWorldTangential1);

            cpd.frictionAngularComponent1B.set(ftorqueAxis1);
            body1.getInvInertiaTensorWorld(tmpMat3).transform(cpd.frictionAngularComponent1B);
          }

          ///

          // apply previous frames impulse on both bodies
          body0.applyImpulse(totalImpulse, rel_pos1);

          tmpVec.negate(totalImpulse);
          body1.applyImpulse(tmpVec, rel_pos2);
        }

      }
    }
  }
View Full Code Here

Examples of com.bulletphysics.dynamics.RigidBody

    ClosestRayResultCallback rayCallback = new ClosestRayResultCallback(from, to);

    dynamicsWorld.rayTest(from, to, rayCallback);

    if (rayCallback.hasHit()) {
      RigidBody body = RigidBody.upcast(rayCallback.collisionObject);
      if (body != null && body.hasContactResponse()) {
        result.hitPointInWorld.set(rayCallback.hitPointWorld);
        result.hitNormalInWorld.set(rayCallback.hitNormalWorld);
        result.hitNormalInWorld.normalize();
        result.distFraction = rayCallback.closestHitFraction;
        return body;
View Full Code Here

Examples of com.bulletphysics.dynamics.RigidBody

    int numWheelsOnGround = 0;

    // collapse all those loops into one!
    for (int i = 0; i < getNumWheels(); i++) {
      WheelInfo wheel_info = wheelInfo.getQuick(i);
      RigidBody groundObject = (RigidBody) wheel_info.raycastInfo.groundObject;
      if (groundObject != null) {
        numWheelsOnGround++;
      }
      sideImpulse.set(i, 0f);
      forwardImpulse.set(i, 0f);
    }

    {
      Transform wheelTrans = Stack.alloc(Transform.class);
      for (int i = 0; i < getNumWheels(); i++) {

        WheelInfo wheel_info = wheelInfo.getQuick(i);

        RigidBody groundObject = (RigidBody) wheel_info.raycastInfo.groundObject;

        if (groundObject != null) {
          getWheelTransformWS(i, wheelTrans);

          Matrix3f wheelBasis0 = Stack.alloc(wheelTrans.basis);
          axle.getQuick(i).set(
              wheelBasis0.getElement(0, indexRightAxis),
              wheelBasis0.getElement(1, indexRightAxis),
              wheelBasis0.getElement(2, indexRightAxis));

          Vector3f surfNormalWS = wheel_info.raycastInfo.contactNormalWS;
          float proj = axle.getQuick(i).dot(surfNormalWS);
          tmp.scale(proj, surfNormalWS);
          axle.getQuick(i).sub(tmp);
          axle.getQuick(i).normalize();

          forwardWS.getQuick(i).cross(surfNormalWS, axle.getQuick(i));
          forwardWS.getQuick(i).normalize();

          float[] floatPtr = floatArrays.getFixed(1);
          ContactConstraint.resolveSingleBilateral(chassisBody, wheel_info.raycastInfo.contactPointWS,
              groundObject, wheel_info.raycastInfo.contactPointWS,
              0f, axle.getQuick(i), floatPtr, timeStep);
          sideImpulse.set(i, floatPtr[0]);
          floatArrays.release(floatPtr);

          sideImpulse.set(i, sideImpulse.get(i) * sideFrictionStiffness2);
        }
      }
    }

    float sideFactor = 1f;
    float fwdFactor = 0.5f;

    boolean sliding = false;
    {
      for (int wheel = 0; wheel < getNumWheels(); wheel++) {
        WheelInfo wheel_info = wheelInfo.getQuick(wheel);
        RigidBody groundObject = (RigidBody) wheel_info.raycastInfo.groundObject;

        float rollingFriction = 0f;

        if (groundObject != null) {
          if (wheel_info.engineForce != 0f) {
            rollingFriction = wheel_info.engineForce * timeStep;
          }
          else {
            float defaultRollingFrictionImpulse = 0f;
            float maxImpulse = wheel_info.brake != 0f ? wheel_info.brake : defaultRollingFrictionImpulse;
            WheelContactPoint contactPt = new WheelContactPoint(chassisBody, groundObject, wheel_info.raycastInfo.contactPointWS, forwardWS.getQuick(wheel), maxImpulse);
            rollingFriction = calcRollingFriction(contactPt);
          }
        }

        // switch between active rolling (throttle), braking and non-active rolling friction (no throttle/break)

        forwardImpulse.set(wheel, 0f);
        wheelInfo.getQuick(wheel).skidInfo = 1f;

        if (groundObject != null) {
          wheelInfo.getQuick(wheel).skidInfo = 1f;

          float maximp = wheel_info.wheelsSuspensionForce * timeStep * wheel_info.frictionSlip;
          float maximpSide = maximp;

          float maximpSquared = maximp * maximpSide;

          forwardImpulse.set(wheel, rollingFriction); //wheelInfo.m_engineForce* timeStep;

          float x = (forwardImpulse.get(wheel)) * fwdFactor;
          float y = (sideImpulse.get(wheel)) * sideFactor;

          float impulseSquared = (x * x + y * y);

          if (impulseSquared > maximpSquared) {
            sliding = true;

            float factor = maximp / (float) Math.sqrt(impulseSquared);

            wheelInfo.getQuick(wheel).skidInfo *= factor;
          }
        }

      }
    }

    if (sliding) {
      for (int wheel = 0; wheel < getNumWheels(); wheel++) {
        if (sideImpulse.get(wheel) != 0f) {
          if (wheelInfo.getQuick(wheel).skidInfo < 1f) {
            forwardImpulse.set(wheel, forwardImpulse.get(wheel) * wheelInfo.getQuick(wheel).skidInfo);
            sideImpulse.set(wheel, sideImpulse.get(wheel) * wheelInfo.getQuick(wheel).skidInfo);
          }
        }
      }
    }

    // apply the impulses
    {
      for (int wheel = 0; wheel < getNumWheels(); wheel++) {
        WheelInfo wheel_info = wheelInfo.getQuick(wheel);

        Vector3f rel_pos = Stack.alloc(Vector3f.class);
        rel_pos.sub(wheel_info.raycastInfo.contactPointWS, chassisBody.getCenterOfMassPosition(tmp));

        if (forwardImpulse.get(wheel) != 0f) {
          tmp.scale(forwardImpulse.get(wheel), forwardWS.getQuick(wheel));
          chassisBody.applyImpulse(tmp, rel_pos);
        }
        if (sideImpulse.get(wheel) != 0f) {
          RigidBody groundObject = (RigidBody) wheelInfo.getQuick(wheel).raycastInfo.groundObject;

          Vector3f rel_pos2 = Stack.alloc(Vector3f.class);
          rel_pos2.sub(wheel_info.raycastInfo.contactPointWS, groundObject.getCenterOfMassPosition(tmp));

          Vector3f sideImp = Stack.alloc(Vector3f.class);
          sideImp.scale(sideImpulse.get(wheel), axle.getQuick(wheel));

          rel_pos.z *= wheel_info.rollInfluence;
          chassisBody.applyImpulse(sideImp, rel_pos);

          // apply friction impulse on the ground
          tmp.negate(sideImp);
          groundObject.applyImpulse(tmp, rel_pos2);
        }
      }
    }
  }
View Full Code Here

Examples of com.bulletphysics.dynamics.RigidBody

  // TODO: stack allocation
  private static /*final*/ RigidBody s_fixed;// = new RigidBody(0, null, null);
 
  private static synchronized RigidBody getFixed() {
    if (s_fixed == null) {
      s_fixed = new RigidBody(0, null, null);
    }
    return s_fixed;
  }
View Full Code Here

Examples of com.bulletphysics.dynamics.RigidBody

      // using motionstate is recommended, it provides interpolation
      // capabilities, and only synchronizes 'active' objects
      DefaultMotionState myMotionState = new DefaultMotionState(groundTransform);
      RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(
          mass, myMotionState, groundShape, localInertia);
      RigidBody body = new RigidBody(rbInfo);

      // add the body to the dynamics world
      dynamicsWorld.addRigidBody(body);
    }

    {
      // create a dynamic rigidbody

      // btCollisionShape* colShape = new
      // btBoxShape(btVector3(1,1,1));
      CollisionShape colShape = new SphereShape(1.f);
      collisionShapes.add(colShape);

      // Create Dynamic Objects
      Transform startTransform = new Transform();
      startTransform.setIdentity();

      float mass = 1f;

      // rigidbody is dynamic if and only if mass is non zero,
      // otherwise static
      boolean isDynamic = (mass != 0f);

      Vector3f localInertia = new Vector3f(0, 0, 0);
      if (isDynamic) {
        colShape.calculateLocalInertia(mass, localInertia);
      }

      startTransform.origin.set(new Vector3f(2, 10, 0));

      // using motionstate is recommended, it provides
      // interpolation capabilities, and only synchronizes
      // 'active' objects
      DefaultMotionState myMotionState = new DefaultMotionState(startTransform);

      RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(
          mass, myMotionState, colShape, localInertia);
      RigidBody body = new RigidBody(rbInfo);

      dynamicsWorld.addRigidBody(body);
    }

    // Do some simulation
    for (int i=0; i<100; i++) {
      dynamicsWorld.stepSimulation(1.f / 60.f, 10);

      // print positions of all objects
      for (int j=dynamicsWorld.getNumCollisionObjects()-1; j>=0; j--)
      {
        CollisionObject obj = dynamicsWorld.getCollisionObjectArray().getQuick(j);
        RigidBody body = RigidBody.upcast(obj);
        if (body != null && body.getMotionState() != null) {
          Transform trans = new Transform();
          body.getMotionState().getWorldTransform(trans);
          System.out.printf("world pos = %f,%f,%f\n", trans.origin.x,
              trans.origin.y, trans.origin.z);
        }
      }
    }
View Full Code Here

Examples of com.bulletphysics.dynamics.RigidBody

      }

      // using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
      DefaultMotionState myMotionState = new DefaultMotionState(groundTransform);
      RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, groundShape, localInertia);
      RigidBody body = new RigidBody(rbInfo);

      // add the body to the dynamics world
      dynamicsWorld.addRigidBody(body);
    }

    {
      // create a few dynamic rigidbodies
      // Re-using the same collision is better for memory usage and performance

      CollisionShape colShape = new BoxShape(new Vector3f(1, 1, 1));
      //CollisionShape colShape = new SphereShape(1f);
      collisionShapes.add(colShape);

      // Create Dynamic Objects
      Transform startTransform = new Transform();
      startTransform.setIdentity();

      float mass = 1f;

      // rigidbody is dynamic if and only if mass is non zero, otherwise static
      boolean isDynamic = (mass != 0f);

      Vector3f localInertia = new Vector3f(0, 0, 0);
      if (isDynamic) {
        colShape.calculateLocalInertia(mass, localInertia);
      }

      float start_x = START_POS_X - ARRAY_SIZE_X / 2;
      float start_y = START_POS_Y;
      float start_z = START_POS_Z - ARRAY_SIZE_Z / 2;

      for (int k = 0; k < ARRAY_SIZE_Y; k++) {
        for (int i = 0; i < ARRAY_SIZE_X; i++) {
          for (int j = 0; j < ARRAY_SIZE_Z; j++) {
            startTransform.origin.set(
                2f * i + start_x,
                10f + 2f * k + start_y,
                2f * j + start_z);

            // using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
            DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
            RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia);
            RigidBody body = new RigidBody(rbInfo);
            body.setActivationState(RigidBody.ISLAND_SLEEPING);

            dynamicsWorld.addRigidBody(body);
            body.setActivationState(RigidBody.ISLAND_SLEEPING);
          }
        }
      }
    }

View Full Code Here

Examples of net.nakou.indie.jsige.entity.RigidBody

    public void fillFromTile(){
  if(tileMap != null){
      BlockMap ent;
      Controller c;
      Element e;
      RigidBody r;
      for (int xAxis=0;xAxis<tileMap.getWidth(); xAxis++)
      {
    for (int yAxis=0;yAxis<tileMap.getHeight(); yAxis++)
    {
        int tileID = tileMap.getTileId(xAxis, yAxis, 0);
        if(CONF.debugLevel >= 3)
      System.out.println(tileMap.getTileProperty(tileID, "Solid", "0"));
        if(tileMap.getTileProperty(tileID, "Solid", "0").equals("1")){
      try {
          ent = new BlockMap();
          e = new Element(ent, tileMap.getVisibleTile(xAxis, yAxis));
          ent.setElement(e);
          c = new Controller(ent, xAxis*32, yAxis*32);
          ent.setController(c);
          r = new RigidBody(ent,1, true, true);
          ent.setRigidbody(r);
                            ent.setEntityName("BlockNĀ°"+tileID);
      } catch (SlickException ex) {
          Logger.getLogger(Map.class.getName()).log(Level.SEVERE, null, ex);
          ent = null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.