Difference between revisions of "Application:configureFrustum"

From GiderosMobile
m
m (Text replacement - "<source" to "<syntaxhighlight")
Line 4: Line 4:
 
=== Description ===
 
=== Description ===
 
Configures the field of view (fov) and far clipping plane for 3D projection.
 
Configures the field of view (fov) and far clipping plane for 3D projection.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
application:configureFrustum(fov,farplane)
 
application:configureFrustum(fov,farplane)
 
</source>
 
</source>

Revision as of 16:58, 12 July 2023

Available since: Gideros 2015.04.04
Class: Application

Description

Configures the field of view (fov) and far clipping plane for 3D projection. <syntaxhighlight lang="lua"> application:configureFrustum(fov,farplane) </source>

Setting a fov of 0 selects the default orthographic projection (no perspective).

The field of view specifies the angle of vision by which the largest side of the scene is seen. It is used to compute the distance of the eye relative to the screen along the Z axis:

  Z=(largest screen dimension/2)/tan(fov/2)

Z is the eye location. The far clipping plane specifies the maximum distance of an object. Objects more distant than the far clipping plane are not drawn.

Note: the perspective is oriented so that the full screen is at Z=0 (so sprite:setPosition(x,y,0) will place the sprite at exactly (x,y) pixels on the screen, irrespective of fov) and distant objects are placed at negative Z values.

If the fov is set at non-zero then perspective projection is activated. If farplane is then not set it takes the default value 100*(screen height). Normally the user should set this value. Note that there is no nearplane in perspective mode (objects are clipped only at the eye position).

If fov is set at 0 then the eye is at +infinity and a near plane is set at z=+farplane. Objects closer than this are clipped. The farplane remains at z=-farplane.

Parameters

fov: (number) specifies the field of view angle in degrees. If fov>0 a perspective projection is used with the eye at position z=+h/tan(fov/2) where h is half the larger screen dimension (logical coordinates). In this case there is a farplane but no nearplane: clipping is done only at the eye position. If fov=0, an orthographic projection is used with both a farplane and a nearplane (see below)
farplane: (number) the distance of the far clipping plane along Z axis. If fov>0 and this value is not set, the farplane is set at distance 100*(screen height) from the origin (z=0). If fov=0 (orthographic projection), a nearplane is also used at distance farplane from the origin. If fov=0 and no farplane is set then near and farplanes are set at 1 pixel from the origin optional