コード例 #1
0
 @Override
 public void simpleUpdate(float tpf) {
   time += tpf;
   int random = rand.nextInt(2000);
   float mult1 = 1.0f;
   float mult2 = 1.0f;
   if (random < 500) {
     mult1 = 1.0f;
     mult2 = 1.0f;
   } else if (random < 1000) {
     mult1 = -1.0f;
     mult2 = 1.0f;
   } else if (random < 1500) {
     mult1 = 1.0f;
     mult2 = -1.0f;
   } else if (random <= 2000) {
     mult1 = -1.0f;
     mult2 = -1.0f;
   }
   box = batchNode.getChild("Box" + random);
   if (box != null) {
     Vector3f v = box.getLocalTranslation();
     box.setLocalTranslation(
         v.x + FastMath.sin(time * mult1) * 20,
         v.y + (FastMath.sin(time * mult1) * FastMath.cos(time * mult1) * 20),
         v.z + FastMath.cos(time * mult2) * 20);
   }
   terrain.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Y));
 }
コード例 #2
0
 @Override
 public Node clone(boolean cloneMaterials) {
   BatchNode clone = (BatchNode) super.clone(cloneMaterials);
   if (batches.size() > 0) {
     for (Batch b : batches) {
       for (int i = 0; i < clone.children.size(); i++) {
         if (clone.children.get(i).getName().equals(b.geometry.getName())) {
           clone.children.remove(i);
           break;
         }
       }
     }
     clone.needsFullRebatch = true;
     clone.batches.clear();
     clone.batchesByGeom.clear();
     clone.batch();
   }
   return clone;
 }
コード例 #3
0
  public void randomGenerator() {
    for (int i = startAt; i < maxCubes - 1; i++) {
      randomize();
      Geometry box = new Geometry("Box" + i, new Box(Vector3f.ZERO, 1, 1, 1));
      box.setLocalTranslation(
          new Vector3f(
              xPosition.get(xPosition.size() - 1),
              yPosition.get(yPosition.size() - 1),
              zPosition.get(zPosition.size() - 1)));
      batchNode.attachChild(box);
      if (i < 500) {
        box.setMaterial(mat1);
      } else if (i < 1000) {

        box.setMaterial(mat2);
      } else if (i < 1500) {

        box.setMaterial(mat3);
      } else {

        box.setMaterial(mat4);
      }
    }
  }
コード例 #4
0
ファイル: CombatPit.java プロジェクト: ArchDemons/Keeper
  @Override
  protected BatchNode constructFloor() {
    BatchNode root = new BatchNode();
    String modelName =
        AssetsConverter.MODELS_FOLDER
            + "/"
            + roomInstance.getRoom().getCompleteResource().getName();
    Point start = roomInstance.getCoordinates().get(0);
    // Contruct the tiles
    boolean hasDoor = false;

    for (Point p : roomInstance.getCoordinates()) {
      // Figure out which peace by seeing the neighbours
      boolean N = roomInstance.hasCoordinate(new Point(p.x, p.y + 1));
      boolean NE = roomInstance.hasCoordinate(new Point(p.x - 1, p.y + 1));
      boolean E = roomInstance.hasCoordinate(new Point(p.x - 1, p.y));
      boolean SE = roomInstance.hasCoordinate(new Point(p.x - 1, p.y - 1));
      boolean S = roomInstance.hasCoordinate(new Point(p.x, p.y - 1));
      boolean SW = roomInstance.hasCoordinate(new Point(p.x + 1, p.y - 1));
      boolean W = roomInstance.hasCoordinate(new Point(p.x + 1, p.y));
      boolean NW = roomInstance.hasCoordinate(new Point(p.x + 1, p.y + 1));

      if (!hasDoor && !S && N && NE && NW && E && W && !SW && !SE) {
        Spatial part = loadAsset(assetManager, modelName + "14" + ".j3o", false);

        resetAndMoveSpatial(part, start, p);
        hasDoor = true;

        part.move(-TILE_WIDTH / 4, 0, -TILE_WIDTH / 4);
        root.attachChild(part);

        continue;
      }

      Node model = new Node();
      for (int i = 0; i < 2; i++) {
        for (int k = 0; k < 2; k++) {
          // 4 - 8 - walls

          int pieceNumber = 13;
          float yAngle = 0;
          // Determine the piece
          if (i == 0 && k == 0) { // North west corner
            if (!N && !W) {
              pieceNumber = 1;
              yAngle = -FastMath.HALF_PI;
            } else if (!S && !E) {
              pieceNumber = 11;
              yAngle = FastMath.HALF_PI;
            } else if ((W || E) && !N) {
              pieceNumber = 0;
              yAngle = FastMath.PI;
            } else if ((N || S) && !W) {
              pieceNumber = 0;
              yAngle = -FastMath.HALF_PI;
            } else if (N && S && !E) {
              pieceNumber = 10;
              yAngle = FastMath.HALF_PI;
            } else if (E && W && !S) {
              pieceNumber = 10;
              // yAngle = FastMath.PI;
            }
          } else if (i == 1 && k == 0) { // North east corner
            if (!N && !E) {
              pieceNumber = 1;
              yAngle = FastMath.PI;
            } else if (!S && !W) {
              pieceNumber = 11;
            } else if ((W || E) && !N) {
              pieceNumber = 0;
              yAngle = FastMath.PI;
            } else if ((N || S) && !E) {
              pieceNumber = 0;
              yAngle = FastMath.HALF_PI;
            } else if ((N || S) && !W) {
              pieceNumber = 10;
              yAngle = -FastMath.HALF_PI;
            } else if (N && S && !W) {
              pieceNumber = 12;
              // yAngle = FastMath.PI;
            } else if (E && W && !S) {
              pieceNumber = 10;
              // yAngle = FastMath.PI;
            }
          } else if (i == 0 && k == 1) { // South west corner
            if (!S && !W) {
              pieceNumber = 1;
            } else if (!N && !E) {
              pieceNumber = 11;
              yAngle = FastMath.PI;
            } else if ((W || E) && !S) {
              pieceNumber = 0;
            } else if ((N || S) && !W) {
              pieceNumber = 0;
              yAngle = -FastMath.HALF_PI;
            } else if (N && S && !E) {
              pieceNumber = 10;
              yAngle = FastMath.HALF_PI;
            } else if (E && W && !N) {
              pieceNumber = 10;
              yAngle = FastMath.PI;
            }
          } else if (i == 1 && k == 1) { // South east corner
            if (!S && !E) {
              pieceNumber = 1;
              yAngle = FastMath.HALF_PI;
            } else if (!N && !W) {
              pieceNumber = 11;
              yAngle = -FastMath.HALF_PI;
            } else if ((W || E) && !S) {
              pieceNumber = 0;
            } else if ((N || S) && !E) {
              pieceNumber = 0;
              yAngle = FastMath.HALF_PI;
            } else if ((N || S) && !W) {
              pieceNumber = 10;
              yAngle = -FastMath.HALF_PI;
            } else if (S && E && !W) {
              pieceNumber = 12;
              // yAngle = FastMath.PI;
            } else if (E && W && !N) {
              pieceNumber = 10;
              yAngle = FastMath.PI;
            }
          }
          // Load the piece
          Spatial part = loadAsset(assetManager, modelName + pieceNumber + ".j3o", false);

          resetAndMoveSpatial(part, start, p);
          if (yAngle != 0) {
            part.rotate(0, yAngle, 0);
          }
          part.move(TILE_WIDTH / 4 - i * TILE_WIDTH / 2, 0, TILE_WIDTH / 4 - k * TILE_WIDTH / 2);
          model.attachChild(part);
        }
      }

      root.attachChild(model);
    }

    // Set the transform and scale to our scale and 0 the transform
    root.move(
        start.x * MapLoader.TILE_WIDTH - MapLoader.TILE_WIDTH / 2,
        0,
        start.y * MapLoader.TILE_HEIGHT - MapLoader.TILE_HEIGHT / 2);
    root.scale(MapLoader.TILE_WIDTH); // Squares anyway...

    return root;
  }
コード例 #5
0
  @Override
  public void simpleInitApp() {
    timer = new NanoTimer();

    batchNode = new SimpleBatchNode("BatchNode");

    xPosition.add(0);
    yPosition.add(0);
    zPosition.add(0);

    mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.White);
    mat1.setColor("GlowColor", ColorRGBA.Blue.mult(10));

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setColor("Color", ColorRGBA.White);
    mat2.setColor("GlowColor", ColorRGBA.Red.mult(10));

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat3.setColor("Color", ColorRGBA.White);
    mat3.setColor("GlowColor", ColorRGBA.Yellow.mult(10));

    mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat4.setColor("Color", ColorRGBA.White);
    mat4.setColor("GlowColor", ColorRGBA.Orange.mult(10));

    randomGenerator();

    // rootNode.attachChild(SkyFactory.createSky(
    //  assetManager, "Textures/SKY02.zip", false));
    inputManager.addMapping("Start Game", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addListener(al, new String[] {"Start Game"});

    getCam().setLocation(new Vector3f(-34.403286f, 126.65158f, 434.791f));
    getCam().setRotation(new Quaternion(0.022630932f, 0.9749435f, -0.18736298f, 0.11776358f));

    batchNode.batch();

    terrain = new Node("terrain");
    terrain.setLocalTranslation(50, 0, 50);
    terrain.attachChild(batchNode);

    flyCam.setMoveSpeed(100);
    rootNode.attachChild(terrain);
    Vector3f pos = new Vector3f(-40, 0, -40);
    batchNode.setLocalTranslation(pos);

    Arrow a = new Arrow(new Vector3f(0, 50, 0));
    Geometry g = new Geometry("a", a);
    g.setLocalTranslation(terrain.getLocalTranslation());
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.setColor("Color", ColorRGBA.Blue);
    g.setMaterial(m);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
    //        SSAOFilter ssao = new SSAOFilter(8.630104f,22.970434f,2.9299977f,0.2999997f);
    //        fpp.addFilter(ssao);
    viewPort.addProcessor(fpp);
    //   viewPort.setBackgroundColor(ColorRGBA.DarkGray);
  }