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.
22 #include "irrlichttypes_extrabloated.h"
23 #include "inventory.h"
24 #include "client/tile.h"
25 #include <ICameraSceneNode.h>
26 #include <ISceneNode.h>
30 struct MapDrawControl;
32 class WieldMeshSceneNode;
35 Nametag(scene::ISceneNode *a_parent_node,
36 const std::string &a_nametag_text,
37 const video::SColor &a_nametag_color,
38 const v3f &a_nametag_pos):
39 parent_node(a_parent_node),
40 nametag_text(a_nametag_text),
41 nametag_color(a_nametag_color),
42 nametag_pos(a_nametag_pos)
45 scene::ISceneNode *parent_node;
46 std::string nametag_text;
47 video::SColor nametag_color;
51 enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT};
54 Client camera class, manages the player and camera scene nodes, the viewing distance
55 and performs view bobbing etc. It also displays the wielded tool in front of the
61 Camera(MapDrawControl &draw_control, Client *client);
64 // Get camera scene node.
65 // It has the eye transformation, pitch and view bobbing applied.
66 inline scene::ICameraSceneNode* getCameraNode() const
71 // Get the camera position (in absolute scene coordinates).
72 // This has view bobbing applied.
73 inline v3f getPosition() const
75 return m_camera_position;
78 // Returns the absolute position of the head SceneNode in the world
79 inline v3f getHeadPosition() const
81 return m_headnode->getAbsolutePosition();
84 // Get the camera direction (in absolute camera coordinates).
85 // This has view bobbing applied.
86 inline v3f getDirection() const
88 return m_camera_direction;
91 // Get the camera offset
92 inline v3s16 getOffset() const
94 return m_camera_offset;
97 // Horizontal field of view
98 inline f32 getFovX() const
103 // Vertical field of view
104 inline f32 getFovY() const
109 // Get maximum of getFovX() and getFovY()
110 inline f32 getFovMax() const
112 return MYMAX(m_fov_x, m_fov_y);
115 // Notify about new server-sent FOV and initialize smooth FOV transition
116 void notifyFovChange();
118 // Checks if the constructor was able to create the scene nodes
119 bool successfullyCreated(std::string &error_message);
121 // Step the camera: updates the viewing range and view bobbing.
122 void step(f32 dtime);
124 // Update the camera from the local player's position.
125 // busytime is used to adjust the viewing range.
126 void update(LocalPlayer* player, f32 frametime, f32 busytime,
127 f32 tool_reload_ratio);
129 // Update render distance
130 void updateViewingRange();
132 // Start digging animation
133 // Pass 0 for left click, 1 for right click
134 void setDigging(s32 button);
136 // Replace the wielded item mesh
137 void wield(const ItemStack &item);
139 // Draw the wielded tool.
140 // This has to happen *after* the main scene is drawn.
141 // Warning: This clears the Z buffer.
142 void drawWieldedTool(irr::core::matrix4* translation=NULL);
144 // Toggle the current camera mode
145 void toggleCameraMode() {
146 if (m_camera_mode == CAMERA_MODE_FIRST)
147 m_camera_mode = CAMERA_MODE_THIRD;
148 else if (m_camera_mode == CAMERA_MODE_THIRD)
149 m_camera_mode = CAMERA_MODE_THIRD_FRONT;
151 m_camera_mode = CAMERA_MODE_FIRST;
154 // Set the current camera mode
155 inline void setCameraMode(CameraMode mode)
157 m_camera_mode = mode;
160 //read the current camera mode
161 inline CameraMode getCameraMode()
163 return m_camera_mode;
166 Nametag *addNametag(scene::ISceneNode *parent_node,
167 const std::string &nametag_text, video::SColor nametag_color,
170 void removeNametag(Nametag *nametag);
174 inline void addArmInertia(f32 player_yaw);
178 scene::ISceneNode *m_playernode = nullptr;
179 scene::ISceneNode *m_headnode = nullptr;
180 scene::ICameraSceneNode *m_cameranode = nullptr;
182 scene::ISceneManager *m_wieldmgr = nullptr;
183 WieldMeshSceneNode *m_wieldnode = nullptr;
186 MapDrawControl& m_draw_control;
190 // Default Client FOV (as defined by the "fov" setting)
193 // Absolute camera position
194 v3f m_camera_position;
195 // Absolute camera direction
196 v3f m_camera_direction;
198 v3s16 m_camera_offset;
200 // Server-sent FOV variables
201 bool m_server_sent_fov = false;
202 f32 m_curr_fov_degrees, m_old_fov_degrees, m_target_fov_degrees;
204 // FOV transition variables
205 bool m_fov_transition_active = false;
206 f32 m_fov_diff, m_transition_time;
208 v2f m_wieldmesh_offset = v2f(55.0f, -35.0f);
214 // Field of view and aspect ratio stuff
219 // View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
220 f32 m_view_bobbing_anim = 0.0f;
221 // If 0, view bobbing is off (e.g. player is standing).
222 // If 1, view bobbing is on (player is walking).
223 // If 2, view bobbing is getting switched off.
224 s32 m_view_bobbing_state = 0;
225 // Speed of view bobbing animation
226 f32 m_view_bobbing_speed = 0.0f;
228 f32 m_view_bobbing_fall = 0.0f;
230 // Digging animation frame (0 <= m_digging_anim < 1)
231 f32 m_digging_anim = 0.0f;
232 // If -1, no digging animation
233 // If 0, left-click digging animation
234 // If 1, right-click digging animation
235 s32 m_digging_button = -1;
237 // Animation when changing wielded item
238 f32 m_wield_change_timer = 0.125f;
239 ItemStack m_wield_item_next;
241 CameraMode m_camera_mode = CAMERA_MODE_FIRST;
243 f32 m_cache_fall_bobbing_amount;
244 f32 m_cache_view_bobbing_amount;
247 std::list<Nametag *> m_nametags;