Package com.bulletphysics.linearmath

Examples of com.bulletphysics.linearmath.Transform


      }
    }
  }
 
  protected void gimpacttrimeshpart_vs_plane_collision(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, StaticPlaneShape shape1, boolean swapped) {
    Transform orgtrans0 = body0.getWorldTransform(Stack.alloc(Transform.class));
    Transform orgtrans1 = body1.getWorldTransform(Stack.alloc(Transform.class));

    StaticPlaneShape planeshape = shape1;
    Vector4f plane = Stack.alloc(Vector4f.class);
    PlaneShape.get_plane_equation_transformed(planeshape, orgtrans1, plane);
View Full Code Here


    linVelA.sub(toA.origin, fromA.origin);
    linVelB.sub(toB.origin, fromB.origin);
   
    float lambda = 0f;
   
    Transform interpolatedTransA = Stack.alloc(fromA);
    Transform interpolatedTransB = Stack.alloc(fromB);

    // take relative motion
    Vector3f r = Stack.alloc(Vector3f.class);
    r.sub(linVelA, linVelB);
   
    Vector3f v = Stack.alloc(Vector3f.class);

    tmp.negate(r);
    MatrixUtil.transposeTransform(tmp, tmp, fromA.basis);
    Vector3f supVertexA = convexA.localGetSupportingVertex(tmp, Stack.alloc(Vector3f.class));
    fromA.transform(supVertexA);
   
    MatrixUtil.transposeTransform(tmp, r, fromB.basis);
    Vector3f supVertexB = convexB.localGetSupportingVertex(tmp, Stack.alloc(Vector3f.class));
    fromB.transform(supVertexB);
   
    v.sub(supVertexA, supVertexB);
   
    int maxIter = MAX_ITERATIONS;

    Vector3f n = Stack.alloc(Vector3f.class);
    n.set(0f, 0f, 0f);
    boolean hasResult = false;
    Vector3f c = Stack.alloc(Vector3f.class);

    float lastLambda = lambda;

    float dist2 = v.lengthSquared();
    //#ifdef BT_USE_DOUBLE_PRECISION
    //  btScalar epsilon = btScalar(0.0001);
    //#else
    float epsilon = 0.0001f;
    //#endif
    Vector3f w = Stack.alloc(Vector3f.class), p = Stack.alloc(Vector3f.class);
    float VdotR;

    while ((dist2 > epsilon) && (maxIter--) != 0) {
      tmp.negate(v);
      MatrixUtil.transposeTransform(tmp, tmp, interpolatedTransA.basis);
      convexA.localGetSupportingVertex(tmp, supVertexA);
      interpolatedTransA.transform(supVertexA);
     
      MatrixUtil.transposeTransform(tmp, v, interpolatedTransB.basis);
      convexB.localGetSupportingVertex(tmp, supVertexB);
      interpolatedTransB.transform(supVertexB);
     
      w.sub(supVertexA, supVertexB);

      float VdotW = v.dot(w);
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;

    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);
      localTransform.setRotation(orn);
      ((CompoundShape)colShape).addChildShape(localTransform, cylinderShape);
    }

    collisionShapes.add(colShape);
View Full Code Here

                  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);
                  p2p.setting.impulseClamp = mousePickClamping;

                  dynamicsWorld.addConstraint(p2p);
View Full Code Here

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

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

  }
 
  public void shootTrimesh(Vector3f destination) {
    if (dynamicsWorld != null) {
      float mass = 4f;
      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

//      return;
//    }

    if (shape.getShapeType() == BroadphaseNativeType.COMPOUND_SHAPE_PROXYTYPE) {
      CompoundShape compoundShape = (CompoundShape) shape;
      Transform childTrans = transformsPool.get();
      for (int i = compoundShape.getNumChildShapes() - 1; i >= 0; i--) {
        compoundShape.getChildTransform(i, childTrans);
        CollisionShape colShape = compoundShape.getChildShape(i);
        drawOpenGL(gl, childTrans, colShape, color, debugMode);
      }
View Full Code Here

      Quat4f qFrom = Stack.alloc(Quat4f.class);
      Quat4f qTo = Stack.alloc(Quat4f.class);
      QuaternionUtil.setRotation(qFrom, new Vector3f(1f, 0f, 0f), 0f);
      QuaternionUtil.setRotation(qTo, new Vector3f(1f, 0f, 0f), 0.7f);

      Transform from = Stack.alloc(Transform.class);
      Transform to = Stack.alloc(Transform.class);
      from.basis.set(qFrom);
      from.origin.set(source[i]);
      to.basis.set(qTo);
      to.origin.set(dest[i]);
     
View Full Code Here

    Quat4f qFrom = Stack.alloc(Quat4f.class);
    Quat4f qTo = Stack.alloc(Quat4f.class);
    QuaternionUtil.setRotation(qFrom, new Vector3f(1f, 0f, 0f), 0f);
    QuaternionUtil.setRotation(qTo, new Vector3f(1f, 0f, 0f), 0.7f);
    for (int i=0; i<NUMRAYS_IN_BAR; i++) {
      Transform from = Stack.alloc(Transform.class);
      from.basis.set(qFrom);
      from.origin.set(source[i]);

      Transform to = Stack.alloc(Transform.class);
      to.basis.set(qTo);
      to.origin.set(dest[i]);

      Vector3f linVel = Stack.alloc(Vector3f.class);
      Vector3f angVel = Stack.alloc(Vector3f.class);

      TransformUtil.calculateVelocity(from, to, 1f, linVel, angVel);
      Transform T = Stack.alloc(Transform.class);
      TransformUtil.integrateTransform(from, linVel, angVel, hit_fraction[i], T);
      drawCube(gl, T);
    }
    gl.glEnable(GL_LIGHTING);
  }
View Full Code Here

    //#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();
    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);
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.