Package com.bulletphysics.collision.dispatch

Examples of com.bulletphysics.collision.dispatch.CollisionObject


    //http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers 
    // Aufwendig, scheint aber wenigstens zu gehen, ohne dass die Boxen durch den Boden fallen.
    int numManifolds = getDynamicsWorld().getDispatcher().getNumManifolds();
    for (int i = 0; i < numManifolds; i++) {
      PersistentManifold contactManifold = getDynamicsWorld().getDispatcher().getManifoldByIndexInternal(i);
      CollisionObject objA = (CollisionObject) contactManifold.getBody0();
     
      //Wir wollen nur Kollisionen zwischen Boden und Appendix wissen!
      if (!objA.equals(groundBody)) {
        continue;
      }
      CollisionObject objB = (CollisionObject) contactManifold.getBody1();
      if (!objB.equals(this.getRigidBody())) {
        continue;
      }
     
      int numContacts = contactManifold.getNumContacts();
      for (int j = 0; j < numContacts; j++) {
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);
        }

        wireColor.set(1f, 1f, 0.5f); // wants deactivation
        if ((i & 1) != 0) {
          wireColor.set(0f, 0f, 1f);
        }

        // color differently for active, sleeping, wantsdeactivation
        // states
        if (colObj.getActivationState() == 1) // active
        {
          if ((i & 1) != 0) {
            // wireColor.add(new Vector3f(1f, 0f, 0f));
            wireColor.x += 1f;
          } else {
            // wireColor.add(new Vector3f(0.5f, 0f, 0f));
            wireColor.x += 0.5f;
          }
        }
        if (colObj.getActivationState() == 2) // ISLAND_SLEEPING
        {
          if ((i & 1) != 0) {
            // wireColor.add(new Vector3f(0f, 1f, 0f));
            wireColor.y += 1f;
          } else {
            // wireColor.add(new Vector3f(0f, 0.5f, 0f));
            wireColor.y += 0.5f;
          }
        }

        GLShapeDrawer.drawOpenGL(gl, m, colObj.getCollisionShape(),
            wireColor, 0);
      }
    }
    updateCamera();
  }
View Full Code Here

      // dynamicsWorld.stepSimulation(1f / 60f, 0);
      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(
View Full Code Here

      // optional but useful: debug drawing
      dynamicsWorld.debugDrawWorld();
    }

    for (int i=2; i>=0; i--) {
      CollisionObject obj = dynamicsWorld.getCollisionObjectArray().getQuick(i);
      RigidBody body = RigidBody.upcast(obj);
      drawFrame(body.getWorldTransform(new Transform()));
    }
   
    renderme();
View Full Code Here

        break;
      }
      case Keyboard.KEY_END: {
        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();
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);
        }

        wireColor.set(1f, 1f, 0.5f); // wants deactivation
        if ((i & 1) != 0) {
          wireColor.set(0f, 0f, 1f);
        }

        // color differently for active, sleeping, wantsdeactivation states
        if (colObj.getActivationState() == 1) // active
        {
          if ((i & 1) != 0) {
            //wireColor.add(new Vector3f(1f, 0f, 0f));
            wireColor.x += 1f;
          }
          else {
            //wireColor.add(new Vector3f(0.5f, 0f, 0f));
            wireColor.x += 0.5f;
          }
        }
        if (colObj.getActivationState() == 2) // ISLAND_SLEEPING
        {
          if ((i & 1) != 0) {
            //wireColor.add(new Vector3f(0f, 1f, 0f));
            wireColor.y += 1f;
          }
          else {
            //wireColor.add(new Vector3f(0f, 0.5f, 0f));
            wireColor.y += 0.5f;
          }
        }

        GLShapeDrawer.drawOpenGL(gl, m, colObj.getCollisionShape(), wireColor, getDebugMode());
      }

      float xOffset = 10f;
      float yStart = 20f;
      float yIncr = 20f;
View Full Code Here

      dynamicsWorld.stepSimulation(1f / 60f, 0);
      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

      if ((numConstraints + numManifolds) == 0) {
        // printf("empty\n");
        return 0f;
      }
      PersistentManifold manifold = null;
      CollisionObject colObj0 = null, colObj1 = null;

      //btRigidBody* rb0=0,*rb1=0;

  //  //#ifdef FORCE_REFESH_CONTACT_MANIFOLDS
  //
  //    BEGIN_PROFILE("refreshManifolds");
  //
  //    int i;
  //
  //
  //
  //    for (i=0;i<numManifolds;i++)
  //    {
  //      manifold = manifoldPtr[i];
  //      rb1 = (btRigidBody*)manifold->getBody1();
  //      rb0 = (btRigidBody*)manifold->getBody0();
  //
  //      manifold->refreshContactPoints(rb0->getCenterOfMassTransform(),rb1->getCenterOfMassTransform());
  //
  //    }
  //
  //    END_PROFILE("refreshManifolds");
  //  //#endif //FORCE_REFESH_CONTACT_MANIFOLDS

      Transform tmpTrans = Stack.alloc(Transform.class);

      //int sizeofSB = sizeof(btSolverBody);
      //int sizeofSC = sizeof(btSolverConstraint);

      //if (1)
      {
        //if m_stackAlloc, try to pack bodies/constraints to speed up solving
        //    btBlock*          sablock;
        //    sablock = stackAlloc->beginBlock();

        //  int memsize = 16;
        //    unsigned char* stackMemory = stackAlloc->allocate(memsize);


        // todo: use stack allocator for this temp memory
        //int minReservation = numManifolds * 2;

        //m_tmpSolverBodyPool.reserve(minReservation);

        //don't convert all bodies, only the one we need so solver the constraints
        /*
        {
        for (int i=0;i<numBodies;i++)
        {
        btRigidBody* rb = btRigidBody::upcast(bodies[i]);
        if (rb &&   (rb->getIslandTag() >= 0))
        {
        btAssert(rb->getCompanionId() < 0);
        int solverBodyId = m_tmpSolverBodyPool.size();
        btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
        initSolverBody(&solverBody,rb);
        rb->setCompanionId(solverBodyId);
        }
        }
        }
        */

        //m_tmpSolverConstraintPool.reserve(minReservation);
        //m_tmpSolverFrictionConstraintPool.reserve(minReservation);

        {
          int i;
         
          Vector3f rel_pos1 = Stack.alloc(Vector3f.class);
          Vector3f rel_pos2 = Stack.alloc(Vector3f.class);

          Vector3f pos1 = Stack.alloc(Vector3f.class);
          Vector3f pos2 = Stack.alloc(Vector3f.class);
          Vector3f vel = Stack.alloc(Vector3f.class);
          Vector3f torqueAxis0 = Stack.alloc(Vector3f.class);
          Vector3f torqueAxis1 = Stack.alloc(Vector3f.class);
          Vector3f vel1 = Stack.alloc(Vector3f.class);
          Vector3f vel2 = Stack.alloc(Vector3f.class);
          Vector3f frictionDir1 = Stack.alloc(Vector3f.class);
          Vector3f frictionDir2 = Stack.alloc(Vector3f.class);
          Vector3f vec = Stack.alloc(Vector3f.class);

          Matrix3f tmpMat = Stack.alloc(Matrix3f.class);
         
          for (i = 0; i < numManifolds; i++) {
            manifold = manifoldPtr.getQuick(manifold_offset+i);
            colObj0 = (CollisionObject) manifold.getBody0();
            colObj1 = (CollisionObject) manifold.getBody1();

            int solverBodyIdA = -1;
            int solverBodyIdB = -1;

            if (manifold.getNumContacts() != 0) {
              if (colObj0.getIslandTag() >= 0) {
                if (colObj0.getCompanionId() >= 0) {
                  // body has already been converted
                  solverBodyIdA = colObj0.getCompanionId();
                }
                else {
                  solverBodyIdA = tmpSolverBodyPool.size();
                  SolverBody solverBody = bodiesPool.get();
                  tmpSolverBodyPool.add(solverBody);
                  initSolverBody(solverBody, colObj0);
                  colObj0.setCompanionId(solverBodyIdA);
                }
              }
              else {
                // create a static body
                solverBodyIdA = tmpSolverBodyPool.size();
                SolverBody solverBody = bodiesPool.get();
                tmpSolverBodyPool.add(solverBody);
                initSolverBody(solverBody, colObj0);
              }

              if (colObj1.getIslandTag() >= 0) {
                if (colObj1.getCompanionId() >= 0) {
                  solverBodyIdB = colObj1.getCompanionId();
                }
                else {
                  solverBodyIdB = tmpSolverBodyPool.size();
                  SolverBody solverBody = bodiesPool.get();
                  tmpSolverBodyPool.add(solverBody);
                  initSolverBody(solverBody, colObj1);
                  colObj1.setCompanionId(solverBodyIdB);
                }
              }
              else {
                // create a static body
                solverBodyIdB = tmpSolverBodyPool.size();
                SolverBody solverBody = bodiesPool.get();
                tmpSolverBodyPool.add(solverBody);
                initSolverBody(solverBody, colObj1);
              }
            }

            float relaxation;

            for (int j = 0; j < manifold.getNumContacts(); j++) {

              ManifoldPoint cp = manifold.getContactPoint(j);

              if (cp.getDistance() <= 0f) {
                cp.getPositionWorldOnA(pos1);
                cp.getPositionWorldOnB(pos2);

                rel_pos1.sub(pos1, colObj0.getWorldTransform(tmpTrans).origin);
                rel_pos2.sub(pos2, colObj1.getWorldTransform(tmpTrans).origin);

                relaxation = 1f;
                float rel_vel;

View Full Code Here

    ownsIslandManager = true;
  }

  protected void saveKinematicState(float timeStep) {
    for (int i = 0; i < collisionObjects.size(); i++) {
      CollisionObject colObj = collisionObjects.getQuick(i);
      RigidBody body = RigidBody.upcast(colObj);
      if (body != null) {
        //Transform predictedTrans = new Transform();
        if (body.getActivationState() != CollisionObject.ISLAND_SLEEPING) {
          if (body.isKinematicObject()) {
View Full Code Here

      Vector3f maxAabb = Stack.alloc(Vector3f.class);
      Vector3f colorvec = Stack.alloc(Vector3f.class);
     
      // todo: iterate over awake simulation islands!
      for (i = 0; i < collisionObjects.size(); i++) {
        CollisionObject colObj = collisionObjects.getQuick(i);
        if (getDebugDrawer() != null && (getDebugDrawer().getDebugMode() & DebugDrawModes.DRAW_WIREFRAME) != 0) {
          Vector3f color = Stack.alloc(Vector3f.class);
          color.set(255f, 255f, 255f);
          switch (colObj.getActivationState()) {
            case CollisionObject.ACTIVE_TAG:
              color.set(255f, 255f, 255f);
              break;
            case CollisionObject.ISLAND_SLEEPING:
              color.set(0f, 255f, 0f);
              break;
            case CollisionObject.WANTS_DEACTIVATION:
              color.set(0f, 255f, 255f);
              break;
            case CollisionObject.DISABLE_DEACTIVATION:
              color.set(255f, 0f, 0f);
              break;
            case CollisionObject.DISABLE_SIMULATION:
              color.set(255f, 255f, 0f);
              break;
            default: {
              color.set(255f, 0f, 0f);
            }
          }

          debugDrawObject(colObj.getWorldTransform(tmpTrans), colObj.getCollisionShape(), color);
        }
        if (debugDrawer != null && (debugDrawer.getDebugMode() & DebugDrawModes.DRAW_AABB) != 0) {
          colorvec.set(1f, 0f, 0f);
          colObj.getCollisionShape().getAabb(colObj.getWorldTransform(tmpTrans), minAabb, maxAabb);
          debugDrawer.drawAabb(minAabb, maxAabb, colorvec);
        }
      }

      Vector3f wheelColor = Stack.alloc(Vector3f.class);
View Full Code Here

TOP

Related Classes of com.bulletphysics.collision.dispatch.CollisionObject

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.