Exemple #1
0
  /**
   * Updates a points arrays with the frustum corners of the provided camera.
   *
   * @param viewCam
   * @param points
   */
  public static void updateFrustumPoints2(Camera viewCam, Vector3f[] points) {
    int w = viewCam.getWidth();
    int h = viewCam.getHeight();

    points[0].set(viewCam.getWorldCoordinates(new Vector2f(0, 0), 0));
    points[1].set(viewCam.getWorldCoordinates(new Vector2f(0, h), 0));
    points[2].set(viewCam.getWorldCoordinates(new Vector2f(w, h), 0));
    points[3].set(viewCam.getWorldCoordinates(new Vector2f(w, 0), 0));

    points[4].set(viewCam.getWorldCoordinates(new Vector2f(0, 0), 1));
    points[5].set(viewCam.getWorldCoordinates(new Vector2f(0, h), 1));
    points[6].set(viewCam.getWorldCoordinates(new Vector2f(w, h), 1));
    points[7].set(viewCam.getWorldCoordinates(new Vector2f(w, 0), 1));
  }
  @Override
  protected void initialize(Application app) {

    ed = getState(EntityDataState.class).getEntityData();
    entities = ed.getEntities(Position.class, ModelType.class);

    // Calculate how big min/max needs to be to incorporate
    // the full view + margin at z = 0
    Camera cam = app.getCamera();
    float z = cam.getViewToProjectionZ(cam.getLocation().z);
    Vector3f worldMin = cam.getWorldCoordinates(new Vector2f(0, 0), z);
    Vector3f worldMax = cam.getWorldCoordinates(new Vector2f(cam.getWidth(), cam.getHeight()), z);
    min = worldMin.addLocal(-margin, -margin, 0);
    max = worldMax.addLocal(margin, margin, 0);
  }
  public static void HighlightModel(Camera cam, InputManager inputManager) {
    CollisionResults results = new CollisionResults();
    Vector2f mouseCoords = new Vector2f(inputManager.getCursorPosition());

    Ray mouseRay =
        new Ray(
            cam.getWorldCoordinates(mouseCoords, 0),
            cam.getWorldCoordinates(mouseCoords, 1)
                .subtractLocal(cam.getWorldCoordinates(mouseCoords, 0))
                .normalizeLocal());
    Main.s_TreeNode.collideWith(mouseRay, results);

    if (results.size() > 0) {
      Spatial target = results.getClosestCollision().getGeometry();
      AmbientLight light = new AmbientLight();
      light.setColor(ColorRGBA.Blue);
      Main.s_TreeNode.addLight(light);
      target.addLight(light);
    }
  }
  public static void MoveModel(Camera cam, InputManager inputManager, Spatial scene) {
    if (Statics.s_PlayerSettingModel == true) {
      CollisionResults results = new CollisionResults();
      Ray ray = new Ray();
      Vector2f click2d = inputManager.getCursorPosition();
      Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 0f);
      Vector3f dir =
          cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 1f)
              .subtractLocal(click3d)
              .normalizeLocal();
      ray.setOrigin(click3d);
      ray.setDirection(dir);
      ray = new Ray(click3d, dir);
      scene.collideWith(ray, results);

      if (results.size() > 0) {
        CollisionResult point = results.getClosestCollision();
        Vector3f destination = point.getContactPoint();
        ObjectHelper.s_Model.setMaterial(ObjectHelper.greenTrans);
        SetModel(destination);
      }
    }
  }