예제 #1
0
  @Override
  public void simpleUpdate(float tpf) {
    Vector3f intersection = getWorldIntersection();
    updateHintText(intersection);

    if (raiseTerrain) {

      if (intersection != null) {
        adjustHeight(intersection, 64, tpf * 60);
      }
    } else if (lowerTerrain) {
      if (intersection != null) {
        adjustHeight(intersection, 64, -tpf * 60);
      }
    }

    if (terrain != null && intersection != null) {
      float h = terrain.getHeight(new Vector2f(intersection.x, intersection.z));
      Vector3f tl = terrain.getWorldTranslation();
      marker.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));
      markerNormal.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));

      Vector3f normal = terrain.getNormal(new Vector2f(intersection.x, intersection.z));
      ((Arrow) markerNormal.getMesh()).setArrowExtent(normal);
    }
  }
예제 #2
0
  /** Business logic */
  public static MotionPath createMotionPath(
      TerrainQuad terrain, Cell[][] cells, Cell from, Cell to, Creature creature)
      throws NoReachablePathException {
    if (creature instanceof AirborneCreature) {
      AirborneCreature airCreature = (AirborneCreature) creature;
      airCreature.takeOff();
    }

    if (!to.creatureAllowed(creature)) {
      throw new NoReachablePathException();
    }

    MotionPath motionPath = new MotionPath();

    /** Different for air creatures */
    if (creature instanceof AirborneCreature) {
      // Add take off waypoint
      Vector3f takeOffWayPoint =
          new Vector3f(
              from.getWorldCoordinates().x, airCreatureHeight, from.getWorldCoordinates().z);

      motionPath.addWayPoint(creature.getModel().getLocalTranslation());
      motionPath.addWayPoint(takeOffWayPoint);

      int numSteps = 100;
      float diffX = (to.getWorldCoordinates().x - from.getWorldCoordinates().x) / (float) numSteps;
      float diffZ = (to.getWorldCoordinates().z - from.getWorldCoordinates().z) / (float) numSteps;

      for (int i = 0; i < numSteps; i++) {
        float x = from.getWorldCoordinates().x + i * diffX;
        float z = from.getWorldCoordinates().z + i * diffZ;
        // float y = terrain.getHeight(new Vector2f(x, z)) + airCreatureHeight;
        motionPath.addWayPoint(new Vector3f(x, airCreatureHeight, z));
      }
    } else {
      List<Cell> findPath = findPath(cells, from, to, creature);

      Cell previousCell = null;

      for (Cell cell : findPath) {
        if (previousCell != null) {
          // Smoothen path
          int numParts = 5;
          float xDiff =
              (cell.getWorldCoordinates().x - previousCell.getWorldCoordinates().x)
                  / (float) numParts;
          float zDiff =
              (cell.getWorldCoordinates().z - previousCell.getWorldCoordinates().z)
                  / (float) numParts;

          for (int i = 0; i < numParts; i++) {
            float x = previousCell.getWorldCoordinates().x + i * xDiff;
            float z = previousCell.getWorldCoordinates().z + i * zDiff;
            Vector3f part = null;

            if (creature instanceof SeaCreature) {
              System.out.println("test");
              part = new Vector3f(x, 0, z);
            } else {
              part = new Vector3f(x, terrain.getHeight(new Vector2f(x, z)) - 100, z);
            }

            motionPath.addWayPoint(part);
          }
        }

        if (creature instanceof SeaCreature) {
          Vector3f old = cell.getWorldCoordinates();
          motionPath.addWayPoint(
              new Vector3f(old.x, creature.getModel().getLocalTranslation().y, old.z));
        } else {
          motionPath.addWayPoint(cell.getWorldCoordinates());
        }

        previousCell = cell;
      }
    }

    motionPath.setCycle(false);
    return motionPath;
  }