]> git.lizzy.rs Git - dragonfireclient.git/blob - src/camera.h
View bobbing is slower in the water.
[dragonfireclient.git] / src / camera.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef CAMERA_HEADER
21 #define CAMERA_HEADER
22
23 #include "common_irrlicht.h"
24 #include "utility.h"
25
26 class LocalPlayer;
27 class MapDrawControl;
28
29 /*
30         Client camera class, manages the player and camera scene nodes, the viewing distance
31         and performs view bobbing etc.
32 */
33 class Camera
34 {
35 public:
36         Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control);
37         ~Camera();
38
39         // Get player scene node.
40         // This node is positioned at the player's torso (without any view bobbing),
41         // as given by Player::m_position. Yaw is applied but not pitch.
42         // Things like wielded tools should be positioned relative to this node.
43         inline scene::ISceneNode* getPlayerNode() const
44         {
45                 return m_playernode;
46         }
47
48         // Get camera scene node.
49         // It has the eye transformation and view bobbing applied.
50         inline scene::ICameraSceneNode* getCameraNode() const
51         {
52                 return m_cameranode;
53         }
54
55         // Get the camera position (in absolute scene coordinates).
56         // This has view bobbing applied.
57         inline v3f getPosition() const
58         {
59                 return m_camera_position;
60         }
61
62         // Get the camera direction (in absolute camera coordinates).
63         // This has view bobbing applied.
64         inline v3f getDirection() const
65         {
66                 return m_camera_direction;
67         }
68
69         // Horizontal field of view
70         inline f32 getFovX() const
71         {
72                 return m_fov_x;
73         }
74
75         // Vertical field of view
76         inline f32 getFovY() const
77         {
78                 return m_fov_y;
79         }
80
81         // Get maximum of getFovX() and getFovY()
82         inline f32 getFovMax() const
83         {
84                 return MYMAX(m_fov_x, m_fov_y);
85         }
86
87         // Step the camera: updates the viewing range and view bobbing.
88         void step(f32 dtime);
89
90         // Update the camera from the local player's position.
91         // frametime is used to adjust the viewing range.
92         void update(LocalPlayer* player, f32 frametime, v2u32 screensize);
93
94         // Render distance feedback loop
95         void updateViewingRange(f32 frametime_in);
96
97         // Update settings from g_settings
98         void updateSettings();
99
100 private:
101         // Scene manager and nodes
102         scene::ISceneManager* m_smgr;
103         scene::ISceneNode* m_playernode;
104         scene::ICameraSceneNode* m_cameranode;
105
106         // draw control
107         MapDrawControl& m_draw_control;
108
109         // viewing_range_min_nodes setting
110         f32 m_viewing_range_min;
111         // viewing_range_max_nodes setting
112         f32 m_viewing_range_max;
113
114         // Absolute camera position
115         v3f m_camera_position;
116         // Absolute camera direction
117         v3f m_camera_direction;
118
119         // Field of view and aspect ratio stuff
120         f32 m_aspect;
121         f32 m_fov_x;
122         f32 m_fov_y;
123
124         // Stuff for viewing range calculations
125         f32 m_wanted_frametime;
126         f32 m_added_frametime;
127         s16 m_added_frames;
128         f32 m_range_old;
129         f32 m_frametime_old;
130         f32 m_frametime_counter;
131         f32 m_time_per_range;
132
133         // View bobbing animation frame (0 <= m_view_bobbing < 0x1000000)
134         s32 m_view_bobbing_anim;
135         // If 0, view bobbing is off (e.g. player is standing).
136         // If 1, view bobbing is on (player is walking).
137         // If 2, view bobbing is getting switched off.
138         s32 m_view_bobbing_state;
139         // If true, view bobbing is slown down (player is swimming)
140         bool m_view_bobbing_slow;
141 };
142
143 #endif
144