Пример #1
0
  public static Matrix convertMatrix4fToMT4JMatrix(Matrix4f matrix) {
    Matrix mat = new Matrix();
    for (int i = 0; i < 4; i++) {
      float[] col = new float[4];
      matrix.getColumn(i, col);
      try {
        mat.setColumn(i, col);
      } catch (Exception e) {

        e.printStackTrace();
      }
    }
    return mat;
  }
Пример #2
0
  public static Matrix4f convertMT4JMatrixToMatrix4f(Matrix matrix) {
    Matrix4f mat = new Matrix4f();
    for (int i = 0; i < 4; i++) {
      float[] col;
      try {
        col = matrix.getColumn(i);

        try {
          mat.setColumn(i, col);
        } catch (Exception e) {

          e.printStackTrace();
        }
      } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }
    return mat;
  }
Пример #3
0
  public void addObjectsToCollisionDomain() {
    Iterator<Entry<MTComponent, ArrayList<MTTriangleMesh>>> groupIter =
        collisionGroups.entrySet().iterator();

    int collidesWith = 0;
    while (groupIter.hasNext()) {
      collidesWith = ~groupId;

      Entry<MTComponent, ArrayList<MTTriangleMesh>> element = groupIter.next();

      // CollisionShape shape = createMeshShapeFromMTMeshTriangle(element.getValue());
      Iterator<MTTriangleMesh> iter = element.getValue().iterator();

      while (iter.hasNext()) {
        MTComponent comp = iter.next();
        CollisionShape shape = createMeshShapeFromMTMeshTriangle((MTTriangleMesh) comp);

        /*	Transform startTransform = new Transform();
        startTransform.setIdentity();

        Vector3f vec = new Vector3f();
        Vector3D translate = currentMesh.getCenterPointRelativeToParent();
        vec.x = translate.x;
        vec.y = translate.y;
        vec.z = translate.z;

        startTransform.origin.set(vec);*/

        Transform startTransform = new Transform();
        startTransform.setIdentity();
        Matrix mat = element.getKey().getGlobalMatrix();

        Vector3f vec = new Vector3f(0.0f, 0.0f, 0.0f);
        vec.x = mat.m03;
        vec.y = mat.m13;
        vec.z = mat.m23;

        // startTransform.transform(vec);
        // Matrix4f mat = CollisionManager.convertMT4JMatrixToMatrix4f(mesh.get);

        // startTransform.set(mat);
        // startTransform.origin.set(vec);
        // mat4f.m03 = mat4f.m03 + vec.x;
        // mat4f.m13 = mat4f.m13 + vec.y;
        // mat4f.m23 = mat4f.m23 + vec.z;
        // mat4f.setTranslation(vec);

        startTransform.origin.set(vec);

        Vector3f scale = new Vector3f(); // get scale value of global matrix

        Vector3D xVec = new Vector3D(mat.m00, mat.m01, mat.m02);
        Vector3D yVec = new Vector3D(mat.m10, mat.m11, mat.m12);
        Vector3D zVec = new Vector3D(mat.m20, mat.m21, mat.m22);

        scale.x = xVec.length();
        scale.y = yVec.length();
        scale.z = zVec.length();

        float[] scaleVals = new float[3];
        scale.get(scaleVals);

        for (int i = 0; i < 3; i++) // get rotation value by extracting scalation
        {

          try {
            float[] colvals = mat.getRow(i);

            for (int j = 0; j < 3; j++) {
              colvals[j] = colvals[j] / scaleVals[i];
            }
            startTransform.basis.setRow(i, colvals);
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }

        // startTransform.set(mat4f);

        float mass = 5f; // fake mass value only needed correctly if used with dynamic engine
        shape.setLocalScaling(scale);
        GImpactMeshShape sh = (GImpactMeshShape) shape;
        sh.updateBound();

        RigidBody body = localCreateRigidBody(mass, startTransform, shape);

        // get Center Of Mass of Triangle Mesh and write it to MTTriangleMesh
        Vector3f vecCOM = new Vector3f();
        body.getCenterOfMassPosition(vecCOM);
        Vector3D vecComMT4J = new Vector3D(vecCOM.x, vecCOM.y, vecCOM.z);
        // mesh.setCenterOfMass(vecComMT4J);
        // mesh.setMass(100.0f);
        // add Object to Collision World

        collisionWorld.addCollisionObject(body, groupId, (short) collidesWith);

        colObjectToComponent.put(body, comp);

        addCollisionObjectToGroup(
            comp.getParent(), body); // save association between collision objects and groups
      }
      groupId = (short) (groupId << 1); // shift groupId so every group has a unique bit value
    }
    SimulatePreDrawAction calcDynamics =
        new SimulatePreDrawAction(collisionWorld, this, scene.getCanvas());
    calcDynamics.setCurrentTimeStep(1.f / 1000000000000.0f);
    scene.registerPreDrawAction(calcDynamics);
  }