3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
23 #include "irrlichttypes_extrabloated.h"
24 #include "inventory.h"
26 #include "client/tile.h"
27 #include "util/numeric.h"
28 #include <ICameraSceneNode.h>
29 #include <ISceneNode.h>
35 struct MapDrawControl;
37 class WieldMeshSceneNode;
40 Nametag(scene::ISceneNode *a_parent_node,
41 const std::string &a_nametag_text,
42 const video::SColor &a_nametag_color):
43 parent_node(a_parent_node),
44 nametag_text(a_nametag_text),
45 nametag_color(a_nametag_color)
48 scene::ISceneNode *parent_node;
49 std::string nametag_text;
50 video::SColor nametag_color;
53 enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT};
56 Client camera class, manages the player and camera scene nodes, the viewing distance
57 and performs view bobbing etc. It also displays the wielded tool in front of the
63 Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
67 // Get camera scene node.
68 // It has the eye transformation, pitch and view bobbing applied.
69 inline scene::ICameraSceneNode* getCameraNode() const
74 // Get the camera position (in absolute scene coordinates).
75 // This has view bobbing applied.
76 inline v3f getPosition() const
78 return m_camera_position;
81 // Get the camera direction (in absolute camera coordinates).
82 // This has view bobbing applied.
83 inline v3f getDirection() const
85 return m_camera_direction;
88 // Get the camera offset
89 inline v3s16 getOffset() const
91 return m_camera_offset;
94 // Horizontal field of view
95 inline f32 getFovX() const
100 // Vertical field of view
101 inline f32 getFovY() const
106 // Get maximum of getFovX() and getFovY()
107 inline f32 getFovMax() const
109 return MYMAX(m_fov_x, m_fov_y);
112 // Checks if the constructor was able to create the scene nodes
113 bool successfullyCreated(std::string &error_message);
115 // Step the camera: updates the viewing range and view bobbing.
116 void step(f32 dtime);
118 // Update the camera from the local player's position.
119 // busytime is used to adjust the viewing range.
120 void update(LocalPlayer* player, f32 frametime, f32 busytime,
121 f32 tool_reload_ratio, ClientEnvironment &c_env);
123 // Update render distance
124 void updateViewingRange();
126 // Start digging animation
127 // Pass 0 for left click, 1 for right click
128 void setDigging(s32 button);
130 // Replace the wielded item mesh
131 void wield(const ItemStack &item);
133 // Draw the wielded tool.
134 // This has to happen *after* the main scene is drawn.
135 // Warning: This clears the Z buffer.
136 void drawWieldedTool(irr::core::matrix4* translation=NULL);
138 // Toggle the current camera mode
139 void toggleCameraMode() {
140 if (m_camera_mode == CAMERA_MODE_FIRST)
141 m_camera_mode = CAMERA_MODE_THIRD;
142 else if (m_camera_mode == CAMERA_MODE_THIRD)
143 m_camera_mode = CAMERA_MODE_THIRD_FRONT;
145 m_camera_mode = CAMERA_MODE_FIRST;
148 // Set the current camera mode
149 inline void setCameraMode(CameraMode mode)
151 m_camera_mode = mode;
154 //read the current camera mode
155 inline CameraMode getCameraMode()
157 return m_camera_mode;
160 Nametag *addNametag(scene::ISceneNode *parent_node,
161 std::string nametag_text, video::SColor nametag_color);
163 void removeNametag(Nametag *nametag);
165 const std::list<Nametag *> &getNametags() { return m_nametags; }
171 scene::ISceneNode *m_playernode = nullptr;
172 scene::ISceneNode *m_headnode = nullptr;
173 scene::ICameraSceneNode *m_cameranode = nullptr;
175 scene::ISceneManager *m_wieldmgr = nullptr;
176 WieldMeshSceneNode *m_wieldnode = nullptr;
179 MapDrawControl& m_draw_control;
182 video::IVideoDriver *m_driver;
184 // Absolute camera position
185 v3f m_camera_position;
186 // Absolute camera direction
187 v3f m_camera_direction;
189 v3s16 m_camera_offset;
191 // Field of view and aspect ratio stuff
196 // View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
197 f32 m_view_bobbing_anim = 0.0f;
198 // If 0, view bobbing is off (e.g. player is standing).
199 // If 1, view bobbing is on (player is walking).
200 // If 2, view bobbing is getting switched off.
201 s32 m_view_bobbing_state = 0;
202 // Speed of view bobbing animation
203 f32 m_view_bobbing_speed = 0.0f;
205 f32 m_view_bobbing_fall = 0.0f;
207 // Digging animation frame (0 <= m_digging_anim < 1)
208 f32 m_digging_anim = 0.0f;
209 // If -1, no digging animation
210 // If 0, left-click digging animation
211 // If 1, right-click digging animation
212 s32 m_digging_button = -1;
214 // Animation when changing wielded item
215 f32 m_wield_change_timer = 0.125f;
216 ItemStack m_wield_item_next;
218 CameraMode m_camera_mode = CAMERA_MODE_FIRST;
220 f32 m_cache_fall_bobbing_amount;
221 f32 m_cache_view_bobbing_amount;
223 f32 m_cache_zoom_fov;
225 std::list<Nametag *> m_nametags;