Minimap geometry conundrum

First of all, I hope I’m not posting this in the wrong sub (I couldn’t find a more suitable one).

I would like to ask you guys for help. It’s not a very difficult thing actually, but I figured it could be fun to ask it here.

I’m trying to figure out the correct height to spawn a camera actor that’s going to work as a minimap. The problem is that the levels are procedurally generated. We have a containing box 10000x10000, and a map could be, for example, 4000x7000, or 3000x3000, 5000x2000, and so on, arranged anywhere inside said containing box. As you can imagine the camera’s height has to change based on the size of the spawned map.

At the moment I’m able to calculate the median point of the map (using its length, widht, and world positioning), but I can’t figure out the correct height to keep the map precisely inside the camera scope.

I’m pretty sure there’s a geometric formula for pyramids, that would solve my problem, but I wasn’t able to figure it out yet.

So I wanted to share my problem, if anyone is willing to think about this with me. :slight_smile:

There are some parts regarding the perspective camera I’m unsure of, but I hope this helps.

For a minimap, are you sure you want a perspective camera? My guess would be that you want an orthographic camera?
For either of them you can find the settings here: FMinimalViewInfo | Unreal Engine Documentation
For an ortho camera:
You need to set the nearplane to something.
You need to set how high up it is in the scene. (That should be the highest point you want visible + the nearplane).
You need to set farplane, it’s the height it’s placed at + lowest point that should be visible.
You need to center it in the scene, (obviously).
You need to set the aspect ratio to fit the ratio of your scene.
You need to set the OrthoWidth to fit the scene.
No math other then finding the highest and lowest points needed.

For a perspective camera as you have noticed it’s a little more complex, but still not that bad.
Here you need to figure out two things to perfectly fit what the camera can see to the map.
Aspect ratio
And height.
I’m assuming you have already chosen a field of view for one axis.
The height can be calulated simply by Pythagoras! As you know the length of one side, and all three angles.
Just input your values into this:
height = (mapWidth/2) * tan(FoV/2)
(This assumes a FoV along the width axis).
Then you get your aspect ratio by simply width/height of the map.

Hey , you seem to know your cameras very well! Those are all good info you just gave me!

For the ortho/persp problem, I would have gone with ortho, of course, but what I’m using to display the map is a SceneCaptureComponent2D (that uses, as Texture Target, a TextureRenderTarget2D), and it does not have an ortho setting, only perspective. Sadly this is a known low priority change Epic Games has pending for almost a couple of years now.

Given that we are in the argument, would you happen to know a better way to show/hide the output from a camera looking down on the level map, and that could use an iso/ortho view? :slight_smile: