void GApp::onSimulation()

in projects/hvvr_samples/modelviewer/modelviewer.cpp [189:236]


void GApp::onSimulation(double sceneTime, double deltaTime) {
    (void)sceneTime;
    hvvr::vector3 posDelta(0.0f);
    if (m_cameraSettings.movable) {
        float cardinalCameraSpeed = (float)(m_cameraSettings.maxSpeed * deltaTime);
        if (GetAsyncKeyState(VK_LSHIFT) & 0x8000)
            cardinalCameraSpeed *= .05f;

        if (GetAsyncKeyState('W') & 0x8000)
            posDelta.z -= cardinalCameraSpeed;
        if (GetAsyncKeyState('A') & 0x8000)
            posDelta.x -= cardinalCameraSpeed;
        if (GetAsyncKeyState('S') & 0x8000)
            posDelta.z += cardinalCameraSpeed;
        if (GetAsyncKeyState('D') & 0x8000)
            posDelta.x += cardinalCameraSpeed;
        if (GetAsyncKeyState(VK_LCONTROL) & 0x8000)
            posDelta.y -= cardinalCameraSpeed;
        if (GetAsyncKeyState(VK_SPACE) & 0x8000)
            posDelta.y += cardinalCameraSpeed;

        m_cameraControl.locallyTranslate(posDelta);
    }

#if GAZE_CURSOR_MODE == GAZE_CURSOR_MODE_MOUSE
    if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
        POINT cursorCoord = {};
        GetCursorPos(&cursorCoord);
        ScreenToClient(HWND(m_window->getWindowHandle()), &cursorCoord);

        RECT clientRect = {};
        GetClientRect(HWND(m_window->getWindowHandle()), &clientRect);
        int width = clientRect.right - clientRect.left;
        int height = clientRect.bottom - clientRect.top;

        float cursorX = float(cursorCoord.x) / width * 2.0f - 1.0f;
        float cursorY = -(float(cursorCoord.y) / height * 2.0f - 1.0f);

        if (fabsf(cursorX) <= 1.0f && fabsf(cursorY) <= 1.0f) {
            float screenDistance = 1.0f;
            hvvr::vector3 cursorPosEye(cursorX * width / height, cursorY, -screenDistance);
            hvvr::vector3 eyeDir = hvvr::normalize(cursorPosEye);
            m_camera->setEyeDir(eyeDir);
        }
    }
#endif

}