Package com.bulletphysics.collision.shapes

Examples of com.bulletphysics.collision.shapes.BoxShape


  public final Vector3f boxShapeHalfExtents = new Vector3f();
  public final BoxShape boxShape;

  public ConvexcastBatch() {
    boxShape = new BoxShape(new Vector3f(0f, 0f, 0f));
    ms = 0;
    max_ms = 0;
    min_ms = 9999;
    sum_ms_samples = 0;
    sum_ms = 0;
View Full Code Here


    this(unused, ray_length, min_z, max_z, -10, 10);
  }

  public ConvexcastBatch(boolean unused, float ray_length, float min_z, float max_z, float min_y, float max_y) {
    boxShapeHalfExtents.set(1f, 1f, 1f);
    boxShape = new BoxShape(boxShapeHalfExtents);
    frame_counter = 0;
    ms = 0;
    max_ms = 0;
    min_ms = 9999;
    sum_ms_samples = 0;
View Full Code Here

    this(ray_length, z, -1000, 10);
  }

  public ConvexcastBatch(float ray_length, float z, float min_y, float max_y) {
    boxShapeHalfExtents.set(1f, 1f, 1f);
    boxShape = new BoxShape(boxShapeHalfExtents);
    frame_counter = 0;
    ms = 0;
    max_ms = 0;
    min_ms = 9999;
    sum_ms_samples = 0;
View Full Code Here

    float mass = 0f;
    Transform startTransform = new Transform();
    startTransform.setIdentity();
    startTransform.origin.set(0f, -2f, 0f);

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

    {
      for (i = 0; i < 10; i++) {
        //btCollisionShape* colShape = new btCapsuleShape(0.5,2.0);//boxShape = new btSphereShape(1.f);
View Full Code Here

    dynamicsWorld.setDebugDrawer(new GLDebugDrawer(gl));

    // Setup a big ground box
    {
      CollisionShape groundShape = new BoxShape(new Vector3f(200f, 10f, 200f));
      Transform groundTransform = new Transform();
      groundTransform.setIdentity();
      groundTransform.origin.set(0f, -15f, 0f);
      localCreateRigidBody(0f, groundTransform, groundShape);
    }
View Full Code Here

    //#ifdef FORCE_ZAXIS_UP
    //cameraUp.set(0,0,1);
    //forwardAxis = 1;
    //#endif

    CollisionShape groundShape = new BoxShape(new Vector3f(50,3,50));
    collisionShapes.add(groundShape);
    collisionConfiguration = new DefaultCollisionConfiguration();
    dispatcher = new CollisionDispatcher(collisionConfiguration);
    Vector3f worldMin = new Vector3f(-1000,-1000,-1000);
    Vector3f worldMax = new Vector3f(1000,1000,1000);
    //overlappingPairCache = new AxisSweep3(worldMin,worldMax);
    overlappingPairCache = new DbvtBroadphase();
    constraintSolver = new SequentialImpulseConstraintSolver();
    dynamicsWorld = new DiscreteDynamicsWorld(dispatcher,overlappingPairCache,constraintSolver,collisionConfiguration);
    //#ifdef FORCE_ZAXIS_UP
    //m_dynamicsWorld->setGravity(btVector3(0,0,-10));
    //#endif

    //m_dynamicsWorld->setGravity(btVector3(0,0,0));
    Transform tr = new Transform();
    tr.setIdentity();

    // either use heightfield or triangle mesh
    //#define  USE_TRIMESH_GROUND 1
    //#ifdef USE_TRIMESH_GROUND
    final float TRIANGLE_SIZE=20f;

    // create a triangle-mesh ground
    int vertStride = 3*4;
    int indexStride = 3*4;

    final int NUM_VERTS_X = 20;
    final int NUM_VERTS_Y = 20;
    final int totalVerts = NUM_VERTS_X*NUM_VERTS_Y;

    final int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);

    vertices = ByteBuffer.allocateDirect(totalVerts*vertStride).order(ByteOrder.nativeOrder());
    ByteBuffer gIndices = ByteBuffer.allocateDirect(totalTriangles*3*4).order(ByteOrder.nativeOrder());

    for (int i=0;i<NUM_VERTS_X;i++)
    {
      for (int j=0;j<NUM_VERTS_Y;j++)
      {
        float wl = 0.2f;
        // height set to zero, but can also use curved landscape, just uncomment out the code
        float height = 0.f;//20.f*sinf(float(i)*wl)*cosf(float(j)*wl);
        //#ifdef FORCE_ZAXIS_UP
        //m_vertices[i+j*NUM_VERTS_X].setValue(
        //  (i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
        //  (j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE,
        //  height
        //  );
        //#else
        int idx = (i+j*NUM_VERTS_X)*3*4;
        vertices.putFloat(idx+0*4, (i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE);
        vertices.putFloat(idx+1*4, height);
        vertices.putFloat(idx+2*4, (j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
        //#endif
      }
    }

    //int index=0;
    for (int i=0;i<NUM_VERTS_X-1;i++)
    {
      for (int j=0;j<NUM_VERTS_Y-1;j++)
      {
        gIndices.putInt(j*NUM_VERTS_X+i);
        gIndices.putInt(j*NUM_VERTS_X+i+1);
        gIndices.putInt((j+1)*NUM_VERTS_X+i+1);

        gIndices.putInt(j*NUM_VERTS_X+i);
        gIndices.putInt((j+1)*NUM_VERTS_X+i+1);
        gIndices.putInt((j+1)*NUM_VERTS_X+i);
      }
    }
    gIndices.flip();

    indexVertexArrays = new TriangleIndexVertexArray(totalTriangles,
      gIndices,
      indexStride,
      totalVerts,vertices,vertStride);

    boolean useQuantizedAabbCompression = true;
    groundShape = new BvhTriangleMeshShape(indexVertexArrays,useQuantizedAabbCompression);

    tr.origin.set(0,-4.5f,0);
    //#else
    ////testing btHeightfieldTerrainShape
    //int width=128;
    //int length=128;
    //unsigned char* heightfieldData = new unsigned char[width*length];
    //{
    //  for (int i=0;i<width*length;i++)
    //  {
    //    heightfieldData[i]=0;
    //  }
    //}
    //
    //char*  filename="heightfield128x128.raw";
    //FILE* heightfieldFile = fopen(filename,"r");
    //if (!heightfieldFile)
    //{
    //  filename="../../heightfield128x128.raw";
    //  heightfieldFile = fopen(filename,"r");
    //}
    //if (heightfieldFile)
    //{
    //  int numBytes =fread(heightfieldData,1,width*length,heightfieldFile);
    //  //btAssert(numBytes);
    //  if (!numBytes)
    //  {
    //    printf("couldn't read heightfield at %s\n",filename);
    //  }
    //  fclose (heightfieldFile);
    //}
    //
    //
    //btScalar maxHeight = 20000.f;
    //
    //bool useFloatDatam=false;
    //bool flipQuadEdges=false;
    //
    //btHeightfieldTerrainShape* heightFieldShape = new btHeightfieldTerrainShape(width,length,heightfieldData,maxHeight,upIndex,useFloatDatam,flipQuadEdges);;
    //groundShape = heightFieldShape;
    //
    //heightFieldShape->setUseDiamondSubdivision(true);
    //
    //btVector3 localScaling(20,20,20);
    //localScaling[upIndex]=1.f;
    //groundShape->setLocalScaling(localScaling);
    //
    //tr.setOrigin(btVector3(0,-64.5f,0));
    //
    //#endif //

    collisionShapes.add(groundShape);

    // create ground object
    localCreateRigidBody(0,tr,groundShape);

    //#ifdef FORCE_ZAXIS_UP
    ////   indexRightAxis = 0;
    ////   indexUpAxis = 2;
    ////   indexForwardAxis = 1;
    //btCollisionShape* chassisShape = new btBoxShape(btVector3(1.f,2.f, 0.5f));
    //btCompoundShape* compound = new btCompoundShape();
    //btTransform localTrans;
    //localTrans.setIdentity();
    ////localTrans effectively shifts the center of mass with respect to the chassis
    //localTrans.setOrigin(btVector3(0,0,1));
    //#else
    CollisionShape chassisShape = new BoxShape(new Vector3f(1.f,0.5f,2.f));
    collisionShapes.add(chassisShape);

    CompoundShape compound = new CompoundShape();
    collisionShapes.add(compound);
    Transform localTrans = new Transform();
    localTrans.setIdentity();
    // localTrans effectively shifts the center of mass with respect to the chassis
    localTrans.origin.set(0,1,0);
    //#endif

    compound.addChildShape(localTrans,chassisShape);

    {
      CollisionShape suppShape = new BoxShape(new Vector3f(0.5f,0.1f,0.5f));
      collisionShapes.add(chassisShape);
      Transform suppLocalTrans = new Transform();
      suppLocalTrans.setIdentity();
      // localTrans effectively shifts the center of mass with respect to the chassis
      suppLocalTrans.origin.set(0f,1.0f,2.5f);
      compound.addChildShape(suppLocalTrans, suppShape);
    }

    tr.origin.set(0,0.f,0);

    carChassis = localCreateRigidBody(800,tr,compound);//chassisShape);
    //m_carChassis->setDamping(0.2,0.2);


    {
      CollisionShape liftShape = new BoxShape(new Vector3f(0.5f,2.0f,0.05f));
      collisionShapes.add(liftShape);
      Transform liftTrans = new Transform();
      liftStartPos.set(0.0f, 2.5f, 3.05f);
      liftTrans.setIdentity();
      liftTrans.origin.set(liftStartPos);
      liftBody = localCreateRigidBody(10,liftTrans, liftShape);

      Transform localA = new Transform(), localB = new Transform();
      localA.setIdentity();
      localB.setIdentity();
      MatrixUtil.setEulerZYX(localA.basis, 0, PI_2, 0);
      localA.origin.set(0.0f, 1.0f, 3.05f);
      MatrixUtil.setEulerZYX(localB.basis, 0, PI_2, 0);
      localB.origin.set(0.0f, -1.5f, -0.05f);
      liftHinge = new HingeConstraint(carChassis,liftBody, localA, localB);
      liftHinge.setLimit(-LIFT_EPS, LIFT_EPS);
      dynamicsWorld.addConstraint(liftHinge, true);

      CollisionShape forkShapeA = new BoxShape(new Vector3f(1.0f,0.1f,0.1f));
      collisionShapes.add(forkShapeA);
      CompoundShape forkCompound = new CompoundShape();
      collisionShapes.add(forkCompound);
      Transform forkLocalTrans = new Transform();
      forkLocalTrans.setIdentity();
      forkCompound.addChildShape(forkLocalTrans, forkShapeA);

      CollisionShape forkShapeB = new BoxShape(new Vector3f(0.1f,0.02f,0.6f));
      collisionShapes.add(forkShapeB);
      forkLocalTrans.setIdentity();
      forkLocalTrans.origin.set(-0.9f, -0.08f, 0.7f);
      forkCompound.addChildShape(forkLocalTrans, forkShapeB);

      CollisionShape forkShapeC = new BoxShape(new Vector3f(0.1f,0.02f,0.6f));
      collisionShapes.add(forkShapeC);
      forkLocalTrans.setIdentity();
      forkLocalTrans.origin.set(0.9f, -0.08f, 0.7f);
      forkCompound.addChildShape(forkLocalTrans, forkShapeC);

      Transform forkTrans = new Transform();
      forkStartPos.set(0.0f, 0.6f, 3.2f);
      forkTrans.setIdentity();
      forkTrans.origin.set(forkStartPos);
      forkBody = localCreateRigidBody(5, forkTrans, forkCompound);

      localA.setIdentity();
      localB.setIdentity();
      MatrixUtil.setEulerZYX(localA.basis, 0, 0, PI_2);
      localA.origin.set(0.0f, -1.9f, 0.05f);
      MatrixUtil.setEulerZYX(localB.basis, 0, 0, PI_2);
      localB.origin.set(0.0f, 0.0f, -0.1f);
      forkSlider = new SliderConstraint(liftBody, forkBody, localA, localB, true);
      forkSlider.setLowerLinLimit(0.1f);
      forkSlider.setUpperLinLimit(0.1f);
      forkSlider.setLowerAngLimit(-LIFT_EPS);
      forkSlider.setUpperAngLimit(LIFT_EPS);
      dynamicsWorld.addConstraint(forkSlider, true);
     
      CompoundShape loadCompound = new CompoundShape();
      collisionShapes.add(loadCompound);
      CollisionShape loadShapeA = new BoxShape(new Vector3f(2.0f,0.5f,0.5f));
      collisionShapes.add(loadShapeA);
      Transform loadTrans = new Transform();
      loadTrans.setIdentity();
      loadCompound.addChildShape(loadTrans, loadShapeA);
      CollisionShape loadShapeB = new BoxShape(new Vector3f(0.1f,1.0f,1.0f));
      collisionShapes.add(loadShapeB);
      loadTrans.setIdentity();
      loadTrans.origin.set(2.1f, 0.0f, 0.0f);
      loadCompound.addChildShape(loadTrans, loadShapeB);
      CollisionShape loadShapeC = new BoxShape(new Vector3f(0.1f,1.0f,1.0f));
      collisionShapes.add(loadShapeC);
      loadTrans.setIdentity();
      loadTrans.origin.set(-2.1f, 0.0f, 0.0f);
      loadCompound.addChildShape(loadTrans, loadShapeC);
      loadTrans.setIdentity();
View Full Code Here

        //#define TEST_UNIFORM_SCALING_SHAPE 1
        //#ifdef TEST_UNIFORM_SCALING_SHAPE
        //btConvexShape* childShape = new btBoxShape(btVector3(1.f,1.f,1.f));
        //m_shootBoxShape = new btUniformScalingShape(childShape,0.5f);
        //#else
        shootBoxShape = new BoxShape(new Vector3f(1f, 1f, 1f));
        //#endif//
      }

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

View Full Code Here

  public CharacterDemo(IGL gl) {
    super(gl);
  }
 
  public void initPhysics() throws Exception {
    CollisionShape groundShape = new BoxShape(new Vector3f(50, 3, 50));
    collisionShapes.add(groundShape);

    collisionConfiguration = new DefaultCollisionConfiguration();
    dispatcher = new CollisionDispatcher(collisionConfiguration);
    Vector3f worldMin = new Vector3f(-1000f,-1000f,-1000f);
View Full Code Here

        collisionConfiguration);

    dynamicsWorld.setGravity(new Vector3f(0, -10, 0));

    // create a few basic rigid bodies
    CollisionShape groundShape = new BoxShape(new Vector3f(50.f, 50.f, 50.f));

    // keep track of the shapes, we release memory at exit.
    // make sure to re-use collision shapes among rigid bodies whenever
    // possible!
    ObjectArrayList<CollisionShape> collisionShapes = new ObjectArrayList<CollisionShape>();

    collisionShapes.add(groundShape);

    Transform groundTransform = new Transform();
    groundTransform.setIdentity();
    groundTransform.origin.set(new Vector3f(0.f, -56.f, 0.f));

    {
      float mass = 0f;

      // 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) {
        groundShape.calculateLocalInertia(mass, localInertia);
      }

      // using motionstate is recommended, it provides interpolation
      // capabilities, and only synchronizes 'active' objects
      DefaultMotionState myMotionState = new DefaultMotionState(groundTransform);
View Full Code Here

    dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

    dynamicsWorld.setGravity(new Vector3f(0f, -10f, 0f));

    // create a few basic rigid bodies
    CollisionShape groundShape = new BoxShape(new Vector3f(50f, 50f, 50f));
    //CollisionShape groundShape = new StaticPlaneShape(new Vector3f(0, 1, 0), 50);

    collisionShapes.add(groundShape);

    Transform groundTransform = new Transform();
    groundTransform.setIdentity();
    groundTransform.origin.set(0, -56, 0);

    // We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
    {
      float mass = 0f;

      // 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) {
        groundShape.calculateLocalInertia(mass, localInertia);
      }

      // 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;
View Full Code Here

TOP

Related Classes of com.bulletphysics.collision.shapes.BoxShape

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.