Package edu.ups.gamedev.terrain

Source Code of edu.ups.gamedev.terrain.HeightMap

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package edu.ups.gamedev.terrain;

import com.jme.app.SimpleGame;
import com.jme.light.PointLight;
import com.jme.light.SpotLight;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Skybox;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.lwjgl.LWJGLTextureState;
import com.jmex.terrain.TerrainPage;
import com.jmex.terrain.util.AbstractHeightMap;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.JFileChooser;

/**
*
* @author scanfield
*/
public class HeightMap extends SimpleGame {
  AbstractHeightMap hm;
  SpotLight spotlight;
  Skybox sb;

  /**
   * @param args
   *            the command line arguments
   */
  public static void main(String[] args) {
    // Create a file chooser
    /*final JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = fc.showOpenDialog(null);

    File file = fc.getSelectedFile();
    */
    File file = new File("/Users/scanfield/Desktop/mapOne");
    System.out.println(System.getProperties());
    HeightMap app = new HeightMap(file);
    app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
    app.start();
  }

  File levelFile;
  MaterialTerrainPage tp;
 
  public HeightMap(File levelFile) {
    super();
    this.levelFile = levelFile;
  }

  public static TextureState getTextureState() {
    /* We assume LWJGL, this logic can change later */
    return new LWJGLTextureState();
  }

  Box box;
 
  protected void simpleUpdate() {
    Vector3f point = cam.getLocation().clone();
    point.x += 10.0f;
    point.y = tp.getHeight( point ) + 2.5f;
    box.setLocalTranslation( point );
   
    Vector3f normal = new Vector3f();
    tp.getSurfaceNormal( point,  normal );
    box.rotateUpTo( normal );
  }

  @Override
  protected void simpleInitGame() {
    try {
     
      box = new Box( "MyBox", new Vector3f( -2.0f, -2.0f, -2.0f ), new Vector3f( 2.0f, 2.0f, 2.0f ));
      box.setRandomColors();
      //box.setSolidColor( new ColorRGBA( 1.0f, 1.0f, 1.0f, 1.0f) );
      rootNode.attachChild( box );

      cam.setFrustumPerspective(45.0f, (float) display.getWidth()
          / (float) display.getHeight(), 1, 3000);
      cam.update();

      Level myLevel = new Level(levelFile);
      rootNode.attachChild(tp = (MaterialTerrainPage) myLevel.getMap().getTerrain());

      Vector3f loc = new Vector3f(0.0f, 300.0f, 0.0f);
      PointLight pl = new PointLight();
      pl.setLocation(loc);
      pl.setEnabled(true);
      lightState.attach(pl);
      wireState.setEnabled(false);
    } catch (FileNotFoundException ex) {
      ex.printStackTrace();
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
}
TOP

Related Classes of edu.ups.gamedev.terrain.HeightMap

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.