Ok so I have been working and moding this tutorial
http://www.jmonkeyengine.com/wiki/doku.php/jme2_-_flag_rush_tutorial_series
And i have skiped a few things like the sky box and the force field becuase I dont need them right now. I am stuck on the lessons 4 and 5 I cant get them to work. I have copied the FlagRushInputHandler.java right out of the tutorial so thats should be no problem, but when I compile it and run it just gives me the output from lesson 3.
Here is my code that I am working on;
package com.jme;
import java.util.HashMap;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import jmetest.flagrushtut.Lesson3;
import com.jme.app.BaseGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.ChaseCamera;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.thirdperson.ThirdPersonMouseLook;
import com.jme.light.DirectionalLight;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.CullState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.util.MidPointHeightMap;
import com.jmex.terrain.util.ProceduralTextureGenerator;
public class Hummer extends BaseGame {
private TerrainBlock tb;
protected Timer timer;
// Our camera object for viewing the scene
private Camera cam;
// the root node of the scene graph
private Node scene;
private Node player;
//private ChaseCamera chaser;
protected InputHandler input;
private ChaseCamera chaser;
// display attributes for the window. We will keep these values
// to allow the user to change them
private int width, height, depth, freq;
private boolean fullscreen;
/**
* Main entry point of the application
*/
public static void main(String[] args) {
Lesson3 app = new Lesson3();
// We will load our own "fantastic" Flag Rush logo. Yes, I'm an artist.
app.setConfigShowMode(ConfigShowMode.AlwaysShow,
Lesson3.class.getClassLoader()
.getResource("jmetest/data/images/FlagRush.png"));
app.start();
}
/**
* During an update we only look for the escape button and update the timer
* to get the framerate.
*
* @see com.jme.app.SimpleGame#update()
*/
protected void update(float interpolation) {
// update the time to get the framerate
timer.update();
interpolation = timer.getTimePerFrame();
//update the keyboard input (move the player around)
input.update(interpolation);
//update the chase camera to handle the player moving around.
chaser.update(interpolation);
// if escape was pressed, we exit
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
finished = true;
}
//We don't want the chase camera to go below the world, so always keep
//it 2 units above the level.
if(cam.getLocation().y < (tb.getHeight(cam.getLocation())+2)) {
cam.getLocation().y = tb.getHeight(cam.getLocation()) + 2;
cam.update();
}
//make sure that if the player left the level we don't crash. When we add collisions,
//the fence will do its job and keep the player inside.
float characterMinHeight = tb.getHeight(player
.getLocalTranslation())+((BoundingBox)player.getWorldBound()).yExtent;
if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
player.getLocalTranslation().y = characterMinHeight;
}
//Because we are changing the scene (moving the skybox and player) we need to update
//the graph.
scene.updateGeometricState(interpolation, true);
}
/**
* draws the scene graph
*
* @see com.jme.app.SimpleGame#render()
*/
protected void render(float interpolation) {
// Clear the screen
display.getRenderer().clearBuffers();
display.getRenderer().draw(scene);
chaser.update(interpolation);
}
/**
* initializes the display and camera.
*
* @see com.jme.app.SimpleGame#initSystem()
*/
protected void initSystem() {
// store the properties information
width = settings.getWidth();
height = settings.getHeight();
depth = settings.getDepth();
freq = settings.getFrequency();
fullscreen = settings.isFullscreen();
try {
display = DisplaySystem.getDisplaySystem(settings.getRenderer());
display.createWindow(width, height, depth, freq, fullscreen);
cam = display.getRenderer().createCamera(width, height);
} catch (JmeException e) {
e.printStackTrace();
System.exit(1);
}
// set the background to black
display.getRenderer().setBackgroundColor(ColorRGBA.black);
// initialize the camera
cam.setFrustumPerspective(45.0f, (float) width / (float) height, 1,
1000);
Vector3f loc = new Vector3f(500.0f, 150.0f, 500.0f);
Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f dir = new Vector3f(0.0f, 0.0f, -1.0f);
// Move our camera to a correct place and orientation.
cam.setFrame(loc, left, up, dir);
/** Signal that we've changed our camera's location/frustum. */
cam.update();
/** Get a high resolution timer for FPS updates. */
timer = Timer.getTimer();
display.getRenderer().setCamera(cam);
KeyBindingManager.getKeyBindingManager().set("exit",
KeyInput.KEY_ESCAPE);
}
/**
* initializes the scene
*
* @see com.jme.app.SimpleGame#initGame()
*/
protected void initGame() {
display.setTitle("Humvee Adventure");
scene = new Node("Scene graph node");
buildTerrain();
buildPlayer();
buildChaseCamera();
scene.attachChild(tb);
input = new FlagRushHandler(player, settings.getRenderer());
buildLighting();
// update the scene graph for rendering
scene.updateGeometricState(0.0f, true);
scene.updateRenderState();
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
scene.setRenderState(buf);
//cull states
CullState cs = display.getRenderer().createCullState();
cs.setCullFace(CullState.Face.Back);
scene.setRenderState(cs);
}
/**
* creates a light for the terrain.
*/
private void buildLighting() {
/** Set up a basic, default light. */
DirectionalLight light = new DirectionalLight();
light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
light.setDirection(new Vector3f(1,-1,0));
light.setEnabled(true);
/** Attach the light to a lightState and the lightState to rootNode. */
LightState lightState = display.getRenderer().createLightState();
lightState.setEnabled(true);
lightState.attach(light);
scene.setRenderState(lightState);
}
/**
* build the height map and terrain block.
*/
private void buildTerrain() {
// Generate a random terrain data
MidPointHeightMap heightMap = new MidPointHeightMap(64, 1f);
// Scale the data
Vector3f terrainScale = new Vector3f(20, 0.5f, 20);
// create a terrainblock
tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
heightMap.getHeightMap(), new Vector3f(0, 0, 0));
tb.setModelBound(new BoundingBox());
tb.updateModelBound();
// generate a terrain texture with 3 textures
ProceduralTextureGenerator pt = new ProceduralTextureGenerator(
heightMap);
pt.addTexture(new ImageIcon(Lesson3.class.getClassLoader()
.getResource("jmetest/data/texture/grassb.png")), -128, 0, 128);
pt.addTexture(new ImageIcon(Lesson3.class.getClassLoader()
.getResource("jmetest/data/texture/dirt.jpg")), 0, 128, 255);
pt.addTexture(new ImageIcon(Lesson3.class.getClassLoader()
.getResource("jmetest/data/texture/highest.jpg")), 128, 255,
384);
pt.createTexture(32);
// assign the texture to the terrain
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
Texture t1 = TextureManager.loadTexture(pt.getImageIcon().getImage(),
Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear, true);
ts.setTexture(t1, 0);
tb.setRenderState(ts);
}
private void buildPlayer() {
//box stand in
Box b = new Box("box", new Vector3f(), 0.35f,0.25f,0.5f);
b.setModelBound(new BoundingBox());
b.updateModelBound();
player = new Node("Player Node");
player.setLocalTranslation(new Vector3f(100,0, 100));
scene.attachChild(player);
player.attachChild(b);
player.updateWorldBound();
float characterMinHeight = tb.getHeight(player
.getLocalTranslation())+((BoundingBox)player.getWorldBound()).yExtent;
if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
player.getLocalTranslation().y = characterMinHeight;}
}
private void buildChaseCamera() {
Vector3f targetOffset = new Vector3f();
targetOffset.y = ((BoundingBox) player.getWorldBound()).yExtent * 1.5f;
HashMap<String, Object> props = new HashMap<String, Object>();
props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "6");
props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "3");
props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
props.put(ThirdPersonMouseLook.PROP_MAXASCENT, ""+45 * FastMath.DEG_TO_RAD);
props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(5, 0, 30 * FastMath.DEG_TO_RAD));
props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
chaser = new ChaseCamera(cam, player, props);
chaser.setMaxDistance(8);
chaser.setMinDistance(2);
}
/**
* will be called if the resolution changes
*
* @see com.jme.app.SimpleGame#reinit()
*/
protected void reinit() {
display.recreateWindow(width, height, depth, freq, fullscreen);
}
/**
* clean up the textures.
*
* @see com.jme.app.SimpleGame#cleanup()
*/
protected void cleanup() {
}
What am i doing wrong with this?
Thanks