I'm having quite a hard time to render a .stl model with the same dimensions and proportions visualized in the picture of the real object. I put the real object at the centre of the view area and I would like to flip between the model and the real object (the real object is 9 times smaller than one in the model).
First, I calibrate the camera using OpenGL like in the tutorial, when the focus is optimal to the real object. After I get the cx, cy, fx and fy values, I create a perspective matrix with these values and I use the glMultMatrixd function. Finally, I resize the photo to be the same as my OpenGL window and compare the photo with the rendered model.
But I have some problems with the result:
- there is proportion distortion (wider than tall)
- there is a perspective distortion (The camera is perpendicular in relation to the object, so I should view only the top of the object, but it is showing the lateral of the object )
- the size is not compatible with the real object (a little smaller)
My relation matrix is below:
GLdouble perspMatrix[16] = { fx / cx, 0 , 0 , 0,
0, fy / cy , 0 , 0,
0, 0 , -(znear + zfar) / (znear - zfar), 2 * zfar*znear / (zfar - znear),
0, 0 , -1 , 0 };