Package com.bulletphysics.linearmath

Examples of com.bulletphysics.linearmath.Transform


  private TypedConstraint[] joints = new TypedConstraint[JOINT_COUNT];

  public TestRig(DynamicsWorld ownerWorld, Vector3f positionOffset, boolean fixed) {
    this.ownerWorld = ownerWorld;

    Transform tmpTrans = new Transform();

    Vector3f up = new Vector3f();
    up.set(0.0f, 1.0f, 0.0f);

    //
    // Setup geometry
    //
    float bodySize  = 0.25f;
    float legLength = 0.45f;
    float foreLegLength = 0.75f;
    shapes[0] = new CapsuleShape(bodySize, 0.10f);
    int i;
    for ( i=0; i<NUM_LEGS; i++)
    {
      shapes[1 + 2*i] = new CapsuleShape(0.10f, legLength);
      shapes[2 + 2*i] = new CapsuleShape(0.08f, foreLegLength);
    }

    //
    // Setup rigid bodies
    //
    float height = 0.5f;
    Transform offset = new Transform();
    offset.setIdentity();
    offset.origin.set(positionOffset);

    // root
    Vector3f root = new Vector3f();
    root.set(0.0f, height, 0.0f);
    Transform transform = new Transform();
    transform.setIdentity();
    transform.origin.set(root);
    tmpTrans.mul(offset, transform);
    if (fixed) {
      bodies[0] = localCreateRigidBody(0.0f, tmpTrans, shapes[0]);
    } else {
      bodies[0] = localCreateRigidBody(1.0f, tmpTrans, shapes[0]);
    }
    // legs
    for ( i=0; i<NUM_LEGS; i++)
    {
      float angle = BulletGlobals.SIMD_2_PI * i / NUM_LEGS;
      float sin = (float)Math.sin(angle);
      float cos = (float)Math.cos(angle);

      transform.setIdentity();
      Vector3f boneOrigin = new Vector3f();
      boneOrigin.set(cos*(bodySize+0.5f*legLength), height, sin*(bodySize+0.5f*legLength));
      transform.origin.set(boneOrigin);

      // thigh
      Vector3f toBone = new Vector3f(boneOrigin);
      toBone.sub(root);
      toBone.normalize();
      Vector3f axis = new Vector3f();
      axis.cross(toBone,up);
      Quat4f q = new Quat4f();
      QuaternionUtil.setRotation(q, axis, BulletGlobals.SIMD_HALF_PI);
      transform.setRotation(q);
      tmpTrans.mul(offset, transform);
      bodies[1+2*i] = localCreateRigidBody(1.0f, tmpTrans, shapes[1+2*i]);

      // shin
      transform.setIdentity();
      transform.origin.set(cos*(bodySize+legLength), height-0.5f*foreLegLength, sin*(bodySize+legLength));
      tmpTrans.mul(offset, transform);
      bodies[2+2*i] = localCreateRigidBody(1.0f, tmpTrans, shapes[2+2*i]);
    }

    // Setup some damping on the bodies
    for (i = 0; i < BODYPART_COUNT; ++i) {
      bodies[i].setDamping(0.05f, 0.85f);
      bodies[i].setDeactivationTime(0.8f);
      bodies[i].setSleepingThresholds(1.6f, 2.5f);
    }

    //
    // Setup the constraints
    //
    HingeConstraint hingeC;
    //ConeTwistConstraint* coneC;

    Transform localA = new Transform();
    Transform localB = new Transform();
    Transform localC = new Transform();

    for ( i=0; i<NUM_LEGS; i++)
    {
      float angle = BulletGlobals.SIMD_2_PI * i / NUM_LEGS;
      float sin = (float)Math.sin(angle);
      float cos = (float)Math.cos(angle);

      // hip joints
      localA.setIdentity();
      localB.setIdentity();
      MatrixUtil.setEulerZYX(localA.basis, 0, -angle,0);
      localA.origin.set(cos*bodySize, 0.0f, sin*bodySize);
      tmpTrans.inverse(bodies[1+2*i].getWorldTransform(new Transform()));
      tmpTrans.mul(tmpTrans, bodies[0].getWorldTransform(new Transform()));
      localB.mul(tmpTrans, localA);
      hingeC = new HingeConstraint(bodies[0], bodies[1+2*i], localA, localB);
      hingeC.setLimit(-0.75f * BulletGlobals.SIMD_2_PI * 0.125f, BulletGlobals.SIMD_2_PI * 0.0625f);
      //hingeC.setLimit(-0.1f, 0.1f);
      joints[2*i] = hingeC;
      ownerWorld.addConstraint(joints[2*i], true);

      // knee joints
      localA.setIdentity();
      localB.setIdentity();
      localC.setIdentity();
      MatrixUtil.setEulerZYX(localA.basis, 0, -angle,0);
      localA.origin.set(cos*(bodySize+legLength), 0.0f, sin*(bodySize+legLength));
      tmpTrans.inverse(bodies[1+2*i].getWorldTransform(new Transform()));
      tmpTrans.mul(tmpTrans, bodies[0].getWorldTransform(new Transform()));
      localB.mul(tmpTrans, localA) ;
      tmpTrans.inverse(bodies[2+2*i].getWorldTransform(new Transform()));
      tmpTrans.mul(tmpTrans, bodies[0].getWorldTransform(new Transform()));
      localC.mul(tmpTrans, localA) ;
      hingeC = new HingeConstraint(bodies[1+2*i], bodies[2+2*i], localB, localC);
      //hingeC.setLimit(-0.01f, 0.01f);
      hingeC.setLimit(- BulletGlobals.SIMD_2_PI * 0.0625f, 0.2f);
      joints[1+2*i] = hingeC;
      ownerWorld.addConstraint(joints[1+2*i], true);
View Full Code Here


    for (int i = 0; i < vehicle.getNumWheels(); i++) {
      // synchronize the wheels with the (interpolated) chassis worldtransform
      vehicle.updateWheelTransform(i, true);
      // draw wheels (cylinders)
      Transform trans = vehicle.getWheelInfo(i).worldTransform;
      GLShapeDrawer.drawOpenGL(gl, trans, wheelShape, wheelColor, getDebugMode());
    }

    super.renderme();
  }
View Full Code Here

  }

  @Override
  public void clientResetScene() {
    gVehicleSteering = 0f;
    Transform tr = new Transform();
    tr.setIdentity();
    carChassis.setCenterOfMassTransform(tr);
    carChassis.setLinearVelocity(new Vector3f(0, 0, 0));
    carChassis.setAngularVelocity(new Vector3f(0, 0, 0));
    dynamicsWorld.getBroadphase().getOverlappingPairCache().cleanProxyFromPairs(carChassis.getBroadphaseHandle(), getDynamicsWorld().getDispatcher());
    if (vehicle != null) {
View Full Code Here

    //#endif //DISABLE_CAMERA

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();

    Transform chassisWorldTrans = new Transform();

    // look at the vehicle
    carChassis.getMotionState().getWorldTransform(chassisWorldTrans);
    cameraTargetPosition.set(chassisWorldTrans.origin);
View Full Code Here

    // JAVA NOTE: added
    dynamicsWorld.setDebugDrawer(new GLDebugDrawer(gl));
   
    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);
        startTransform.origin.set(2f * i, 10f, 1f);
        localCreateRigidBody(1f, startTransform, colShape);
      }
    }

    startTransform.setIdentity();
    staticBody = localCreateRigidBody(mass, startTransform, groundShape);

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

    // enable custom material callback
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);
    }

    // Spawn one ragdoll
View Full Code Here

  }

  @Override
  public void clientResetScene() {
    gVehicleSteering = 0.f;
    Transform tr = new Transform();
    tr.setIdentity();
    carChassis.setCenterOfMassTransform(tr);
    carChassis.setLinearVelocity(new Vector3f(0,0,0));
    carChassis.setAngularVelocity(new Vector3f(0,0,0));
    dynamicsWorld.getBroadphase().getOverlappingPairCache().cleanProxyFromPairs(carChassis.getBroadphaseHandle(),getDynamicsWorld().getDispatcher());
    if (vehicle != null)
    {
      vehicle.resetSuspension();
      for (int i=0;i<vehicle.getNumWheels();i++)
      {
        // synchronize the wheels with the (interpolated) chassis worldtransform
        vehicle.updateWheelTransform(i,true);
      }
    }
    Transform liftTrans = new Transform();
    liftTrans.setIdentity();
    liftTrans.origin.set(liftStartPos);
    liftBody.activate();
    liftBody.setCenterOfMassTransform(liftTrans);
    liftBody.setLinearVelocity(new Vector3f(0,0,0));
    liftBody.setAngularVelocity(new Vector3f(0,0,0));

    Transform forkTrans = new Transform();
    forkTrans.setIdentity();
    forkTrans.origin.set(forkStartPos);
    forkBody.activate();
    forkBody.setCenterOfMassTransform(forkTrans);
    forkBody.setLinearVelocity(new Vector3f(0,0,0));
    forkBody.setAngularVelocity(new Vector3f(0,0,0));

    liftHinge.setLimit(-LIFT_EPS, LIFT_EPS);
    liftHinge.enableAngularMotor(false, 0, 0);

    forkSlider.setLowerLinLimit(0.1f);
    forkSlider.setUpperLinLimit(0.1f);
    forkSlider.setPoweredLinMotor(false);

    Transform loadTrans = new Transform();
    loadTrans.setIdentity();
    loadTrans.origin.set(loadStartPos);
    loadBody.activate();
    loadBody.setCenterOfMassTransform(loadTrans);
    loadBody.setLinearVelocity(new Vector3f(0,0,0));
    loadBody.setAngularVelocity(new Vector3f(0,0,0));
View Full Code Here

    //#endif //DISABLE_CAMERA

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();

    Transform chassisWorldTrans = new Transform();

    // look at the vehicle
    carChassis.getMotionState().getWorldTransform(chassisWorldTrans);
    cameraTargetPosition.set(chassisWorldTrans.origin);
View Full Code Here

    for (int i=0;i<vehicle.getNumWheels();i++)
    {
      // synchronize the wheels with the (interpolated) chassis worldtransform
      vehicle.updateWheelTransform(i,true);
      // draw wheels (cylinders)
      Transform trans = vehicle.getWheelInfo(i).worldTransform;
      GLShapeDrawer.drawOpenGL(gl,trans,wheelShape,wheelColor,getDebugMode()/*,worldBoundsMin,worldBoundsMax*/);
    }
   
    super.renderme();

 
View Full Code Here

    //#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();
      loadStartPos.set(0.0f, -3.5f, 7.0f);
      loadTrans.origin.set(loadStartPos);
      loadBody  = localCreateRigidBody(4, loadTrans, loadCompound);
    }

View Full Code Here

TOP

Related Classes of com.bulletphysics.linearmath.Transform

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.