satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
57 stars 13 forks source link

[VR] Add missing translation by IPD on camera transformation (EyeParameters transform) #90

Open satoshinm opened 7 years ago

satoshinm commented 7 years ago

https://github.com/satoshinm/NetCraft/pull/63#issuecomment-299115925

https://github.com/mrdoob/three.js/blob/36565aa86a44d02cdb9c8af4ba91816928180fab/examples/js/effects/OculusRiftEffect.js#L127

        // Compute camera projection matrices
        var proj = (new THREE.Matrix4()).makePerspective( fov, aspect, 0.3, 10000 );
        var h = 4 * (HMD.hScreenSize/4 - HMD.interpupillaryDistance/2) / HMD.hScreenSize;
        left.proj = ((new THREE.Matrix4()).makeTranslation( h, 0.0, 0.0 )).multiply(proj);
        right.proj = ((new THREE.Matrix4()).makeTranslation( -h, 0.0, 0.0 )).multiply(proj);

        // Compute camera transformation matrices
        left.tranform = (new THREE.Matrix4()).makeTranslation( -worldFactor * HMD.interpupillaryDistance/2, 0.0, 0.0 );
        right.tranform = (new THREE.Matrix4()).makeTranslation( worldFactor * HMD.interpupillaryDistance/2, 0.0, 0.0 );

The first part (camera projection matrices) is ported, used in g->vr.left.h and with me->state.x shifted before and after each render_scene():

    // Compute x translation offset (h) for projection matrix
    double h = 4 * (g->vr.hScreenSize/4 - g->vr.interpupillaryDistance/2) / g->vr.hScreenSize;

    g->vr.left.h = h;
    g->vr.right.h = -h;

...

            if (g->show_vr) {
                // left eye
                glBindFramebuffer(GL_FRAMEBUFFER, g->vr.framebuffer);
                glViewport(0, 0, g->width, g->height);
                me->state.x += g->vr.left.h;
                render_scene();
                me->state.x -= g->vr.left.h;
                render_vr_eye(&g->vr.left);

                // right eye
                glBindFramebuffer(GL_FRAMEBUFFER, g->vr.framebuffer);
                glViewport(0, 0, g->width, g->height);
                me->state.x += g->vr.right.h;
                render_scene();
                me->state.x -= g->vr.right.h;
                render_vr_eye(&g->vr.right);

but what about the second part? The "compute camera transformation matrices" code is ported and executed but not used anywhere yet:


    // Compute camera transformation matrices
    mat_translate(g->vr.left.transform, -g->vr.worldFactor * g->vr.interpupillaryDistance/2, 0.0, 0.0);
    mat_translate(g->vr.right.transform, g->vr.worldFactor * g->vr.interpupillaryDistance/2, 0.0, 0.0);

Are both translations needed? (camera projection and camera transformation)