Ticket #941: FOV-improved-11162011.patch

File FOV-improved-11162011.patch, 9.0 KB (added by historic_bruno, 12 years ago)
  • binaries/data/config/default.cfg

     
    7575view.rotate.x.speed = 1.2
    7676view.rotate.x.min = 20
    7777view.rotate.x.max = 60
    78 view.rotate.x.default = 30
     78view.rotate.x.default = 40
    7979view.rotate.y.speed = 2.0
    8080view.rotate.y.speed.wheel = 0.45
    8181view.rotate.y.default = 0.0
    8282view.drag.speed = 0.5
    8383view.zoom.speed = 256.0
    8484view.zoom.speed.wheel = 32.0
    85 view.zoom.min = 96.0
    86 view.zoom.max = 512.0
    87 view.zoom.default = 192.0
     85view.zoom.min = 64.0
     86view.zoom.max = 256.0
     87view.zoom.default = 128.0
    8888view.pos.smoothness = 0.1
    8989view.zoom.smoothness = 0.4
    9090view.rotate.x.smoothness = 0.5
    9191view.rotate.y.smoothness = 0.3
     92view.near = 16.0                            ; Near plane distance
     93view.far = 4096.0                           ; Far plane distance
     94view.fov = 45.0                             ; Field of view (degrees), lower is narrow, higher is wide
    9295
    9396; HOTKEY MAPPINGS:
    9497
  • source/graphics/GameView.cpp

     
    5959
    6060extern int g_xres, g_yres;
    6161
    62 const float CGameView::defaultFOV = DEGTORAD(20.f);
    63 const float CGameView::defaultNear = 16.f;
    64 const float CGameView::defaultFar = 4096.f;
    65 const float CGameView::defaultCullFOV = CGameView::defaultFOV + DEGTORAD(6.0f); //add 6 degrees to the default FOV for use with the culling frustum
    66 
    6762// Maximum distance outside the edge of the map that the camera's
    6863// focus point can be moved
    6964static const float CAMERA_EDGE_MARGIN = 2.0f*CELL_SIZE;
     
    280275    float ViewZoomMin;
    281276    float ViewZoomMax;
    282277    float ViewZoomDefault;
     278    float ViewFOV;
     279    float ViewNear;
     280    float ViewFar;
    283281    int JoystickPanX;
    284282    int JoystickPanY;
    285283    int JoystickRotateX;
     
    333331    vp.m_Height=g_yres;
    334332    m->ViewCamera.SetViewPort(vp);
    335333
    336     m->ViewCamera.SetProjection(defaultNear, defaultFar, defaultFOV);
     334    m->ViewCamera.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
    337335    SetupCameraMatrixSmooth(m, &m->ViewCamera.m_Orientation);
    338336    m->ViewCamera.UpdateFrustum();
    339337
     
    351349void CGameView::SetViewport(const SViewPort& vp)
    352350{
    353351    m->ViewCamera.SetViewPort(vp);
    354     m->ViewCamera.SetProjection(defaultNear, defaultFar, defaultFOV);
     352    m->ViewCamera.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
    355353}
    356354
    357355CObjectManager& CGameView::GetObjectManager() const
     
    430428    CFG_GET_SYS_VAL("view.rotate.x.smoothness", Float, m->RotateX.m_Smoothness);
    431429    CFG_GET_SYS_VAL("view.rotate.y.smoothness", Float, m->RotateY.m_Smoothness);
    432430
     431    CFG_GET_SYS_VAL("view.near", Float, m->ViewNear);
     432    CFG_GET_SYS_VAL("view.far", Float, m->ViewFar);
     433    CFG_GET_SYS_VAL("view.fov", Float, m->ViewFOV);
     434
     435    // Convert to radians
    433436    m->RotateX.SetValue(DEGTORAD(m->ViewRotateXDefault));
    434437    m->RotateY.SetValue(DEGTORAD(m->ViewRotateYDefault));
     438    m->ViewFOV = DEGTORAD(m->ViewFOV);
    435439
    436440    return 0;
    437441}
     
    463467        // from model rendering; as it is now, a shadow map is only rendered if its associated model is to be
    464468        // rendered.
    465469        // (See http://trac.wildfiregames.com/ticket/504)
    466         m->CullCamera.SetProjection(defaultNear, defaultFar, defaultCullFOV);
     470        m->CullCamera.SetProjection(m->ViewNear, m->ViewFar, GetCullFOV());
    467471        m->CullCamera.UpdateFrustum();
    468472    }
    469473    g_Renderer.SetSceneCamera(m->ViewCamera, m->CullCamera);
     
    774778    }
    775779
    776780    if (m->ConstrainCamera)
     781    {
    777782        m->RotateX.ClampSmoothly(DEGTORAD(m->ViewRotateXMin), DEGTORAD(m->ViewRotateXMax));
     783    }
    778784
    779785    ClampDistance(m, true);
    780786
     
    890896    m->RotateY.Wrap(-(float)M_PI, (float)M_PI);
    891897
    892898    // Update the camera matrix
     899    m->ViewCamera.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
    893900    SetupCameraMatrixSmooth(m, &m->ViewCamera.m_Orientation);
    894901    m->ViewCamera.UpdateFrustum();
    895902}
     
    971978    return m->FollowEntity;
    972979}
    973980
     981float CGameView::GetNear() const
     982{
     983    return m->ViewNear;
     984}
     985
     986float CGameView::GetFar() const
     987{
     988    return m->ViewFar;
     989}
     990
     991float CGameView::GetFOV() const
     992{
     993    return m->ViewFOV;
     994}
     995
     996float CGameView::GetCullFOV() const
     997{
     998    return m->ViewFOV + DEGTORAD(6.0f); //add 6 degrees to the default FOV for use with the culling frustum;
     999}
     1000
     1001void CGameView::SetCameraProjection()
     1002{
     1003    m->ViewCamera.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
     1004}
     1005
    9741006InReaction game_view_handler(const SDL_Event_* ev)
    9751007{
    9761008    // put any events that must be processed even if inactive here
  • source/graphics/GameView.h

     
    3737class CGameView : private Scene
    3838{
    3939    NONCOPYABLE(CGameView);
    40 public:
    41     static const float defaultFOV, defaultCullFOV, defaultNear, defaultFar;
    42 
    4340private:
    4441    CGameViewImpl* m;
    4542
     
    8885    void CameraFollow(entity_id_t entity, bool firstPerson);
    8986    entity_id_t GetFollowedEntity();
    9087
     88    float GetNear() const;
     89    float GetFar() const;
     90    float GetFOV() const;
     91    float GetCullFOV() const;
     92
     93    // Set projection of current camera using near, far, and FOV values
     94    void SetCameraProjection();
     95
    9196    CCamera *GetCamera();
    9297    CCinemaManager* GetCinema();
    9398
  • source/ps/Util.cpp

     
    296296        g_Renderer.Resize(tile_w, tile_h);
    297297        SViewPort vp = { 0, 0, tile_w, tile_h };
    298298        g_Game->GetView()->GetCamera()->SetViewPort(vp);
    299         g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
     299        g_Game->GetView()->SetCameraProjection();
    300300    }
    301301
    302302    // Temporarily move everything onto the front buffer, so the user can
     
    350350        g_Renderer.Resize(g_xres, g_yres);
    351351        SViewPort vp = { 0, 0, g_xres, g_yres };
    352352        g_Game->GetView()->GetCamera()->SetViewPort(vp);
    353         g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
    354 
     353        g_Game->GetView()->SetCameraProjection();
    355354        g_Game->GetView()->GetCamera()->SetProjectionTile(1, 0, 0);
    356355    }
    357356
  • source/renderer/Renderer.cpp

     
    12231223    vp.m_X = 0;
    12241224    vp.m_Y = 0;
    12251225    m_ViewCamera.SetViewPort(vp);
    1226     m_ViewCamera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV*1.05f); // Slightly higher than view FOV
     1226    m_ViewCamera.SetProjection(g_Game->GetView()->GetNear(), g_Game->GetView()->GetFar(), g_Game->GetView()->GetFOV()*1.05f); // Slightly higher than view FOV
    12271227    CMatrix3D scaleMat;
    12281228    scaleMat.SetScaling(m_Height/float(std::max(1, m_Width)), 1.0f, 1.0f);
    12291229    m_ViewCamera.m_ProjMat = scaleMat * m_ViewCamera.m_ProjMat;
     
    13071307    vp.m_X = 0;
    13081308    vp.m_Y = 0;
    13091309    m_ViewCamera.SetViewPort(vp);
    1310     m_ViewCamera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV*1.05f); // Slightly higher than view FOV
     1310    m_ViewCamera.SetProjection(g_Game->GetView()->GetNear(), g_Game->GetView()->GetFar(), g_Game->GetView()->GetFOV()*1.05f); // Slightly higher than view FOV
    13111311    CMatrix3D scaleMat;
    13121312    scaleMat.SetScaling(m_Height/float(std::max(1, m_Width)), 1.0f, 1.0f);
    13131313    m_ViewCamera.m_ProjMat = scaleMat * m_ViewCamera.m_ProjMat;
  • source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp

     
    6060        g_Renderer.Resize(w, h);
    6161        SViewPort vp = { 0, 0, w, h };
    6262        g_Game->GetView()->GetCamera()->SetViewPort(vp);
    63         g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
     63        g_Game->GetView()->SetCameraProjection();
    6464    }
    6565
    6666    unsigned char* img = new unsigned char [w*h*3];
     
    113113        g_Renderer.Resize(g_xres, g_yres);
    114114        SViewPort vp = { 0, 0, g_xres, g_yres };
    115115        g_Game->GetView()->GetCamera()->SetViewPort(vp);
    116         g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
     116        g_Game->GetView()->SetCameraProjection();
    117117    }
    118118
    119119}
  • source/tools/atlas/GameInterface/View.cpp

     
    220220    SViewPort vp = { 0, 0, g_xres, g_yres };
    221221    CCamera& camera = GetCamera();
    222222    camera.SetViewPort(vp);
    223     camera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
     223    camera.SetProjection(g_Game->GetView()->GetNear(), g_Game->GetView()->GetFar(), g_Game->GetView()->GetFOV());
    224224    camera.UpdateFrustum();
    225225
    226226    // Update the pathfinder display if necessary