Flag Rush Tut. - Player

Hey… I'm working on the Flag Rush Tutorial, and I want to add the player (the little gray box). Can someone tell me why there is only the terrain without player? thx








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

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.ImageIcon;

import jmetest.terrain.TestTerrain;

import com.jme.app.BaseGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.light.DirectionalLight;
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.LightState;
import com.jme.scene.state.TextureState;
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 Main extends BaseGame {

    private TerrainBlock tb;
    protected Timer timer;
    private Camera cam;
    private Node scene;
    private int width, height, depth, freq;
    private boolean fullscreen;
    public Node player;

    public static void main(String[] args) {
        Main app = new Main();

        app.setConfigShowMode(ConfigShowMode.AlwaysShow, Main.class.getClassLoader().getResource(
                "jmetest/data/images/FlagRush.png"));
        app.start();
    }

    protected void update(float interpolation) {

        timer.update();
        interpolation = timer.getTimePerFrame();

        if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
            finished = true;
        }


        float characterMinHeight = tb.getHeight(player.getLocalTranslation()) + ((BoundingBox) player.getWorldBound()).yExtent;
        if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
            player.getLocalTranslation().y = characterMinHeight;
        }
    }

    protected void render(float interpolation) {

        display.getRenderer().clearBuffers();

        display.getRenderer().draw(scene);

    }

    protected void initSystem() {

        width = settings.getWidth();
        height = settings.getHeight();
        depth = settings.getDepth();
        freq = settings.getFrequency();
        fullscreen = settings.isFullscreen();


        display = DisplaySystem.getDisplaySystem(settings.getRenderer());
        display.createWindow(width, height, depth, freq, fullscreen);

        cam = display.getRenderer().createCamera(width, height);



        display.getRenderer().setBackgroundColor(ColorRGBA.gray.clone());

        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);

        cam.setFrame(loc, left, up, dir);

        cam.update();


        timer = Timer.getTimer();

        display.getRenderer().setCamera(cam);

        KeyBindingManager.getKeyBindingManager().set("exit",
                KeyInput.KEY_ESCAPE);
    }

    protected void initGame() {
        scene = new Node("Scene graph node");

        buildTerrain();
        scene.attachChild(tb);

        buildPlayer();

        scene.updateGeometricState(0.0f, true);
        scene.updateRenderState();
    }

    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();
    }

    private void buildTerrain() {



        MidPointHeightMap heightMap = new MidPointHeightMap(64, 1f);

        Vector3f terrainScale = new Vector3f(20, 0.5f, 20);

        tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
                heightMap.getHeightMap(), new Vector3f(0, 0, 0));

        tb.setModelBound(new BoundingBox());
        tb.updateModelBound();



        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        Texture t1 = TextureManager.loadTexture("grass.jpg",
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear);
        ts.setTexture(t1, 0);

        tb.setRenderState(ts);
    }

    protected void reinit() {
        display.recreateWindow(width, height, depth, freq, fullscreen);
    }

    /**
     * close the window and also exit the program.
     */
    protected void quit() {
        super.quit();
        System.exit(0);
    }


    protected void cleanup() {
    }
}



Actually the player is added. It is so small that you could not see it.



Box b = new Box("box", new Vector3f(), 0.35f, 0.25f, 0.5f);



I think you should finish the flag rush tutorial you're reading, because the next part of it is you will add a ChaseCamera which will let you see your player. its like a camera focusing on the player.



somewhat like this.

    private void setChaseCam(){

      Vector3f targetOffSet = new Vector3f();
      targetOffSet.y = ((BoundingBox)playerNode.getWorldBound()).yExtent * 2.0f;

      HashMap props = new HashMap();
      props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "8");
      props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "3");
      props.put(ThirdPersonMouseLook.PROP_MAXASCENT, "" + FastMath.DEG_TO_RAD * 45);
      props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(7,2,FastMath.DEG_TO_RAD*30));
      props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffSet);

      chaseCam = new ChaseCamera(cam, playerNode, props);
      chaseCam.setMaxDistance(10);
      chaseCam.setMinDistance(2);

    }

thx…but if I add the chase cam, the box is under the terrain… :? Is something wrong with my code…?

try to add a little in the characterMinHeight when you assign it to the player's localTranslation.

float characterMinHeight = tb.getHeight(player.getLocalTranslation()) + ((BoundingBox) player.getWorldBound()).yExtent;
        if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
            player.getLocalTranslation().y = characterMinHeight + 0.8f;
        }