Ticket #941: FOV-controls-09042011.patch

File FOV-controls-09042011.patch, 11.6 KB (added by historic_bruno, 19 months ago)
  • binaries/data/config/default.cfg

     
    8585view.zoom.min = 96.0 
    8686view.zoom.max = 512.0 
    8787view.zoom.default = 192.0 
     88view.fov.min = 20 
     89view.fov.max = 70 
     90view.fov.speed = 0.5 
     91view.fov.speed.wheel = 0.1 
     92view.fov.default = 45 
    8893view.pos.smoothness = 0.1 
    8994view.zoom.smoothness = 0.4 
    9095view.rotate.x.smoothness = 0.5 
    9196view.rotate.y.smoothness = 0.3 
     97view.fov.smoothness = 0.3 
    9298 
    9399; HOTKEY MAPPINGS: 
    94100 
     
    120126hotkey.camera.rotate.ccw = "Ctrl+RightArrow", "Ctrl+D", E ; Rotate camera anticlockwise around terrain 
    121127hotkey.camera.rotate.wheel.cw = "Shift+WheelUp", MouseX1    ; Rotate camera clockwise around terrain (stepped control) 
    122128hotkey.camera.rotate.wheel.ccw = "Shift+WheelDown", MouseX2 ; Rotate camera anticlockwise around terrain (stepped control) 
     129hotkey.camera.fov.wheel.increase = "Ctrl+WheelUp" 
     130hotkey.camera.fov.wheel.decrease = "Ctrl+WheelDown" 
    123131hotkey.camera.pan = MouseMiddle, ForwardSlash             ; Enable scrolling by moving mouse 
    124132hotkey.camera.left = A, LeftArrow                         ; Scroll or rotate left 
    125133hotkey.camera.right = D, RightArrow                       ; Scroll or rotate right 
  • source/graphics/GameView.cpp

     
    5959 
    6060extern int g_xres, g_yres; 
    6161 
    62 const float CGameView::defaultFOV = DEGTORAD(20.f); 
    6362const float CGameView::defaultNear = 16.f; 
    6463const 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 
    6664 
    6765// Maximum distance outside the edge of the map that the camera's 
    6866// focus point can be moved 
     
    184182        ViewZoomMin(0), 
    185183        ViewZoomMax(0), 
    186184        ViewZoomDefault(0), 
     185        ViewFOVMin(0), 
     186        ViewFOVMax(0), 
     187        ViewFOVDefault(0), 
     188        ViewFOVSpeed(0), 
     189        ViewFOVSpeedWheel(0), 
    187190        JoystickPanX(-1), 
    188191        JoystickPanY(-1), 
    189192        JoystickRotateX(-1), 
     
    196199        PosZ(0, 0, 0.01f), 
    197200        Zoom(0, 0, 0.1f), 
    198201        RotateX(0, 0, 0.001f), 
    199         RotateY(0, 0, 0.001f) 
     202        RotateY(0, 0, 0.001f), 
     203        FOV(DEGTORAD(45.0f), 0, 0.1f) 
    200204    { 
    201205    } 
    202206 
     
    280284    float ViewZoomMin; 
    281285    float ViewZoomMax; 
    282286    float ViewZoomDefault; 
     287    float ViewFOVMin; 
     288    float ViewFOVMax; 
     289    float ViewFOVDefault; 
     290    float ViewFOVSpeed; 
     291    float ViewFOVSpeedWheel; 
    283292    int JoystickPanX; 
    284293    int JoystickPanY; 
    285294    int JoystickRotateX; 
     
    295304    CSmoothedValue Zoom; 
    296305    CSmoothedValue RotateX; // inclination around x axis (relative to camera) 
    297306    CSmoothedValue RotateY; // rotation around y (vertical) axis 
     307    CSmoothedValue FOV; 
    298308 
    299309    static void ScriptingInit(); 
    300310}; 
     
    333343    vp.m_Height=g_yres; 
    334344    m->ViewCamera.SetViewPort(vp); 
    335345 
    336     m->ViewCamera.SetProjection(defaultNear, defaultFar, defaultFOV); 
     346    m->ViewCamera.SetProjection(defaultNear, defaultFar, m->FOV.GetValue()); 
    337347    SetupCameraMatrixSmooth(m, &m->ViewCamera.m_Orientation); 
    338348    m->ViewCamera.UpdateFrustum(); 
    339349 
     
    351361void CGameView::SetViewport(const SViewPort& vp) 
    352362{ 
    353363    m->ViewCamera.SetViewPort(vp); 
    354     m->ViewCamera.SetProjection(defaultNear, defaultFar, defaultFOV); 
     364    m->ViewCamera.SetProjection(defaultNear, defaultFar, m->FOV.GetValue()); 
    355365} 
    356366 
    357367CObjectManager& CGameView::GetObjectManager() const 
     
    415425    CFG_GET_SYS_VAL("view.zoom.min", Float, m->ViewZoomMin); 
    416426    CFG_GET_SYS_VAL("view.zoom.max", Float, m->ViewZoomMax); 
    417427    CFG_GET_SYS_VAL("view.zoom.default", Float, m->ViewZoomDefault); 
     428    CFG_GET_SYS_VAL("view.fov.min", Float, m->ViewFOVMin); 
     429    CFG_GET_SYS_VAL("view.fov.max", Float, m->ViewFOVMax); 
     430    CFG_GET_SYS_VAL("view.fov.default", Float, m->ViewFOVDefault); 
     431    CFG_GET_SYS_VAL("view.fov.speed", Float, m->ViewFOVSpeed); 
     432    CFG_GET_SYS_VAL("view.fov.speed.wheel", Float, m->ViewFOVSpeedWheel); 
    418433 
    419434    CFG_GET_SYS_VAL("joystick.camera.pan.x", Int, m->JoystickPanX); 
    420435    CFG_GET_SYS_VAL("joystick.camera.pan.y", Int, m->JoystickPanY); 
     
    429444    CFG_GET_SYS_VAL("view.zoom.smoothness", Float, m->Zoom.m_Smoothness); 
    430445    CFG_GET_SYS_VAL("view.rotate.x.smoothness", Float, m->RotateX.m_Smoothness); 
    431446    CFG_GET_SYS_VAL("view.rotate.y.smoothness", Float, m->RotateY.m_Smoothness); 
     447    CFG_GET_SYS_VAL("view.fov.smoothness", Float, m->FOV.m_Smoothness); 
    432448 
    433449    m->RotateX.SetValue(DEGTORAD(m->ViewRotateXDefault)); 
    434450    m->RotateY.SetValue(DEGTORAD(m->ViewRotateYDefault)); 
     451    m->FOV.SetValue(DEGTORAD(m->ViewFOVDefault)); 
    435452 
    436453    return 0; 
    437454} 
     
    463480        // from model rendering; as it is now, a shadow map is only rendered if its associated model is to be 
    464481        // rendered. 
    465482        // (See http://trac.wildfiregames.com/ticket/504) 
    466         m->CullCamera.SetProjection(defaultNear, defaultFar, defaultCullFOV); 
     483        m->CullCamera.SetProjection(defaultNear, defaultFar, GetCullFOV()); 
    467484        m->CullCamera.UpdateFrustum(); 
    468485    } 
    469486    g_Renderer.SetSceneCamera(m->ViewCamera, m->CullCamera); 
     
    774791    } 
    775792 
    776793    if (m->ConstrainCamera) 
     794    { 
    777795        m->RotateX.ClampSmoothly(DEGTORAD(m->ViewRotateXMin), DEGTORAD(m->ViewRotateXMax)); 
     796        m->FOV.ClampSmoothly(DEGTORAD(m->ViewFOVMin), DEGTORAD(m->ViewFOVMax)); 
     797    } 
    778798 
    779799    ClampDistance(m, true); 
    780800 
     
    889909 
    890910    m->RotateY.Wrap(-(float)M_PI, (float)M_PI); 
    891911 
     912    m->FOV.Update(DeltaTime); 
     913 
    892914    // Update the camera matrix 
     915    m->ViewCamera.SetProjection(defaultNear, defaultFar, m->FOV.GetValue()); 
    893916    SetupCameraMatrixSmooth(m, &m->ViewCamera.m_Orientation); 
    894917    m->ViewCamera.UpdateFrustum(); 
    895918} 
     
    934957    m->PosZ.SetValue(target.Z - delta.Z); 
    935958    m->RotateX.SetValue(DEGTORAD(m->ViewRotateXDefault)); 
    936959    m->RotateY.SetValue(DEGTORAD(m->ViewRotateYDefault)); 
     960    m->FOV.SetValue(DEGTORAD(m->ViewFOVDefault)); 
    937961 
    938962    ClampDistance(m, false); 
    939963 
     
    958982    // Reset orientations to default 
    959983    m->RotateX.SetValueSmoothly(DEGTORAD(m->ViewRotateXDefault)); 
    960984    m->RotateY.SetValueSmoothly(DEGTORAD(m->ViewRotateYDefault)); 
     985    m->FOV.SetValue(DEGTORAD(m->ViewFOVDefault)); 
    961986} 
    962987 
    963988void CGameView::CameraFollow(entity_id_t entity, bool firstPerson) 
     
    971996    return m->FollowEntity; 
    972997} 
    973998 
     999float CGameView::GetFOV() const 
     1000{ 
     1001    return m->FOV.GetValue(); 
     1002} 
     1003 
     1004float CGameView::GetCullFOV() const 
     1005{ 
     1006    return m->FOV.GetValue() + DEGTORAD(6.0f);  //add 6 degrees to the default FOV for use with the culling frustum; 
     1007} 
     1008 
    9741009InReaction game_view_handler(const SDL_Event_* ev) 
    9751010{ 
    9761011    // put any events that must be processed even if inactive here 
     
    10321067            m->RotateY.AddSmoothly(-m->ViewRotateYSpeedWheel); 
    10331068            return IN_HANDLED; 
    10341069        } 
     1070        else if (hotkey == "camera.fov.wheel.increase") 
     1071        { 
     1072            m->FOV.AddSmoothly(m->ViewFOVSpeedWheel); 
     1073            return IN_HANDLED; 
     1074        } 
     1075        else if (hotkey == "camera.fov.wheel.decrease") 
     1076        { 
     1077            m->FOV.AddSmoothly(-m->ViewFOVSpeedWheel); 
     1078            return IN_HANDLED; 
     1079        } 
    10351080        else if (hotkey == "camera.reset") 
    10361081        { 
    10371082            ResetCameraAngleZoom(); 
  • source/graphics/GameView.h

     
    3838{ 
    3939    NONCOPYABLE(CGameView); 
    4040public: 
    41     static const float defaultFOV, defaultCullFOV, defaultNear, defaultFar; 
     41    static const float defaultNear, defaultFar; 
    4242 
    4343private: 
    4444    CGameViewImpl* m; 
     
    8888    void CameraFollow(entity_id_t entity, bool firstPerson); 
    8989    entity_id_t GetFollowedEntity(); 
    9090 
     91    float GetFOV() const; 
     92    float GetCullFOV() const; 
     93 
    9194    CCamera *GetCamera(); 
    9295    CCinemaManager* GetCinema(); 
    9396 
  • 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()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, g_Game->GetView()->GetFOV()); 
    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); 
     353        g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, g_Game->GetView()->GetFOV()); 
    354354 
    355355        g_Game->GetView()->GetCamera()->SetProjectionTile(1, 0, 0); 
    356356    } 
  • source/renderer/Renderer.cpp

     
    12201220    vp.m_X = 0; 
    12211221    vp.m_Y = 0; 
    12221222    m_ViewCamera.SetViewPort(vp); 
    1223     m_ViewCamera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV*1.05f); // Slightly higher than view FOV 
     1223    m_ViewCamera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, g_Game->GetView()->GetFOV()*1.05f); // Slightly higher than view FOV 
    12241224    CMatrix3D scaleMat; 
    12251225    scaleMat.SetScaling(m_Height/float(std::max(1, m_Width)), 1.0f, 1.0f); 
    12261226    m_ViewCamera.m_ProjMat = scaleMat * m_ViewCamera.m_ProjMat; 
     
    13041304    vp.m_X = 0; 
    13051305    vp.m_Y = 0; 
    13061306    m_ViewCamera.SetViewPort(vp); 
    1307     m_ViewCamera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV*1.05f); // Slightly higher than view FOV 
     1307    m_ViewCamera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, g_Game->GetView()->GetFOV()*1.05f); // Slightly higher than view FOV 
    13081308    CMatrix3D scaleMat; 
    13091309    scaleMat.SetScaling(m_Height/float(std::max(1, m_Width)), 1.0f, 1.0f); 
    13101310    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()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, g_Game->GetView()->GetFOV()); 
    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()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, g_Game->GetView()->GetFOV()); 
    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(CGameView::defaultNear, CGameView::defaultFar, g_Game->GetView()->GetFOV()); 
    224224    camera.UpdateFrustum(); 
    225225 
    226226    // Update the pathfinder display if necessary