]> git.lizzy.rs Git - dragonfireclient.git/blob - src/camera.h
645b9355d572758d639a0d51f94c1f49240f5b71
[dragonfireclient.git] / src / camera.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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 "irrlichttypes_extrabloated.h"
24 #include "inventory.h"
25 #include "mesh.h"
26 #include "tile.h"
27 #include "util/numeric.h"
28 #include <ICameraSceneNode.h>
29
30 #include "client.h"
31
32 class LocalPlayer;
33 struct MapDrawControl;
34 class IGameDef;
35
36 /*
37         Client camera class, manages the player and camera scene nodes, the viewing distance
38         and performs view bobbing etc. It also displays the wielded tool in front of the
39         first-person camera.
40 */
41 class Camera
42 {
43 public:
44         Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
45                         IGameDef *gamedef);
46         ~Camera();
47
48         // Get player scene node.
49         // This node is positioned at the player's torso (without any view bobbing),
50         // as given by Player::m_position. Yaw is applied but not pitch.
51         inline scene::ISceneNode* getPlayerNode() const
52         {
53                 return m_playernode;
54         }
55
56         // Get head scene node.
57         // It has the eye transformation and pitch applied,
58         // but no view bobbing.
59         inline scene::ISceneNode* getHeadNode() const
60         {
61                 return m_headnode;
62         }
63
64         // Get camera scene node.
65         // It has the eye transformation, pitch and view bobbing applied.
66         inline scene::ICameraSceneNode* getCameraNode() const
67         {
68                 return m_cameranode;
69         }
70
71         // Get the camera position (in absolute scene coordinates).
72         // This has view bobbing applied.
73         inline v3f getPosition() const
74         {
75                 return m_camera_position;
76         }
77
78         // Get the camera direction (in absolute camera coordinates).
79         // This has view bobbing applied.
80         inline v3f getDirection() const
81         {
82                 return m_camera_direction;
83         }
84         
85         // Get the camera offset
86         inline v3s16 getOffset() const
87         {
88                 return m_camera_offset;
89         }
90
91         // Horizontal field of view
92         inline f32 getFovX() const
93         {
94                 return m_fov_x;
95         }
96
97         // Vertical field of view
98         inline f32 getFovY() const
99         {
100                 return m_fov_y;
101         }
102
103         // Get maximum of getFovX() and getFovY()
104         inline f32 getFovMax() const
105         {
106                 return MYMAX(m_fov_x, m_fov_y);
107         }
108
109         // Checks if the constructor was able to create the scene nodes
110         bool successfullyCreated(std::wstring& error_message);
111
112         // Step the camera: updates the viewing range and view bobbing.
113         void step(f32 dtime);
114
115         // Update the camera from the local player's position.
116         // busytime is used to adjust the viewing range.
117         void update(LocalPlayer* player, f32 frametime, f32 busytime,
118                         v2u32 screensize, f32 tool_reload_ratio,
119                         int current_camera_mode, ClientEnvironment &c_env);
120
121         // Render distance feedback loop
122         void updateViewingRange(f32 frametime_in, f32 busytime_in);
123
124         // Start digging animation
125         // Pass 0 for left click, 1 for right click
126         void setDigging(s32 button);
127
128         // Replace the wielded item mesh
129         void wield(const ItemStack &item, u16 playeritem);
130
131         // Draw the wielded tool.
132         // This has to happen *after* the main scene is drawn.
133         // Warning: This clears the Z buffer.
134         void drawWieldedTool();
135
136 private:
137         // Scene manager and nodes
138         scene::ISceneManager* m_smgr;
139         scene::ISceneNode* m_playernode;
140         scene::ISceneNode* m_headnode;
141         scene::ICameraSceneNode* m_cameranode;
142
143         scene::ISceneManager* m_wieldmgr;
144         scene::IMeshSceneNode* m_wieldnode;
145         u8 m_wieldlight;
146
147         // draw control
148         MapDrawControl& m_draw_control;
149         
150         IGameDef *m_gamedef;
151
152         // Absolute camera position
153         v3f m_camera_position;
154         // Absolute camera direction
155         v3f m_camera_direction;
156         // Camera offset
157         v3s16 m_camera_offset;
158
159         // Field of view and aspect ratio stuff
160         f32 m_aspect;
161         f32 m_fov_x;
162         f32 m_fov_y;
163
164         // Stuff for viewing range calculations
165         f32 m_added_busytime;
166         s16 m_added_frames;
167         f32 m_range_old;
168         f32 m_busytime_old;
169         f32 m_frametime_counter;
170         f32 m_time_per_range;
171
172         // View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
173         f32 m_view_bobbing_anim;
174         // If 0, view bobbing is off (e.g. player is standing).
175         // If 1, view bobbing is on (player is walking).
176         // If 2, view bobbing is getting switched off.
177         s32 m_view_bobbing_state;
178         // Speed of view bobbing animation
179         f32 m_view_bobbing_speed;
180         // Fall view bobbing
181         f32 m_view_bobbing_fall;
182
183         // Digging animation frame (0 <= m_digging_anim < 1)
184         f32 m_digging_anim;
185         // If -1, no digging animation
186         // If 0, left-click digging animation
187         // If 1, right-click digging animation
188         s32 m_digging_button;
189
190         //dummymesh for camera
191         irr::scene::IAnimatedMesh* m_dummymesh;
192
193         // Animation when changing wielded item
194         f32 m_wield_change_timer;
195         scene::IMesh *m_wield_mesh_next;
196         u16 m_previous_playeritem;
197         std::string m_previous_itemname;
198 };
199
200 #endif