The best way for the camera on a RTS minimap

Hello guys,

I am working on a RTS/Citybuilder game and today I added a minimap to the game. The map itself works but it is not that helpful if you cant see where on this map the camera is. What I want is a way to mark the visible terrain on the minimap (which has changing sizes since the camera’s rotation is not fixed) that is not too heavy for the performance.

In one sentence: What’s the best way to find out if a position (Vector3f) is inside the camera frustrum?

Is there a way to use Spatial.getCulling(Camera) for this? I thought of creating a massive amount of invisible Spatials over the map but this did not sound like a very good idea to me… I am pretty sure someone has done this before and might share his way to do it :wink: I Did this with a 2D game before but there I did no have the problem with camera rotation (around x and y axis).

Kind regards
Smire

Not sure if i got you problem right, but to check if a position in inside the frustum you can:

  1. Create a small BoundingVolume at your location and use Camera.contains(BoundingVolume)

  2. Use Camera.getScreenCoordinates(Vector3f worldPos) and check the result. Should be:
    -1 < x < 1
    -1 < y < 1
    0 < z < 1

not 100% sure about the results so you should test first :wink:

I’ll have a look on that :wink: It would be enough to have my “public boolean isInScreen(Vector3f pos)” working… If it does I will post it here.

Your 2) helped me very much, I just had to change a little things :wink:

This one works:

public boolean isInScreen(Vector3f pos)
{
    Vector3f l = cam.getScreenCoordinates(pos);
    
    return
            l.x > 0 && l.x < cam.getWidth() &&
            l.y > 0 && l.y < cam.getHeight() &&
            l.z > 0 && l.z < 1;
    
}

Thank you :slight_smile:

Nice to hear.

Just as an add, i am not sure what you actually need. but you might come away cheaper if you go the opposite way.

*Calculate the 8 world positions of the camera frustum.
At least that would keep the cost constant and might give you all required informations you need to draw a frustum like object on the minimap

I assume you want something like: (the yellow trapezoid) ?

Um if you wan’t that trapezoid or whatever that is, you just pick a square and them multiply every vertex of it by camera matrix.

That’s indeed what I want. The camera frustrum thing was the first I tried but I did not work as I expected it. Biggest problem is that I have a variable terrain height and so I don’t have collision if the map borders are visible. The ability to rotate the camera in two different axes did not make it easier… Since the way I have now has no feelable impact on the performance I guess I leave it like that for now. Maybe I will look on it later… :wink: