RageMatrix RageDisplay::GetCenteringMatrix( float fTranslateX, float fTranslateY, float fAddWidth, float fAddHeight ) const { // in screen space, left edge = -1, right edge = 1, bottom edge = -1. top edge = 1 float fWidth = (float) GetActualVideoModeParams().width; float fHeight = (float) GetActualVideoModeParams().height; float fPercentShiftX = SCALE( fTranslateX, 0, fWidth, 0, +2.0f ); float fPercentShiftY = SCALE( fTranslateY, 0, fHeight, 0, -2.0f ); float fPercentScaleX = SCALE( fAddWidth, 0, fWidth, 1.0f, 2.0f ); float fPercentScaleY = SCALE( fAddHeight, 0, fHeight, 1.0f, 2.0f ); RageMatrix m1; RageMatrix m2; RageMatrixTranslation( &m1, fPercentShiftX, fPercentShiftY, 0 ); RageMatrixScaling( &m2, fPercentScaleX, fPercentScaleY, 1 ); RageMatrix mOut; RageMatrixMultiply( &mOut, &m1, &m2 ); return mOut; }
bool RageDisplay::SaveScreenshot( RString sPath, GraphicsFileFormat format ) { RageTimer timer; RageSurface *surface = this->CreateScreenshot(); // LOG->Trace( "CreateScreenshot took %f seconds", timer.GetDeltaTime() ); /* Unless we're in lossless, resize the image to 640x480. If we're saving lossy, * there's no sense in saving 1280x960 screenshots, and we don't want to output * screenshots in a strange (non-1) sample aspect ratio. */ if( format != SAVE_LOSSLESS && format != SAVE_LOSSLESS_SENSIBLE ) { // Maintain the DAR. ASSERT( GetActualVideoModeParams().fDisplayAspectRatio > 0 ); int iHeight = 480; // This used to be lrintf. However, lrintf causes odd resolutions like // 639x480 (4:3) and 853x480 (16:9). ceilf gives correct values. -aj int iWidth = static_cast<int>(ceilf( iHeight * GetActualVideoModeParams().fDisplayAspectRatio )); timer.Touch(); RageSurfaceUtils::Zoom( surface, iWidth, iHeight ); // LOG->Trace( "%ix%i -> %ix%i (%.3f) in %f seconds", surface->w, surface->h, iWidth, iHeight, GetActualVideoModeParams().fDisplayAspectRatio, timer.GetDeltaTime() ); } RageFile out; if( !out.Open( sPath, RageFile::WRITE ) ) { LOG->Trace("Couldn't write %s: %s", sPath.c_str(), out.GetError().c_str() ); SAFE_DELETE( surface ); return false; } bool bSuccess = false; timer.Touch(); RString strError = ""; switch( format ) { case SAVE_LOSSLESS: bSuccess = RageSurfaceUtils::SaveBMP( surface, out ); break; case SAVE_LOSSLESS_SENSIBLE: bSuccess = RageSurfaceUtils::SavePNG( surface, out, strError ); break; case SAVE_LOSSY_LOW_QUAL: bSuccess = RageSurfaceUtils::SaveJPEG( surface, out, false ); break; case SAVE_LOSSY_HIGH_QUAL: bSuccess = RageSurfaceUtils::SaveJPEG( surface, out, true ); break; DEFAULT_FAIL( format ); } // LOG->Trace( "Saving Screenshot file took %f seconds.", timer.GetDeltaTime() ); SAFE_DELETE( surface ); if( !bSuccess ) { LOG->Trace("Couldn't write %s: %s", sPath.c_str(), out.GetError().c_str() ); return false; } return true; }
void RageDisplay_D3D::EndFrame() { g_pd3dDevice->EndScene(); FrameLimitBeforeVsync( GetActualVideoModeParams().rate ); g_pd3dDevice->Present( 0, 0, 0, 0 ); FrameLimitAfterVsync(); RageDisplay::EndFrame(); }
/* gluLookAt. The result is pre-multiplied to the matrix (M = L * M) instead of * post-multiplied. */ void RageDisplay::LoadLookAt( float fFOV, const RageVector3 &Eye, const RageVector3 &At, const RageVector3 &Up ) { float fAspect = GetActualVideoModeParams().fDisplayAspectRatio; g_ProjectionStack.LoadMatrix( GetPerspectiveMatrix(fFOV, fAspect, 1, 1000) ); // Flip the Y coordinate, so positive numbers go down. g_ProjectionStack.Scale( 1, -1, 1 ); g_ViewStack.LoadMatrix( RageLookAt(Eye.x, Eye.y, Eye.z, At.x, At.y, At.z, Up.x, Up.y, Up.z) ); }