### Matching Luxcore & Opengl Field Of View

Posted:

**Fri Oct 16, 2020 12:57 am**I've been looking through the Blender addon, but I can't seem to find this. Essentially i am trying to draw a rectangle in OpenGl to match Luxcore sensor width and height by using the Field of View. While I am getting the correct ratios, the renders don't match the opengl camera. Some code below to demonstrate, the fov is equal to the luxcore FOV. I tested it with a similar renderer and things were matching up.

Oh and where does the Lens value 74.51911163330078 come from? It is used to calculate lens radius for depth of field. Is it a constant?

Oh and where does the Lens value 74.51911163330078 come from? It is used to calculate lens radius for depth of field. Is it a constant?

Code: Select all

```
static float proj[16];
glMatrixMode(GL_PROJECTION);
auto _proj = perspective(radians(fov), cam_w / cam_h, 0.05f, 500.0f);
glPushMatrix();
glLoadIdentity();
glMultMatrixf(&_proj[0][0]);
glGetFloatv(GL_PROJECTION_MATRIX, proj);
glPopMatrix();
const double _nearScale = 1.0;
const double _near = proj[11] / (proj[10] - 1.0);
const double nLeft = _near * _nearScale *(proj[2] - 1.0) / proj[0];
const double nRight = _near * _nearScale *(1.0 + proj[2]) / proj[0];
const double nTop = _near * _nearScale *(1.0 + proj[6]) / proj[5];
const double nBottom = _near * _nearScale *(proj[6] - 1.0) / proj[5];
glMatrixMode(GL_MODELVIEW);
glLineStipple(1, 0xAAAA);
glLineWidth(2.0);
glPushMatrix();
glMultMatrixf(&inverse(viewMat)[0][0]);
glBegin(GL_LINES);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(nLeft, nBottom, -_near);
glVertex3f(nRight, nBottom, -_near);
glVertex3f(nRight, nTop, -_near);
glVertex3f(nLeft, nTop, -_near);
glVertex3f(nLeft, nTop, -_near);
glVertex3f(nLeft, nBottom, -_near);
glVertex3f(nRight, nTop, -_near);
glVertex3f(nRight, nBottom, -_near);
glEnd();
glPopMatrix();
```