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;
36 enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT};
39 Client camera class, manages the player and camera scene nodes, the viewing distance
40 and performs view bobbing etc. It also displays the wielded tool in front of the
46 Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
50 // Get player scene node.
51 // This node is positioned at the player's torso (without any view bobbing),
52 // as given by Player::m_position. Yaw is applied but not pitch.
53 inline scene::ISceneNode* getPlayerNode() const
58 // Get head scene node.
59 // It has the eye transformation and pitch applied,
60 // but no view bobbing.
61 inline scene::ISceneNode* getHeadNode() const
66 // Get camera scene node.
67 // It has the eye transformation, pitch and view bobbing applied.
68 inline scene::ICameraSceneNode* getCameraNode() const
73 // Get the camera position (in absolute scene coordinates).
74 // This has view bobbing applied.
75 inline v3f getPosition() const
77 return m_camera_position;
80 // Get the camera direction (in absolute camera coordinates).
81 // This has view bobbing applied.
82 inline v3f getDirection() const
84 return m_camera_direction;
87 // Get the camera offset
88 inline v3s16 getOffset() const
90 return m_camera_offset;
93 // Horizontal field of view
94 inline f32 getFovX() const
99 // Vertical field of view
100 inline f32 getFovY() const
105 // Get maximum of getFovX() and getFovY()
106 inline f32 getFovMax() const
108 return MYMAX(m_fov_x, m_fov_y);
111 // Checks if the constructor was able to create the scene nodes
112 bool successfullyCreated(std::wstring& error_message);
114 // Step the camera: updates the viewing range and view bobbing.
115 void step(f32 dtime);
117 // Update the camera from the local player's position.
118 // busytime is used to adjust the viewing range.
119 void update(LocalPlayer* player, f32 frametime, f32 busytime,
120 f32 tool_reload_ratio, ClientEnvironment &c_env);
122 // Render distance feedback loop
123 void updateViewingRange(f32 frametime_in, f32 busytime_in);
125 // Start digging animation
126 // Pass 0 for left click, 1 for right click
127 void setDigging(s32 button);
129 // Replace the wielded item mesh
130 void wield(const ItemStack &item, u16 playeritem);
132 // Draw the wielded tool.
133 // This has to happen *after* the main scene is drawn.
134 // Warning: This clears the Z buffer.
135 void drawWieldedTool(irr::core::matrix4* translation=NULL);
137 // Toggle the current camera mode
138 void toggleCameraMode() {
139 if (m_camera_mode == CAMERA_MODE_FIRST)
140 m_camera_mode = CAMERA_MODE_THIRD;
141 else if (m_camera_mode == CAMERA_MODE_THIRD)
142 m_camera_mode = CAMERA_MODE_THIRD_FRONT;
144 m_camera_mode = CAMERA_MODE_FIRST;
147 //read the current camera mode
148 inline CameraMode getCameraMode()
150 return m_camera_mode;
155 scene::ISceneNode* m_playernode;
156 scene::ISceneNode* m_headnode;
157 scene::ICameraSceneNode* m_cameranode;
159 scene::ISceneManager* m_wieldmgr;
160 scene::IMeshSceneNode* m_wieldnode;
164 MapDrawControl& m_draw_control;
168 // Absolute camera position
169 v3f m_camera_position;
170 // Absolute camera direction
171 v3f m_camera_direction;
173 v3s16 m_camera_offset;
175 // Field of view and aspect ratio stuff
180 // Stuff for viewing range calculations
181 f32 m_added_busytime;
185 f32 m_frametime_counter;
186 f32 m_time_per_range;
188 // View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
189 f32 m_view_bobbing_anim;
190 // If 0, view bobbing is off (e.g. player is standing).
191 // If 1, view bobbing is on (player is walking).
192 // If 2, view bobbing is getting switched off.
193 s32 m_view_bobbing_state;
194 // Speed of view bobbing animation
195 f32 m_view_bobbing_speed;
197 f32 m_view_bobbing_fall;
199 // Digging animation frame (0 <= m_digging_anim < 1)
201 // If -1, no digging animation
202 // If 0, left-click digging animation
203 // If 1, right-click digging animation
204 s32 m_digging_button;
206 //dummymesh for camera
207 irr::scene::IAnimatedMesh* m_dummymesh;
209 // Animation when changing wielded item
210 f32 m_wield_change_timer;
211 scene::IMesh *m_wield_mesh_next;
212 u16 m_previous_playeritem;
213 std::string m_previous_itemname;
215 CameraMode m_camera_mode;