Forceflow / trimesh2

C++ library and set of utilities for input, output, and basic manipulation of 3D triangle meshes
GNU General Public License v2.0
307 stars 72 forks source link

GLCamera::setupGL function #9

Closed xchhuang closed 5 years ago

xchhuang commented 5 years ago

Hi,

I have a question about the GLCamera::setupGL() function. Based on the source code, it returns a projection matrix using:

diag = sqrt(float(sqr(width) + sqr(height)));
top = (float) height/diag * 0.5f*field_of_view * neardist;
bottom = -top;
right = (float) width/diag * 0.5f*field_of_view * neardist;
left = -right;
glFrustum(left, right, bottom, top, neardist, fardist)`.

However, the above calculation of (left, right, bottom, top) seems a bit different to what I have learned below (needs a tangent function):

function perspectiveCameraUsingFrustum (fovy, aspect, near, far) {
  top = near * Math.tan(toRadians(fovy)/2);
  bottom = -top;
  right = top * aspect;
  left = -right;
  return createFrustum(left, right, bottom, top, near, far);
}

Can anyone explain if they are the same or their differences ? Thanks in advance.

Forceflow commented 5 years ago

It boils down to the same thing.