The aspect ratio argument is the aspect ratio of the viewport. Hence it
is used to compute the left/right parameters of the frustum from the
bottom/top parameter.
The makePerspective function follow the GLU convention.
On 02/09/2013 15:16, Robert Osfield wrote:
Hi Mike,
The implementation used in the OSG is intended to be consistent with
OpenGL conventions for gluPerspective. I have just reviewed the code and
it looks correct.
It sounds like your expectation of how makePerspective() works is out of
sync with how it's intended to work, so rather than a bug what you
actually see is simply a mis-understanding. To apply your fix would
actually break user code and would introduce a bug rather than fix one.
Robert.
On 2 September 2013 11:44, Mike Fournigault <[email protected]
<mailto:[email protected]>> wrote:
Hi,
I found a bug in the method makePerspective of
Matrix_implementation. I am using the version 3.0.1 of OSG.
I am working on a confidential network and computer, and so I could
not test the same method in a newer version
of OSG. I searched for any fix of that bug on the forum, but it
seems that this bug has not been fixed yet.
The bug is that, the computed parameters "right" and "left" computed
to define the frustum are incorrect.
It is easy to verify with the following numerical example.
Suppose that we want to create a perspective with a fovx of 90° and
a fovy of 30°. Suppose that znear is equal to 10,
and zfar is equal to 500. We would ask for a perspective with an
aspect ratio equal to 3.
The corresponding frustum is so that the half FOV along x axis is
equal to 45°. According to the definition of the
viewing frustum, the triangle defined with edges of length zNearand
right is isosceles, rectangle at the
vertex common between those 2 edges. And so, right is equal to 10 as
zNear.
In Matrix_implementation::makePerspective, the frustum parameters
(and so right) are computed as :
Code:
void Matrix_implementation::makePerspective (double fovy, double
aspectRatio,
double zNear, double zFar)
{
double tan_fovy = tan (DegreesToRadians (fovy * 0.5));
double right = tan_fovy * aspectRatio * zNear;
double left = -right;
double top = tan_fovy * zNear;
double bottom = -top;
makeFrustum (left, right, bottom, top, zNear, zFar);
}
The parameters top and bottom are good, but not left and right.
Indeed, the value of aspectRatio would have been applied on the fovy
and not on its tangent.
With this code and the given numerical example, we found that right
is equal to 8.04 and not 10.
I suggest the following code :
Code:
void Matrix_implementation::makePerspective (double fovy, double
aspectRatio,
double zNear, double zFar)
{
double tan_fovyDiv2 = tan (DegreesToRadians (fovy * 0.5));
double top = tan_fovyDiv2 * zNear;
double bottom = -top;
double tan_fovxDiv2 = tan (DegreesToRadians (fovy * 0.5 *
aspectRatio));
double right = tan_fovxDiv2 * zNear;
double left = -right;
makeFrustum (left, right, bottom, top, zNear, zFar);
}
With this code, and the given numerical example we found that right
is equal to 10.
The method Matrix_implementation::makePerspective is used in the
Matrixd class and so in the Camera class.
Thank you!
Cheers,
Mike
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56059#56059
_______________________________________________
osg-submissions mailing list
[email protected]
<mailto:[email protected]>
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org