コード例 #1
0
  /** Removes the from scene. */
  public void removeFromScene() {
    MTComponent cursorTraceContainer = null;
    MTCanvas canvas = scene.getCanvas();

    /*
    //Re-use cursor trace group which is always on top for this menu
    MTComponent[] children = canvas.getChildren();
    for (int i = 0; i < children.length; i++) {
    	MTComponent component = children[i];
    	if (component instanceof MTOverlayContainer
    			&&
    		component.getName().equalsIgnoreCase("Cursor Trace group")){
    		cursorTraceContainer  = component;
    		if (cursorTraceContainer.containsChild(this)){
    			cursorTraceContainer.removeChild(this);
    		}
    	}
    }
    */

    //		/*
    // cursor tracer group NOT found in the scene -> add overlay container to canvas
    if (cursorTraceContainer == null) {
      if (canvas.containsChild(overlayGroup)) {
        canvas.removeChild(overlayGroup);
      }
    }
    //		*/
  }
コード例 #2
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);
  }