Exemplo n.º 1
0
Arquivo: main.cpp Projeto: 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 );
}
Exemplo n.º 2
0
void Application::Render() {
    if (!m_deviceLost) {
        try {
            // Clear the viewport
            g_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L);

            // Begin the scene
            if (SUCCEEDED(g_pDevice->BeginScene())) {
                D3DXMATRIX view, proj;
                D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f, 2.0f, -10.0f), &D3DXVECTOR3(0.0f, 2.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
                D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1.0f, 1000.0f);

                g_pEffect->SetMatrix("matVP", &(view * proj));

                D3DXVECTOR4 lightPos(-20.0f, 75.0f, -120.0f, 0.0f);
                g_pEffect->SetVector("lightPos", &lightPos);

                //Render All Physics Objects
                physicsEngine.Render();

                RECT rc = {10, 590, 0, 590};
                g_pFont->DrawText(NULL, "Press Space to restart simulation.", -1, &rc, DT_LEFT | DT_BOTTOM | DT_NOCLIP, 0x88000000);

                RECT rc2 = {10, 570, 0, 570};
                string s = "Press Return to toggle slowmotion: ";
                s += (m_slowMotion ? "ON" : "OFF");
                g_pFont->DrawText(NULL, s.c_str(), -1, &rc2, DT_LEFT | DT_BOTTOM | DT_NOCLIP, 0x88000000);

                // End the scene.
                g_pDevice->EndScene();
                g_pDevice->Present(0, 0, 0, 0);
            }
        }
        catch(...) {
            g_debug << "Error in Application::Render() \n";
        }
    }
}
Exemplo n.º 3
0
void Application::Render() {
    if (!m_deviceLost) {
        try {
            // Clear the viewport
            g_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L);

            // Begin the scene
            if (SUCCEEDED(g_pDevice->BeginScene())) {
                D3DXMATRIX view, proj;
                D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(cos(m_angle) * 15.0f, 5.0f, sin(m_angle) * 15.0f), &D3DXVECTOR3(0.0f, 2.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
                D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 3.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1.0f, 1000.0f);

                g_pEffect->SetMatrix("matVP", &(view * proj));

                D3DXVECTOR4 lightPos(-20.0f, 75.0f, -120.0f, 0.0f);
                g_pEffect->SetVector("lightPos", &lightPos);

                //Render All Physics Objects
                physicsEngine.Render();

                RECT rc1 = {10, 10, 0, 590};
                g_pFont->DrawText(NULL, "Press 1: Use Hinge Constraints.", -1, &rc1, DT_LEFT | DT_TOP | DT_NOCLIP, 0x88000000);
                RECT rc2 = {10, 30, 0, 590};
                g_pFont->DrawText(NULL, "Press 2: Use Twist-Cone Constraints.", -1, &rc2, DT_LEFT | DT_TOP | DT_NOCLIP, 0x88000000);
                RECT rc3 = {10, 50, 0, 590};
                g_pFont->DrawText(NULL, "Press 3: Use Point-2-Point Constraints.", -1, &rc3, DT_LEFT | DT_TOP | DT_NOCLIP, 0x88000000);

                // End the scene.
                g_pDevice->EndScene();
                g_pDevice->Present(0, 0, 0, 0);
            }
        }
        catch(...) {
            g_debug << "Error in Application::Render() \n";
        }
    }
}