Minimaps + Camera Nodes

Hey all,



I'm trying to construct a minimap, I thought to use a Camera Node displayed in Ortho mode with the camera positionned above and far out from the terrain - producing an excellent (and live if necessary) minimap.



Try as I might, I can't get the camera node to display - i've managed to get Font2D's displaying messages in ortho mode but I must be doing something wrong with the cameranode that I can't see. I've seen one example in other posts of this sort of technique but it was for a rearview mirror in a car racing game, and no code was included or available that I know of.



I envisaged this minimap being a seperate state, since it's a sort of ortho layer over my third person game, the state is included here, i'm simply adding it to the gameinstancemanager and setting active to true:




import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.CameraNode;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jmex.font2d.Font2D;
import com.jmex.font2d.Text2D;
import com.jmex.game.state.BasicGameState;

public class MiniMapState extends BasicGameState
{
private CameraNode mapNode;
protected ColorRGBA color;
protected AlphaState alphaState;

public MiniMapState(String name)
{
super(name);
this.initLevel();
}

public void initLevel()
{
color = new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);

alphaState = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
alphaState.setBlendEnabled(true);
alphaState.setSrcFunction(AlphaState.SB_SRC_ALPHA);
alphaState.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
alphaState.setTestEnabled(true);
alphaState.setTestFunction(AlphaState.TF_GREATER);
alphaState.setEnabled(true);

rootNode = new Node();
rootNode.setCullMode(Spatial.CULL_NEVER);
rootNode.setLightCombineMode(LightState.OFF);

ZBufferState zbs = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
zbs.setFunction(ZBufferState.CF_ALWAYS);

Camera camera = DisplaySystem.getDisplaySystem().getRenderer().createCamera(300, 300);
camera.setFrustumPerspective(45.0f, (float)DisplaySystem.getDisplaySystem().getWidth() / (float)DisplaySystem.getDisplaySystem().getHeight(), 1.0f, 1000.0f);
camera.setParallelProjection(false);
camera.update();
Vector3f loc = new Vector3f(0.0f, 0.0f, 25.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);
camera.setFrame(loc, left, up, dir);

mapNode = new CameraNode("Minimap", camera);

mapNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
mapNode.setRenderState(zbs);

Quaternion q = new Quaternion();
float angle = 20;
angle -= 180;
angle *= -1 * FastMath.DEG_TO_RAD;
q.fromAngleAxis(angle, new Vector3f(0, 1, 0));
mapNode.setLocalRotation(q);

mapNode.updateRenderState();

rootNode.attachChild(mapNode);
}

public void update(float tpf)
{
rootNode.updateGeometricState(tpf, true);
//update Overhead Camera
    mapNode.updateWorldData(tpf);
}

public void render(float tpf)
{
DisplaySystem.getDisplaySystem().getRenderer().draw(rootNode);
}

}

Hi Henri,



Try looking at the following for some inspiration on the minimap:



http://www.krugle.org/examples/p-pO8YhwTvN6gJimQU/TestSpatialLookAt.java



Add the security monitor node to the fpsNode.



Hope that helps!