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"
27 #include "util/numeric.h"
28 #include <ICameraSceneNode.h>
33 struct MapDrawControl;
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
44 Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
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
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
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 // Get the camera direction (in absolute camera coordinates).
79 // This has view bobbing applied.
80 inline v3f getDirection() const
82 return m_camera_direction;
85 // Get the camera offset
86 inline v3s16 getOffset() const
88 return m_camera_offset;
91 // Horizontal field of view
92 inline f32 getFovX() const
97 // Vertical field of view
98 inline f32 getFovY() const
103 // Get maximum of getFovX() and getFovY()
104 inline f32 getFovMax() const
106 return MYMAX(m_fov_x, m_fov_y);
109 // Checks if the constructor was able to create the scene nodes
110 bool successfullyCreated(std::wstring& error_message);
112 // Step the camera: updates the viewing range and view bobbing.
113 void step(f32 dtime);
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);
121 // Render distance feedback loop
122 void updateViewingRange(f32 frametime_in, f32 busytime_in);
124 // Start digging animation
125 // Pass 0 for left click, 1 for right click
126 void setDigging(s32 button);
128 // Replace the wielded item mesh
129 void wield(const ItemStack &item, u16 playeritem);
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();
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;
143 scene::ISceneManager* m_wieldmgr;
144 scene::IMeshSceneNode* m_wieldnode;
148 MapDrawControl& m_draw_control;
152 // Absolute camera position
153 v3f m_camera_position;
154 // Absolute camera direction
155 v3f m_camera_direction;
157 v3s16 m_camera_offset;
159 // Field of view and aspect ratio stuff
164 // Stuff for viewing range calculations
165 f32 m_added_busytime;
169 f32 m_frametime_counter;
170 f32 m_time_per_range;
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;
181 f32 m_view_bobbing_fall;
183 // Digging animation frame (0 <= m_digging_anim < 1)
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;
190 //dummymesh for camera
191 irr::scene::IAnimatedMesh* m_dummymesh;
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;