Package com.bulletphysics.collision.shapes

Examples of com.bulletphysics.collision.shapes.BoxShape


        // Add dynamic agents (mass != 0).
        if (rand.nextDouble() < 1 && i < 1000) {
            float kantenLaenge = 1 + ((float) (i)) / 50 + (float) rand.nextGaussian();
            CollisionShape box1;
            if (rand.nextDouble() < 0.9) {
                box1 = new BoxShape(new Vector3f(kantenLaenge, kantenLaenge, kantenLaenge));
            } else {
                box1 = new SphereShape(kantenLaenge);
            }
            env.getCollisionShapes().add(box1);
            env.addAgent(new Agent3D(
View Full Code Here


        positionOnPredecessor.y * this.getSize().y,
        positionOnPredecessor.z * this.getSize().z
        ));
   
    // Create rigidbody in physicsworld.
    BoxShape box = new BoxShape(size);
    Vector3f localInertia = new Vector3f (0,0,0);
    Transform transform = new Transform();
    transform.setIdentity();
    transform.origin.set(this.position);   
    DefaultMotionState motionState = new DefaultMotionState(transform);
    box.calculateLocalInertia(mass, localInertia);
    RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(
        this.mass, motionState, box, localInertia);
    RigidBody body = new RigidBody(rbInfo);
    this.getDynamicsWorld().addRigidBody(body);
    this.body = body;
View Full Code Here

      EvolvableBoxAgent3DGenome genome
      ) {
    super(
        id,
        env,
        new BoxShape(size),   // Agent's CollisionShape is always a box.
        initialPosition,
        null,           // There's no initial rotation.
        size.x * size.y * size.z); // Mass is equal to volume.
    this.size = size;
    this.mass = size.x * size.y * size.z;
 
View Full Code Here

    }

    public void addFloor(Box floor) {
        float mass = 0f; // make it static
        // create the CollisionShape
        CollisionShape groundShape = new BoxShape(new Vector3f((float) floor.getXExtent(), (float) floor.getYExtent(), (float) floor.getZExtent()));
        // set initial transform based on floor
        Transform groundTransform = new Transform();
        groundTransform.setIdentity();
        groundTransform.origin.set(new Vector3f(floor.getTranslation().getXf(), floor.getTranslation().getYf(), floor.getTranslation().getZf()));
        Vector3f localInertia = new Vector3f(0, 0, 0);
View Full Code Here

         // setup the physics
        float mass = 10.0f;
        // set extent based on box
        Vector3f halfExtents = new Vector3f((float) box.getXExtent(),
                (float) box.getYExtent(), (float) box.getZExtent());
        BoxShape shape = new BoxShape(halfExtents);
        // fix local inertia
        Vector3f localInertia = new Vector3f(0, 0, 0);
        shape.calculateLocalInertia(mass, localInertia);
        // set initial transform based on box
        Transform startTransform = new Transform();
        startTransform.setIdentity();
        startTransform.origin.set(box.getTranslation().getXf(), box.getTranslation().getYf(), box.getTranslation().getZf());
        MotionStateBind motionState = new MotionStateBind(startTransform);
View Full Code Here

    dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collision_config);

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

    //#ifdef FORCE_ZAXIS_UP
    //m_cameraUp = btVector3(0,0,1);
    //m_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 SimpleBroadphase();
    overlappingPairCache = new DbvtBroadphase();
    constraintSolver = new SequentialImpulseConstraintSolver();
    dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration);
    //#ifdef FORCE_ZAXIS_UP
    //dynamicsWorld.setGravity(new Vector3f(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 = 4 * 3 /* sizeof(btVector3) */;
    int indexStride = 3 * 4 /* 3*sizeof(int) */;

    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());

    Vector3f tmp = new Vector3f();
    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 = 0f; // 20f * (float)Math.sin(i * wl) * (float)Math.cos(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
        tmp.set(
            (i - NUM_VERTS_X * 0.5f) * TRIANGLE_SIZE,
            height,
            (j - NUM_VERTS_Y * 0.5f) * TRIANGLE_SIZE);

        int index = i + j * NUM_VERTS_X;
        vertices.putFloat((index * 3 + 0) * 4, tmp.x);
        vertices.putFloat((index * 3 + 1) * 4, tmp.y);
        vertices.putFloat((index * 3 + 2) * 4, tmp.z);
        //#endif
      }
    }

    //int index=0;
    gIndices.clear();
    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.0f, 0.5f, 2.0f));
    collisionShapes.add(chassisShape);

    CompoundShape compound = new CompoundShape();
    collisionShapes.add(compound);
    Transform localTrans = new Transform();
View Full Code Here

    startTransform.origin.set(0f, -2f, 0f);

    CollisionShape colShape;

    if (USE_BOX_SHAPE) {
      colShape = new BoxShape(new Vector3f(1f, 1f, 1f));
    }
    else {
      colShape = new CompoundShape();
      CollisionShape cylinderShape = new CylinderShapeX(new Vector3f(4, 1, 1));
      CollisionShape boxShape = new BoxShape(new Vector3f(4f, 1f, 1f));
      Transform localTransform = new Transform();
      localTransform.setIdentity();
      ((CompoundShape)colShape).addChildShape(localTransform, boxShape);
      Quat4f orn = new Quat4f();
      QuaternionUtil.setEuler(orn, BulletGlobals.SIMD_HALF_PI, 0f, 0f);
View Full Code Here

    float mass = 0f;
    Transform startTransform = new Transform();
    startTransform.setIdentity();

    CollisionShape staticboxShape1 = new BoxShape(new Vector3f(200f, 1f, 200f)); // floor
    CollisionShape staticboxShape2 = new BoxShape(new Vector3f(1f, 50f, 200f)); // left wall
    CollisionShape staticboxShape3 = new BoxShape(new Vector3f(1f, 50f, 200f)); // right wall
    CollisionShape staticboxShape4 = new BoxShape(new Vector3f(200f, 50f, 1f)); // front wall
    CollisionShape staticboxShape5 = new BoxShape(new Vector3f(200f, 50f, 1f)); // back wall

    CompoundShape staticScenario = new CompoundShape(); // static scenario

    startTransform.origin.set(0f, 0f, 0f);
    staticScenario.addChildShape(startTransform, staticboxShape1);
    startTransform.origin.set(-200f, 25f, 0f);
    staticScenario.addChildShape(startTransform, staticboxShape2);
    startTransform.origin.set(200f, 25f, 0f);
    staticScenario.addChildShape(startTransform, staticboxShape3);
    startTransform.origin.set(0f, 25f, 200f);
    staticScenario.addChildShape(startTransform, staticboxShape4);
    startTransform.origin.set(0f, 25f, -200f);
    staticScenario.addChildShape(startTransform, staticboxShape5);

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

    RigidBody staticBody = localCreateRigidBody(mass, startTransform, staticScenario);

    staticBody.setCollisionFlags(staticBody.getCollisionFlags() | CollisionFlags.STATIC_OBJECT);

    // enable custom material callback
    //staticBody.setCollisionFlags(staticBody.getCollisionFlags() | CollisionFlags.CUSTOM_MATERIAL_CALLBACK);

    // static plane
    Vector3f normal = new Vector3f(0.4f, 1.5f, -0.4f);
    normal.normalize();
    CollisionShape staticplaneShape6 = new StaticPlaneShape(normal, 0f); // A plane

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

    RigidBody staticBody2 = localCreateRigidBody(mass, startTransform, staticplaneShape6);

    staticBody2.setCollisionFlags(staticBody2.getCollisionFlags() | CollisionFlags.STATIC_OBJECT);

    for (int i=0; i<9; i++) {
      CollisionShape boxShape = new BoxShape(new Vector3f(1f, 1f, 1f));
      startTransform.origin.set(2f * i - 5f, 2f, -3f);
      localCreateRigidBody(1, startTransform, boxShape);
    }
  }
View Full Code Here

        // you can comment out any of the specific cases, and use the default
        // the benefit of 'default' is that it approximates the actual collision shape including collision margin
       
        switch (shape.getShapeType()) {
          case BOX_SHAPE_PROXYTYPE: {
            BoxShape boxShape = (BoxShape) shape;
            Vector3f halfExtent = boxShape.getHalfExtentsWithMargin(vectorsPool.get());
            gl.glScalef(2f * halfExtent.x, 2f * halfExtent.y, 2f * halfExtent.z);
            gl.drawCube(1f);
            vectorsPool.release(halfExtent);
            useWireframeFallback = false;
            break;
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.