ObjReader Community

WIP => WIP => Topic started by: Patrice Terrier on October 18, 2019, 11:27:22 am

Title: Lerping
Post by: Patrice Terrier on October 18, 2019, 11:27:22 am
I gave a closer look at your LerpReset, trying to understand how it works.

I would like to use it to perform smooth zooming while processing the WM_MOUSEWHEEL message in Main.cpp,
to replace the code bellow in red:

    case WM_MOUSEWHEEL:
        if (GetFocus() != hWnd) { SetFocus(hWnd); }
        ry = float(HIINT(wParam)) / 120.0f * gP.rCameraPos[2] / CAMERA_FOVY;

        maxK = 2;
        if (gP.bEnableSmoothZoom) { // 10-12-2015
            maxK = 11; ry = ry / 10;
        }
//        nBreak += 1;
        for (K = 1; K < maxK; K++) {
            gP.rCameraPos[2] -= ry;
            if (gP.rCameraPos[2] > CAMERA_ZFAR - 1) {
                gP.rCameraPos[2] = CAMERA_ZFAR - 1;
            } else if (gP.rCameraPos[2] < CAMERA_ZNEAR) {
                gP.rCameraPos[2] = CAMERA_ZNEAR;
            }
            gl_AdjustNearPlane();
            gP.bRedraw = TRUE; // Redraw the OpenGL scene
            if (maxK > 2) { gl_DrawScene(); Sleep(0); }
        }
//        myDoEvents(gP.hMain);
//        nBreak = 0;
        break;


Unfortunatly i am unsure of what to do, and i don't want to break your existing LerpReset code that works very well,
could you help?
Title: Re: Lerping
Post by: Michael Lobko-Lobanovsky on October 18, 2019, 06:21:39 pm
No, it won't work this way, Patrice.

I was planning to substitute your "smooth zoom" (I haven't ever seen any need in, or positive effect of, this "feature") with my own "Inertial mouse" option. The inertial mouse adds some momentum to left mouse drag and mouse wheel scroll, so that once the button or wheel is released, the model doesn't stop abruptly but rather continues to move, rotate or zoom a little gradually decelerating to a full stop. I'm sure you saw this effect in a great many of OpenGL examples on the net.

I implemented this effect in my Objector many years ago. But the problem is that I was unfortunate to break Objector's code a while ago and now I cannot either run it in my IDE or successfully compile it to offer you a practical example... :'(

Do you happen to still have any copy of my compiled Objector (I can decompile it to its FBSL source code and thus restore the functionality of my sources) by any chance?
Title: Re: Lerping
Post by: Patrice Terrier on October 18, 2019, 09:30:10 pm
Here is a copy of the Objector you sent me.

I couldn't see the smooth zooming in it.

I do have D2D inertia somewhere, but it is based on DirectX.
Title: Re: Lerping
Post by: Michael Lobko-Lobanovsky on October 19, 2019, 01:23:45 am
Thank you, Patrice!

Unfortunately that's a very, very early build of Objector that didn't even use skinning or GLSL shaders yet. Neither did it have inertial mouse or many other bells and whistles added at much later stages.

Can you check if you have any other Objector samples I used to send you from time to time to exemplify my progress? They should use a skinned main window like in the snapshot below:


P.S. And, uhm, there was never any "smooth zooming" in Objector whatever that term meant to you. There was only inertial rotation/panning/zooming of the model (I call that option "inertial mouse") which, in later builds, was the mouse's default behavior.
Title: Re: Lerping
Post by: Patrice Terrier on October 19, 2019, 09:52:03 am
I did check again for another Objector version, and i found one, however older than the one i sent you.
One is from june 2015, the other from october 2015 (the one from the zip). :(

I am using the word "smooth zooming" by comparison with the smooth scrolling that was available in some windows controls (Listbox)

To better see what i call smooth zooming change both the maxK and ry parameters into the red code section.

    case WM_MOUSEWHEEL:
        if (GetFocus() != hWnd) { SetFocus(hWnd); }
        ry = float(HIINT(wParam)) / 120.0f * gP.rCameraPos[2] / CAMERA_FOVY;

        maxK = 2;
        if (gP.bEnableSmoothZoom) { // 10-12-2015
            //maxK = 11; ry = ry / 10;
            maxK = 25; ry = ry / 40.0f;
        }
//        nBreak += 1;
        for (K = 1; K < maxK; K++) {
            gP.rCameraPos[2] -= ry;
            if (gP.rCameraPos[2] > CAMERA_ZFAR - 1) {
                gP.rCameraPos[2] = CAMERA_ZFAR - 1;
            } else if (gP.rCameraPos[2] < CAMERA_ZNEAR) {
                gP.rCameraPos[2] = CAMERA_ZNEAR;
            }
            gl_AdjustNearPlane();
            gP.bRedraw = TRUE; // Redraw the OpenGL scene
            if (maxK > 2) { gl_DrawScene(); Sleep(0); }
        }
//        myDoEvents(gP.hMain);
//        nBreak = 0;
        break;


The problem is that i am not sure that these values (working fine on my computer) would produce the same effect on others.

I could add inertia, changing the ry value within the loop.

But i want to get something working the same on all computers.