Exemple #1
0
  @Override
  public void simpleInitApp() {
    // add a random cube
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.randomColor());
    geom.setMaterial(mat);
    geom.move(
        (FastMath.nextRandomFloat() * 10) - 5,
        (FastMath.nextRandomFloat() * 10) - 5,
        (FastMath.nextRandomFloat() * -10));
    rootNode.attachChild(geom);

    // add saved cubes
    String userHome = System.getProperty("user.home");
    BinaryImporter importer = BinaryImporter.getInstance();
    importer.setAssetManager(assetManager);
    try {
      File file = new File(userHome + "/mycoolgame/savedgame.j3o");
      Node sceneNode = (Node) importer.load(file);
      sceneNode.setName("My restored node");
      rootNode.attachChild(sceneNode);
      Logger.getLogger(SaveAndLoad.class.getName()).log(Level.INFO, "Success: Loaded saved node.");
    } catch (IOException ex) {
      Logger.getLogger(SaveAndLoad.class.getName())
          .log(Level.INFO, "Warning: Could not load saved node.", ex);
    }
  }
 /**
  * This method applies the variation to the particle with already set velocity.
  *
  * @param particle the particle to be affected
  */
 protected void applyVelocityVariation(Particle particle) {
   particle.velocity.set(initialVelocity);
   temp.set(FastMath.nextRandomFloat(), FastMath.nextRandomFloat(), FastMath.nextRandomFloat());
   temp.multLocal(2f);
   temp.subtractLocal(1f, 1f, 1f);
   temp.multLocal(initialVelocity.length());
   particle.velocity.interpolate(temp, velocityVariation);
 }
 @Override
 public void getRandomPoint(Vector3f store) {
   do {
     store.x = (FastMath.nextRandomFloat() * 2f - 1f) * radius;
     store.y = (FastMath.nextRandomFloat() * 2f - 1f) * radius;
     store.z = (FastMath.nextRandomFloat() * 2f - 1f) * radius;
   } while (store.distance(center) > radius);
 }
Exemple #4
0
    public Hallway(Vector3f start, float xi, float zi) {
      float x = start.getX() + xi;
      float z = start.getZ() + zi;
      float rng, dist;
      int len = 0;
      int spread = 0;
      int lenMax = FastMath.nextRandomInt(HALL_LENGTH_MIN, HALL_LENGTH_MAX);
      boolean b = false;
      // Make sure both xi and zi have an absolute value of 1:
      xi = A.sign(xi);
      zi = A.sign(zi);
      // Assign the first 2 corners:
      corners[0] =
          new Vector3f(
              (zi * (HALL_WIDTH - 1)) + x,
              start.getY(),
              (xi * (HALL_WIDTH - 1)) + z); // Bottom Left
      corners[1] =
          new Vector3f(
              (-zi * (HALL_WIDTH - 1)) + x,
              start.getY(),
              (-xi * (HALL_WIDTH - 1)) + z); // Bottom Right
      Vector3f left = corners[0].clone();
      Vector3f right = corners[1].clone();
      ArrayList<HallData> newHalls = new ArrayList(1);
      while (len <= lenMax) {
        if (world.get(left) != null && world.get(left).contains("h")) {
          b = true;
        }
        if (world.get(right) != null && world.get(right).contains("h")) {
          b = true;
        }
        // Check each of the spaces in this step for hallway:
        if (b) {
          right.addLocal(-xi, 0, -zi);
          left.addLocal(-xi, 0, -zi);
          break;
        }
        world.put(left.clone(), "h");
        world.put(right.add(zi, 0, xi), "h");
        world.put(right.clone(), "h");
        // Check distance & random to see if more hallways should be created:
        dist = left.distance(Vector3f.ZERO);
        rng = FastMath.nextRandomFloat();
        if (dist < HALL_MAX_RADIUS && spread > HALL_SPREAD && len < lenMax) {
          if (rng < 0.13f) {
            newHalls.add(new HallData(left.clone(), zi, xi));
            spread = 0;
          } else if (rng < 0.26f) {
            newHalls.add(new HallData(right.clone(), -zi, -xi));
            spread = 0;
          } else if (rng < 0.33f) {
            newHalls.add(new HallData(left.clone(), zi, xi));
            newHalls.add(new HallData(right.clone(), -zi, -xi));
            spread = 0;
          }
        }
        x += xi;
        z += zi;
        spread++;
        len++;
        left.addLocal(xi, 0, zi);
        right.addLocal(xi, 0, zi);
      }
      corners[2] = right.clone(); // Top Right
      corners[3] = left.clone(); // Top Left

      // Generate hallways:
      int j = 0;
      while (j < newHalls.size()) {
        hallways.add(new Hallway(newHalls.get(j).start, newHalls.get(j).xi, newHalls.get(j).zi));
        j++;
      }

      // Return if there's no hallway to generate (0 in size):
      float xs = FastMath.abs(corners[1].getX() - corners[3].getX()) + 1;
      float zs = FastMath.abs(corners[1].getZ() - corners[3].getZ()) + 1;
      if (Math.min(FastMath.abs(xs), FastMath.abs(zs)) < 1) {
        return;
      }

      // Generate the front wall:
      walls.add(new Wall(left.add(xi, 0, zi), -zi, -xi, HALL_WIDTH * 2 - 1));
      walls.add(new Wall(left.add(zi, 0, xi), -xi, -zi, len + 1));
      walls.add(new Wall(right.add(-zi, 0, -xi), -xi, -zi, len + 1));

      // Generate the actual floor:
      float xloc = (corners[3].getX() + corners[1].getX()) * 0.5f;
      float zloc = (corners[3].getZ() + corners[1].getZ()) * 0.5f;
      NPCManager.addNew("grunt", new Vector3f(xloc, start.getY(), zloc).mult(ZS).add(0, 5, 0));
      center = new Vector3f(xloc, start.getY() - 0.5f, zloc);
      floor = geoFloor(center, xs, zs, T.getMaterialPath("BC_Tex"), new Vector2f(zs, xs), true);
      map.add(floor);
    }