android - Calculating frustum FOV for a PerspectiveCamera -
i have screen consisting of 2 areas:
(values assumed particular example , may of course vary depending on screen).
the screen in total 1080x1432px (wxh) , consists of 2 areas, each clipped using glviewport
. because want area (1) not fill screen when zooming.
- game area. can zoomed. size 1080x1277px (wxh) , located @ top.
- the hud (fyi objects here can moved area (1). non zoomable. size 1080x154 (wxh).
both have own cameras.
area (1) width 15f , height more 15f (does not matter long it's @ least 15f).
i want area (2) 7f in width , 1f in height (for convenience). want set camera accordingly. i've tried calculating 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 create 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 manually try set distance 1f can still view box, if go below 1.0f box won't display. , distance being calculcated approx 0.76f.
i trying use same concept https://xoppa.github.io/blog/a-simple-card-game/ calculate fov. works fine area (1).
can not use camera this? calculate fov incorrectly? why object disappear when go below 1f in distance?
thanks.
the projection matrix describes mapping 3d points of scene, 2d points of viewport. transforms eye space clip space, , coordinates in clip space transformed normalized device coordinates (ndc) dividing w
component of clip coordinates. ndc in range (-1,-1,-1) (1,1,1).
every geometry out of ndc clipped.
the objects between near plane , far plane of camera frustum mappend range (-1, 1) of ndc.
(see further how render depth linearly in modern opengl gl_fragcoord.z in fragment shader?)
this means if want see objects nearer 1f, have set distnce near plane less 1f.
note, near plane , far plane should close possible scene, increase computational accuracy , avoid z-fighting, they must include want see scene.
Comments
Post a Comment