AlloSphere-Research-Group / allolib

Library for interactive multimedia application development
BSD 3-Clause "New" or "Revised" License
36 stars 14 forks source link

examples/graphics/mirror.cpp is not a mirror | complete or rename #18

Open kybr opened 5 years ago

kybr commented 5 years ago

examples/graphics/mirror.cpp is not a mirror. please complete or rename.

I checked: the calculation of the position of the "mirror camera" seems correct---It's just reflected across an axis. I checked this by rendering that position with a sphere. It seems to be in the right place.

I think perhaps the issue is that some of the other parameters of the "mirror camera" are not correct. Imagine a wire-frame frustum drawn from the mirror camera's perspective. (Or, maybe just literally render this wire-frame as a way to see how to repair this example.) The lines that define the frustum must run through the corners of the mirror surface (the textured quad). This frustum is oblique, No? It's an off-axis frustum (google: oblique frustum and off-axis frustum and look at the links at the end of this comment). The surface the camera projects onto is at an angle (not a right angle) with respect to the viewer. And, the field of view change as I move closer or further away from the mirror. Yet, here's how the mirror camera is setup:

    g.pushProjMatrix(Matrix4f::perspective(45, 1, 0.001, 100));
    g.pushViewMatrix(Matrix4f::lookAt(mirrorCam.ux(), mirrorCam.uy(),
                                      mirrorCam.uz(), mirrorCam.pos()));

To me, that looks like a camera with a fixed field of view projecting onto a surface that is always 90 degrees to the viewer. This is why this mirror looks good when I am looking at it head-on (90 degrees), but as I look at it from an angle, it looks wrong.

-

A (virtual) mirror is just a (virtual) window plus a reflection. In this example, the reflection part is correct (I think), but window part is wrong. I recommend we make a new example called window that illustrates the difference between toe-in and off-axis. This example would be very useful for teaching the basics of what some of the advanced stuff this framework does at its core: stereo, omni-stereo, projecting onto curved surfaces from odd angles. Getting these examples (e.g., mirror, window, other stuff that does off-axis projection) wrong should be particularly embarrassing for this framework :)