Package com.bulletphysics.dynamics

Examples of com.bulletphysics.dynamics.RigidBody


      Transform startTransform = new Transform();
      startTransform.setIdentity();
      Vector3f camPos = getCameraPosition();
      startTransform.origin.set(camPos);

      RigidBody body = localCreateRigidBody(mass, startTransform, trimeshShape);

      Vector3f linVel = new Vector3f(destination.x - camPos.x, destination.y - camPos.y, destination.z - camPos.z);
      linVel.normalize();
      linVel.scale(ShootBoxInitialSpeed * 0.25f);

      Transform tr = new Transform();
      tr.origin.set(camPos);
      tr.setRotation(new Quat4f(0f, 0f, 0f, 1f));
      body.setWorldTransform(tr);

      body.setLinearVelocity(linVel);
      body.setAngularVelocity(new Vector3f(0f, 0f, 0f));
    }
  }
View Full Code Here


      shape.calculateLocalInertia(mass, localInertia);
    }

    DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
    RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia);
    RigidBody body = new RigidBody(rbInfo);

    ownerWorld.addRigidBody(body);

    return body;
  }
View Full Code Here

        int numObj = getDynamicsWorld().getNumCollisionObjects();
        if (numObj != 0) {
          CollisionObject obj = getDynamicsWorld().getCollisionObjectArray().getQuick(numObj - 1);

          getDynamicsWorld().removeCollisionObject(obj);
          RigidBody body = RigidBody.upcast(obj);
          if (body != null && body.getMotionState() != null) {
            //delete body->getMotionState();
          }
          //delete obj;
        }
        break;
View Full Code Here

        //#else
        shootBoxShape = new BoxShape(new Vector3f(1f, 1f, 1f));
        //#endif//
      }

      RigidBody body = this.localCreateRigidBody(mass, startTransform, shootBoxShape);

      Vector3f linVel = new Vector3f(destination.x - camPos.x, destination.y - camPos.y, destination.z - camPos.z);
      linVel.normalize();
      linVel.scale(ShootBoxInitialSpeed);

      Transform worldTrans = body.getWorldTransform(new Transform());
      worldTrans.origin.set(camPos);
      worldTrans.setRotation(new Quat4f(0f, 0f, 0f, 1f));
      body.setWorldTransform(worldTrans);
     
      body.setLinearVelocity(linVel);
      body.setAngularVelocity(new Vector3f(0f, 0f, 0f));

      body.setCcdMotionThreshold(1f);
      body.setCcdSweptSphereRadius(0.2f);
    }
  }
View Full Code Here

          // apply an impulse
          if (dynamicsWorld != null) {
            CollisionWorld.ClosestRayResultCallback rayCallback = new CollisionWorld.ClosestRayResultCallback(cameraPosition, rayTo);
            dynamicsWorld.rayTest(cameraPosition, rayTo, rayCallback);
            if (rayCallback.hasHit()) {
              RigidBody body = RigidBody.upcast(rayCallback.collisionObject);
              if (body != null) {
                body.setActivationState(CollisionObject.ACTIVE_TAG);
                Vector3f impulse = new Vector3f(rayTo);
                impulse.normalize();
                float impulseStrength = 10f;
                impulse.scale(impulseStrength);
                Vector3f relPos = new Vector3f();
                relPos.sub(rayCallback.hitPointWorld, body.getCenterOfMassPosition(new Vector3f()));
                body.applyImpulse(impulse, relPos);
              }
            }
          }
        }
        else {
        }
        break;
      }
      case 0: {
        if (state == 0) {
          // add a point to point constraint for picking
          if (dynamicsWorld != null) {
            CollisionWorld.ClosestRayResultCallback rayCallback = new CollisionWorld.ClosestRayResultCallback(cameraPosition, rayTo);
            dynamicsWorld.rayTest(cameraPosition, rayTo, rayCallback);
            if (rayCallback.hasHit()) {
              RigidBody body = RigidBody.upcast(rayCallback.collisionObject);
              if (body != null) {
                // other exclusions?
                if (!(body.isStaticObject() || body.isKinematicObject())) {
                  pickedBody = body;
                  pickedBody.setActivationState(CollisionObject.DISABLE_DEACTIVATION);

                  Vector3f pickPos = new Vector3f(rayCallback.hitPointWorld);

                  Transform tmpTrans = body.getCenterOfMassTransform(new Transform());
                  tmpTrans.inverse();
                  Vector3f localPivot = new Vector3f(pickPos);
                  tmpTrans.transform(localPivot);

                  Point2PointConstraint p2p = new Point2PointConstraint(body, localPivot);
View Full Code Here

    //#ifdef USE_MOTIONSTATE
    DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
   
    RigidBodyConstructionInfo cInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia);
   
    RigidBody body = new RigidBody(cInfo);
    //#else
    //btRigidBody* body = new btRigidBody(mass,0,shape,localInertia); 
    //body->setWorldTransform(startTransform);
    //#endif//
   
View Full Code Here

    if (dynamicsWorld != null) {
      int numObjects = dynamicsWorld.getNumCollisionObjects();
      wireColor.set(1f, 0f, 0f);
      for (int i = 0; i < numObjects; i++) {
        CollisionObject colObj = dynamicsWorld.getCollisionObjectArray().getQuick(i);
        RigidBody body = RigidBody.upcast(colObj);

        if (body != null && body.getMotionState() != null) {
          DefaultMotionState myMotionState = (DefaultMotionState) body.getMotionState();
          m.set(myMotionState.graphicsWorldTrans);
        }
        else {
          colObj.getWorldTransform(m);
        }
View Full Code Here

      numObjects = dynamicsWorld.getNumCollisionObjects();
    }

    for (int i = 0; i < numObjects; i++) {
      CollisionObject colObj = dynamicsWorld.getCollisionObjectArray().getQuick(i);
      RigidBody body = RigidBody.upcast(colObj);
      if (body != null) {
        if (body.getMotionState() != null) {
          DefaultMotionState myMotionState = (DefaultMotionState) body.getMotionState();
          myMotionState.graphicsWorldTrans.set(myMotionState.startWorldTrans);
          colObj.setWorldTransform(myMotionState.graphicsWorldTrans);
          colObj.setInterpolationWorldTransform(myMotionState.startWorldTrans);
          colObj.activate();
        }
        // removed cached contact points
        dynamicsWorld.getBroadphase().getOverlappingPairCache().cleanProxyFromPairs(colObj.getBroadphaseHandle(), getDynamicsWorld().getDispatcher());

        body = RigidBody.upcast(colObj);
        if (body != null && !body.isStaticObject()) {
          RigidBody.upcast(colObj).setLinearVelocity(new Vector3f(0f, 0f, 0f));
          RigidBody.upcast(colObj).setAngularVelocity(new Vector3f(0f, 0f, 0f));
        }
      }
View Full Code Here

    // 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

    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

TOP

Related Classes of com.bulletphysics.dynamics.RigidBody

Copyright © 2018 www.massapicom. 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.