示例#1
0
void Application::Update(float deltaTime) {
    try {
        //Check for lost device
        HRESULT coop = g_pDevice->TestCooperativeLevel();

        if (coop != D3D_OK) {
            if (coop == D3DERR_DEVICELOST) {
                if (m_deviceLost == false)
                    DeviceLost();
            }
            else if (coop == D3DERR_DEVICENOTRESET) {
                if (m_deviceLost == true)
                    DeviceGained();
            }

            Sleep(100);
            return;
        }

        //Physics Engine
        physicsEngine.Update(deltaTime);

        if (KeyDown('1')) {
            physicsEngine.Reset(HINGE);
        }
        else if (KeyDown('2')) {
            physicsEngine.Reset(TWISTCONE);
        }
        else if (KeyDown('3')) {
            physicsEngine.Reset(BALLPOINT);
        }

        if (KeyDown(VK_LEFT))m_angle += deltaTime;
        if (KeyDown(VK_RIGHT))m_angle -= deltaTime;

        //Keyboard input
        if (KeyDown(VK_ESCAPE)) {
            Quit();
        }

        if (KeyDown(VK_RETURN) && KeyDown(18)) {     //ALT + RETURN
            //Switch between windowed mode and fullscreen mode
            m_present.Windowed = !m_present.Windowed;

            DeviceLost();
            DeviceGained();

            if (m_present.Windowed) {
                RECT rc = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
                AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);
                SetWindowPos(m_mainWindow, HWND_NOTOPMOST, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
                UpdateWindow(m_mainWindow);
            }
        }
    }
    catch(...) {
        g_debug << "Error in Application::Update() \n";
    }
}
示例#2
0
void Application::Update(float deltaTime) {
    try {
        //Check for lost device
        HRESULT coop = g_pDevice->TestCooperativeLevel();

        if (coop != D3D_OK) {
            if (coop == D3DERR_DEVICELOST) {
                if (m_deviceLost == false)
                    DeviceLost();
            }
            else if (coop == D3DERR_DEVICENOTRESET) {
                if (m_deviceLost == true)
                    DeviceGained();
            }

            Sleep(100);
            return;
        }

        //Physics Engine
        physicsEngine.Update(m_slowMotion ? deltaTime * 0.1f : deltaTime * 1.0f);

        //reset simulation
        if (KeyDown(VK_SPACE)) {
            physicsEngine.Reset();
        }

        //Keyboard input
        if (KeyDown(VK_ESCAPE)) {
            Quit();
        }

        if (KeyDown(VK_RETURN) && KeyDown(18)) {     //ALT + RETURN
            //Switch between windowed mode and fullscreen mode
            m_present.Windowed = !m_present.Windowed;

            DeviceLost();
            DeviceGained();

            if (m_present.Windowed) {
                RECT rc = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
                AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);
                SetWindowPos(m_mainWindow, HWND_NOTOPMOST, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
                UpdateWindow(m_mainWindow);
            }
        }

        //Slowmotion on/off
        if (KeyDown(VK_RETURN)) {
            m_slowMotion = !m_slowMotion;
            Sleep(300);
        }

    }
    catch(...) {
        g_debug << "Error in Application::Update() \n";
    }
}