I currently have a screen consisting of two areas:
(Values are just assumed for this particular example and may of course vary depending on screen).
The screen in total is 1080x1432px (WxH) and consists of two areas, each clipped using glViewPort
. This because I want area (1) not to fill the screen when zooming.
- Game area. Can be zoomed. The size is 1080x1277px (WxH) and located at the top.
- The HUD (FYI objects from here can be moved to area (1). Non zoomable. The size is 1080x154 (WxH).
Both have their own cameras.
Area (1) width is 15f and the height is more than 15f (does not matter as long as it's at least 15f).
I want area (2) to be 7f in width and 1f in height (for convenience). Thus I want to set the camera accordingly. I've tried to do this by calculating the FOV:
float size = 1f;
float halfHeight = size * 0.5f;
halfHeight *= (float) 154 / (float) 1080;
float fullHeight = 2 * halfHeight;
float halfFovRadians = MathUtils.degreesToRadians * camera.fieldOfView * 0.5f;
float distance = halfHeight / (float) Math.tan(halfFovRadians);
camera.viewportWidth = 1080;
camera.viewportHeight = 154;
camera.position.set(0f, 0, distance);
camera.lookAt(0, 0, 0);
camera.update();
And I create a object:
ModelBuilder builder = new ModelBuilder();
builder.begin();
builder.node();
MeshPartBuilder meshBuilder = builder.part("lattice", GL20.GL_TRIANGLES,
VertexAttributes.Usage.Position,
new Material(ColorAttribute.createDiffuse(Color.GRAY)));
BoxShapeBuilder.build(meshBuilder, 0f, 0f, 0f, 7f, 1f, 0f);
Model model = builder.end();
mHudModel = new ModelInstance(model);
If I manually try to set distance to 1f I can still view the box, but if I go below 1.0f the box won't display. And the distance being calculcated is approx 0.76f.
I am trying to use the same concept as https://xoppa.github.io/blog/a-simple-card-game/ to calculate the FOV. It works fine for area (1).
Can I not use the camera like this? Do I calculate the FOV incorrectly? Why would my object disappear when I go below 1f in distance?
Thanks.