Esempio n. 1
0
  public Trapeeze(Game game) {
    Cylinder pole = new Cylinder(10, 10, radius, height, true);
    leftPole = new Geometry("leftPole", pole);
    leftPole.rotate(90f * FastMath.DEG_TO_RAD, 0, 0);
    leftPole.setLocalTranslation(-1f, height / 2f, 0f);
    leftPole.setShadowMode(RenderQueue.ShadowMode.Cast);

    rightPole = new Geometry("rightPole", pole);
    rightPole.rotate(90f * FastMath.DEG_TO_RAD, 0, 0);
    rightPole.setLocalTranslation(1f, height / 2f, 0f);
    rightPole.setShadowMode(RenderQueue.ShadowMode.Cast);

    float betweenPoles = rightPole.getLocalTranslation().x - leftPole.getLocalTranslation().x;
    Box seat = new Box(betweenPoles, radius, radius * 4);
    swing = new Geometry("swing", seat);
    swing.rotate(90f * FastMath.DEG_TO_RAD, 0, 0);
    swing.setLocalTranslation(0f, 3, 0f);
    swing.setShadowMode(RenderQueue.ShadowMode.Cast);

    swing.move(-4.0f, 6f, 0.0f);
    leftPole.move(-4.0f, 10f, 0.0f);
    rightPole.move(-4.0f, 10f, 0.0f);

    setTrapeezeMaterial(Main.matOrange);

    collisionShape = CollisionShapeFactory.createBoxShape(leftPole);
    collisionShape = CollisionShapeFactory.createBoxShape(rightPole);
    collisionShape = CollisionShapeFactory.createBoxShape(swing);

    this.attachChild(leftPole);
    this.attachChild(swing);
  }
Esempio n. 2
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);
    }
  }
Esempio n. 3
0
  @Override
  public void simpleInitApp() {

    Sphere sphereMesh = new Sphere(32, 32, 1f);

    Geometry spherePlainGeo = new Geometry("rough sphere", sphereMesh);
    Material spherePlainMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    spherePlainMat.setFloat("Shininess", 0f); // [1,128]
    spherePlainMat.setBoolean("UseMaterialColors", true);
    spherePlainMat.setColor("Ambient", ColorRGBA.Black);
    spherePlainMat.setColor("Diffuse", ColorRGBA.Cyan);
    spherePlainMat.setColor("Specular", ColorRGBA.White);
    spherePlainGeo.setMaterial(spherePlainMat);
    spherePlainGeo.move(-2.5f, 0, 0);
    rootNode.attachChild(spherePlainGeo);

    Geometry sphereShinyGeo = new Geometry("normal sphere", sphereMesh);
    Material sphereShinyMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    sphereShinyMat.setBoolean("UseMaterialColors", true);
    sphereShinyMat.setColor("Ambient", ColorRGBA.Black);
    sphereShinyMat.setColor("Diffuse", ColorRGBA.Cyan);
    sphereShinyMat.setColor("Specular", ColorRGBA.White);
    sphereShinyMat.setFloat("Shininess", 4f); // [1,128]
    sphereShinyGeo.setMaterial(sphereShinyMat);
    rootNode.attachChild(sphereShinyGeo);

    Geometry sphereVeryShinyGeo = new Geometry("Smooth sphere", sphereMesh);
    Material sphereVeryShinyMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    sphereVeryShinyMat.setBoolean("UseMaterialColors", true);
    sphereVeryShinyMat.setColor("Ambient", ColorRGBA.Black);
    sphereVeryShinyMat.setColor("Diffuse", ColorRGBA.Cyan);
    sphereVeryShinyMat.setColor("Specular", ColorRGBA.White);
    sphereVeryShinyMat.setFloat("Shininess", 100f); // [1,128]
    sphereVeryShinyGeo.setMaterial(sphereVeryShinyMat);
    sphereVeryShinyGeo.move(2.5f, 0, 0);
    rootNode.attachChild(sphereVeryShinyGeo);

    /** Must add a light to make the lit object visible! */
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(1, 0, -2));
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);
  }
  @Override
  public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.White);
    flyCam.setMoveSpeed(50);

    /** A simple textured sphere */
    Sphere sphereMesh = new Sphere(16, 16, 1);
    Geometry sphereGeo = new Geometry("lit textured sphere", sphereMesh);
    Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Interface/Monkey.png"));
    sphereMat.setBoolean("UseMaterialColors", true);
    sphereMat.setColor("Diffuse", ColorRGBA.Gray);
    sphereMat.setColor("Ambient", ColorRGBA.Gray);
    // alpha test start
    sphereMat.getAdditionalRenderState().setAlphaTest(true);
    sphereMat.getAdditionalRenderState().setAlphaFallOff(.5f);
    sphereGeo.setQueueBucket(Bucket.Transparent);
    // alpha test end
    sphereGeo.setMaterial(sphereMat);
    sphereGeo.move(-2f, 0f, 0f);
    sphereGeo.rotate(FastMath.DEG_TO_RAD * -90, FastMath.DEG_TO_RAD * 120, 0f);
    rootNode.attachChild(sphereGeo);

    /**
     * This material turns the box into a stained glass window. The texture has an alpha channel and
     * is partially transparent.
     */
    Box windowMesh = new Box(new Vector3f(0f, 0f, 0f), 1f, 1.4f, 0.01f);
    Geometry windowGeo = new Geometry("stained glass window", windowMesh);
    Material windowMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    windowMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/mucha-window.png"));
    windowMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    windowGeo.setMaterial(windowMat);
    windowGeo.setQueueBucket(Bucket.Transparent);
    windowGeo.setMaterial(windowMat);
    windowGeo.move(1, 0, 0);
    rootNode.attachChild(windowGeo);

    /**
     * A box with its material color "bleeding" through. The texture has an alpha channel and is
     * partially transparent.
     */
    Cylinder logMesh = new Cylinder(32, 32, 1, 8, true);
    TangentBinormalGenerator.generate(logMesh);
    Geometry logGeo = new Geometry("Bleed-through color", logMesh);
    Material logMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    logMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Bark/bark_diffuse.png"));
    logMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Bark/bark_normal.png"));
    logMat.setBoolean("UseMaterialColors", true);
    logMat.setColor("Diffuse", ColorRGBA.Orange);
    logMat.setColor("Ambient", ColorRGBA.Gray);
    logMat.setBoolean("UseAlpha", true);
    logGeo.setMaterial(logMat);
    logGeo.move(0f, 0f, -2f);
    logGeo.rotate(0f, FastMath.DEG_TO_RAD * 90, 0f);
    rootNode.attachChild(logGeo);

    /** Must add a light to make the lit object visible! */
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(1, 0, -2).normalizeLocal());
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);
    AmbientLight ambient = new AmbientLight();
    ambient.setColor(ColorRGBA.White);
    rootNode.addLight(ambient);
  }