Skip to content

About setting widescreen fov parameter [question] #49

Open
@suijingfeng

Description

@suijingfeng

This thread is more about question than issue. The following code is extracted from RE_RenderScene in tr_scene.c

parms.fovX = tr.refdef.fov_x;
parms.fovY = tr.refdef.fov_y;

if (!( fd->rdflags & RDF_NOWORLDMODEL ) ) // don't affect interface refdefs
{
	float zoomfov = tr.refdef.fov_x / 90;	
	int thisisit;
	float erspact = tr.refdef.width / tr.refdef.height;
	float aspact = glConfig.vidWidth / glConfig.vidHeight;
	if (erspact == aspact) thisisit = 1;
	if (((tr.refdef.fov_x /  tr.refdef.fov_y) > 1.3) && (thisisit))
        {
                // undo vert-
                parms.fovY = parms.fovY * (73.739792 / tr.refdef.fov_y) * zoomfov;
                // recalculate the fov
                parms.fovX = (atan (glConfig.vidWidth / (glConfig.vidHeight / tan ((parms.fovY * M_PI) / 360.0f))) * 360.0f) / M_PI;
                parms.fovY = (atan (glConfig.vidHeight / (glConfig.vidWidth / tan ((parms.fovX * M_PI) / 360.0f))) * 360.0f) / M_PI;
        }
}

It boil down to

parms.fovX = tr.refdef.fov_x;
parms.fovY = tr.refdef.fov_y;
if (!( fd->rdflags & RDF_NOWORLDMODEL ) ) // don't affect interface refdefs
{
    if ((parms.fovX > parms.fovY * 1.3f) && (tr.refdef.width * glConfig.vidHeight == glConfig.vidWidth * tr.refdef.height ))
    {
        // undo vert-
        parms.fovY = parms.fovX * (73.739792 / 90.0);
        // recalculate the fov_x
        parms.fovX = atan( tan(parms.fovY*(M_PI/360.0)) * glConfig.windowAspect ) * (360.0 / M_PI);
    }
}

because:

  1. glConfig.windowAspect = glConfig.vidWidth / glConfig.vidHeight is already computed previously, don't compute it every time in the main loop.

  2. parms.fovX = (atan (glConfig.vidWidth / (glConfig.vidHeight / tan ((parms.fovY * M_PI) / 360.0f))) * 360.0f) / M_PI are equivalent to parms.fovY = (atan (glConfig.vidHeight / (glConfig.vidWidth / tan ((parms.fovX * M_PI) / 360.0f))) * 360.0f) / M_PI; because:

glConfig.vidWidth / glConfig.vidHeight = tan( parms.fovX * M_PI / 360) / tan( parms.fovY * M_PI / 360)
there no need to compute parms.fovY again, right?

  1. what i am doing is trying to avoid float divided, it seems that adding this code code snippet to my rendergl2 module make sarge run faster. it may somewhere which OA different from ioq3.

I don't know how 1.3f and 73.739792 this two parameters comes from. Can someone tell something about that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions