void gameLoop() { frameNum++; //LOG("doFrame()..."); doFrame(); h3dSetNodeTransform(cam, //0, 0, 0, 0, 10, 10, _rx ,_ry, 0, 1, 1, 1 ); //LOG("h3dRender(cam)..."); h3dRender(cam); //LOG("h3dutShowFrameStats(fontMatRes, panelMatRes, 2)..."); h3dutShowFrameStats(fontMatRes, panelMatRes, 2); #if 0 //int n = snprintf(text, textLen - 1, "Frame %d: %f ms", frameNum, msSinceLastFrame()); //int n = snprintf(text, textLen - 1, "Frame %d", frameNum % 32); int n = snprintf(text, textLen - 1, "Frame %d", frameNum); LOG("Showing text \"%s\" (wrote %d chars) with color (%d, %d, %d)", text, n, frameNum % 2, (frameNum >> 1) % 2, (frameNum >> 2) % 2); h3dutShowText(text, 0.5, 0.5, // Position 0.05, // Size (scale) frameNum % 2, (frameNum >> 1) % 2, (frameNum >> 2) % 2, // Color (RGB) fontMatRes // Font material ); #endif //LOG("h3dFinalizeFrame()..."); h3dFinalizeFrame(); //LOG("Frame finished."); } // end gameLoop
void Application::mainLoop( float timeSinceLastFrame ) { keyHandler( timeSinceLastFrame ); // Set camera parameters h3dSetNodeTransform( _cam, _x, _y, _z, _rx ,_ry, 0, 1, 1, 1 ); _lightTimer += timeSinceLastFrame; // Has it gone a second since the light changed color? if( _lightTimer >= 1.0f ) { // Set a random light color switch( rand() % 6 ) { case 0: // Red h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f ); break; case 1: // Green h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f ); break; case 2: // Blue h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f ); break; case 3: // Yellow h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f ); break; case 4: // Purple h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f ); break; case 5: // Cyan h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f ); break; } // Reset the timer _lightTimer = 0.0f; } // Show stats h3dutShowFrameStats( _fontMatRes, _panelMatRes, _statMode ); if( _statMode > 0 ) { displaySoundInfo(); } // Show logo const float ww = (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportWidthI ) / (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportHeightI ); const float ovLogo[] = { ww-0.4f, 0.8f, 0, 1, ww-0.4f, 1, 0, 0, ww, 1, 1, 0, ww, 0.8f, 1, 1 }; h3dShowOverlays( ovLogo, 4, 1.f, 1.f, 1.f, 1.f, _logoMatRes, 0 ); // Render scene h3dRender( _cam ); // Finish rendering of frame h3dFinalizeFrame(); // Remove all overlays h3dClearOverlays(); // Write all mesages to log file h3dutDumpMessages(); }