[SOLVED] Setting up a mini-map

Hi guys.

So I’m currently trying to implement a minimap into my design, and it mostly works. I have the viewports set up, and it successfully moves around a birds eye view of the scene. I have a few things I need help with :

  1. How do I draw a circle, or dot or some kind of graphics on the small mini map where the player currently is?
  2. The viewport is in 3D so when moving around mini map it changes slightly in a 3D way. How would I make this 2D?
  3. When I spin round (camera wise) I want the viewport camera to also spin round, but not when I look up or down. WHat quarternion/vectors would I need?

Here’s my current code:

Initialise the minimap:

[java]public void miniMap() {
cam_n = cam.clone();
cam_n.setViewPort(0.8f, 1.0f, 0.0f, 0.4f);
int[] currLocation = vectorCoordsToInt(player.getPhysicsLocation());
cam_n.setLocation(new Vector3f(currLocation[0], currLocation[1] + 100, currLocation[2]));
cam_n.lookAt(new Vector3f(0, -1, 0), Vector3f.UNIT_Y);
//cam_n.setRotation(new Quaternion(-0.07f, 0.92f, -0.25f, -0.27f));
ViewPort view_n = renderManager.createMainView("", cam_n);


Update the minimap inside simpleUpdate:

[java] int[] currLocation = vectorCoordsToInt(player.getPhysicsLocation());
cam_n.setLocation(new Vector3f(currLocation[0], currLocation[1] + 100, currLocation[2]));

Thanks a lot for your time!

Regards, Alex

could you describe this with something more visual (like a drawing?). I think I understand what you mean, but want to make sure

The mini-map in my game has its own scene graph and render. This makes it easy to include object not present in the main scene. Perhaps this approach would work for you.

Another possibility would be to place a marker at the desired screen location using the guiViewPort.

Your minimap is perspective because you are using a perspective camera.

To change the camera type from perspective, would I use

[java]cam.setFrustumPerspective [/java]?

what properties would I need to give it to make the camera truly birds eye?

maybe this is what you are looking for?

1 Like

I tried setting that to false - it didn’t change anything :confused:

I would recommend you give true a chance.

1 Like

It seems to work thanks, but suddenly the camera is really zoomed into the plane? It seems like it no longer takes the cam.setLocation() into account?

To change the scale of the view, you would change the top, bottom, left, and right planes of the camera’s frustrum. The JME3 interface for doing this is somewhat awkward. You could use this utility I wrote:
* Increase a camera’s field-of-view tangent by a specified factor.
* @param camera camera to alter (not null)
* @param factor amount to reduce the FOV tangent (>0)
public static void zoom(Camera camera, float factor) {
float bottom = camera.getFrustumBottom();
camera.setFrustumBottom(bottom * factor);
float left = camera.getFrustumLeft();
camera.setFrustumLeft(left * factor);
float right = camera.getFrustumRight();
camera.setFrustumRight(right * factor);
float top = camera.getFrustumTop();
camera.setFrustumTop(top * factor);

1 Like

Code works brilliantly - thank you everyone for your help!

If anyone’s interested this is the final result:

1 Like

Just realised - the mini map is rectangular instead of square? I was playing around with getting the scene size,and it’s 128x128, which confused me as the birds eye view shows it all as rectangular? Ideas?

Not clear what sort of ideas you’re looking for.

If the map is a viewport, its dimensions (relative to the main window) are specified using Camera.setViewPort(). If the proportions of object rendered by the camera are squashed, you probably need to adjust the camera frustum’s top and bottom relative to its left and right.

Sorted - thanks. I set the frustum for the top and bottom to be factor*2, and the left and right to be factor.

1 Like