From 1be7055f59d1535dcd9028dedba4986e7dccdff1 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 23 Apr 2003 02:23:51 +0000 Subject: [PATCH] working on perspective stuff for tilted menu items --- stepmania/src/RageDisplay.cpp | 81 +++++++++++++++++++++++------ stepmania/src/RageDisplay.h | 2 + stepmania/src/ScreenSelectMusic.cpp | 5 ++ 3 files changed, 73 insertions(+), 15 deletions(-) diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index 492afbc9b7..af40ef7ca4 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -148,22 +148,8 @@ void RageDisplay::SetupOpenGL() glHint(GL_POINT_SMOOTH_HINT, GL_DONT_CARE); /* Initialize the default ortho projection. */ - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - float left = 0, right = SCREEN_WIDTH, bottom = SCREEN_HEIGHT, top = 0; - if(strncmp((const char*)glGetString(GL_RENDERER),"GLDirect",strlen("GLDirect"))==0) - { - /* GLDirect incorrectly uses Direct3D's device coordinate system - * instead of OpenGL's, so we need to compensate. */ - left += 0.5f; - right += 0.5f; - bottom += 0.5f; - top += 0.5f; - } - - glOrtho(left, right, bottom, top, SCREEN_NEAR, SCREEN_FAR ); - glMatrixMode( GL_MODELVIEW ); + LoadMenuPerspective(0); // 0 FOV = ortho } RageDisplay::~RageDisplay() @@ -620,6 +606,70 @@ void RageDisplay::PopMatrix() ASSERT(g_ModelMatrixCnt-->0); } +void RageDisplay::LoadMenuPerspective(float fovDegrees) +{ + /* fovDegrees == 0 looks the same as an ortho projection. However, + * we don't want to mess with the ModelView stack because + * EnterPerspectiveMode's preserve location feature expectes there + * not to be any camera transforms. So, do a true ortho projection + * if fovDegrees == 0. Perhaps it would be more convenient to keep + * separate model and view stacks like D3D? + */ + if( fovDegrees == 0 ) + { + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + + float left = 0, right = SCREEN_WIDTH, bottom = SCREEN_HEIGHT, top = 0; + if(strncmp((const char*)glGetString(GL_RENDERER),"GLDirect",strlen("GLDirect"))==0) + { + /* GLDirect incorrectly uses Direct3D's device coordinate system + * instead of OpenGL's, so we need to compensate. */ + left += 0.5f; + right += 0.5f; + bottom += 0.5f; + top += 0.5f; + } + glOrtho(left, right, bottom, top, SCREEN_NEAR, SCREEN_FAR ); + + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + } + else + { + CLAMP( fovDegrees, 0.1f, 179.9f ); + float fovRadians = fovDegrees / 180.f * PI; + // tan(theta) = 320/d + float theta = fovRadians/2; + float fDistCameraFromImage = SCREEN_WIDTH/2 / tanf( theta ); + + /* It's the caller's responsibility to push first. */ + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + + glFrustum( + -(SCREEN_WIDTH/2)/fDistCameraFromImage, + +(SCREEN_WIDTH/2)/fDistCameraFromImage, + +(SCREEN_HEIGHT/2)/fDistCameraFromImage, + -(SCREEN_HEIGHT/2)/fDistCameraFromImage, + 1, + fDistCameraFromImage+1000 + ); + + glMatrixMode( GL_MODELVIEW ); + RageVector3 Up( 0.0f, 1.0f, 0.0f ); + RageVector3 Eye( CENTER_X, CENTER_Y, fDistCameraFromImage ); + RageVector3 At( CENTER_X, CENTER_Y, 0 ); + glLoadIdentity(); + gluLookAt(Eye.x, Eye.y, Eye.z, At.x, At.y, At.z, Up.x, Up.y, Up.z); + + /* GLDirect incorrectly uses Direct3D's device coordinate system + * instead of OpenGL's, so we need to compensate. */ + if(strncmp((const char*)glGetString(GL_RENDERER),"GLDirect",strlen("GLDirect"))==0) + glTranslatef( 0.5f, 0.5f, 0 ); + } +} + /* Switch from orthogonal to perspective view. * * Tricky: we want to maintain all of the zooms, rotations and translations @@ -655,6 +705,7 @@ void RageDisplay::EnterPerspective(float fov, bool preserve_loc, float near_clip float aspect = SCREEN_WIDTH/(float)SCREEN_HEIGHT; gluPerspective(fov, aspect, near_clip, far_clip); + /* Flip the Y coordinate, so positive numbers go down. */ glScalef(1, -1, 1); diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 7662489a1f..40364c1ae5 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -80,10 +80,12 @@ public: int GetMaxTextureSize() const; // This far clipping this might cause Z-fighting if we ever turn the z-buffer on + void LoadMenuPerspective(float fovDegrees); void EnterPerspective(float fov, bool preserve_loc = true, float near = 1, float far = 1000); void ExitPerspective(); void LookAt(const RageVector3 &Eye, const RageVector3 &At, const RageVector3 &Up); + /* Statistics */ int GetFPS() const; int GetVPF() const; diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 5b71cd3ef9..ec20a615eb 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -31,6 +31,7 @@ #include "ThemeManager.h" #include "Notes.h" #include "ActorUtil.h" +#include "RageDisplay.h" const int NUM_SCORE_DIGITS = 9; @@ -189,10 +190,14 @@ ScreenSelectMusic::~ScreenSelectMusic() void ScreenSelectMusic::DrawPrimitives() { + DISPLAY->LoadMenuPerspective(90); + m_Menu.DrawBottomLayer(); Screen::DrawPrimitives(); m_Menu.DrawTopLayer(); m_sprOptionsMessage.Draw(); + + DISPLAY->LoadMenuPerspective(0); } void ScreenSelectMusic::TweenOnScreen()