Ejemplo n.º 1
0
Archivo: main.cpp Proyecto: Jadela/GT1
//Render the objects
void display()
{
	// Get CPU time from start.
	CPUtime = GetPerformanceTicks();

	// Initialize the physics time at the beginning of the program.
	if ( CPUphysicsTime == 0 )
		CPUphysicsTime = CPUtime - CPUphysicsTimeStep;

	while ( (CPUphysicsTime + CPUphysicsTimeStep) <= CPUtime )
	{
		physEngine.Update(physicsTimestep);
		CPUphysicsTime += CPUphysicsTimeStep;
	}

	//Make sure we do not get ahead of current time due to rounding errors
	if ( CPUphysicsTime > CPUtime )
		CPUphysicsTime = CPUtime;

	//Render section
	physEngine.Render();

	//Display the results
	glEnable( GL_BLEND );
	glPopMatrix();
	glutSwapBuffers();
	glClear( GL_COLOR_BUFFER_BIT );
}
Ejemplo 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(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";
    }
}
Ejemplo n.º 3
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";
    }
}