3 Copyright (C) 2010-2011 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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 "common_irrlicht.h"
24 #include "inventory.h"
28 #include <ICameraSceneNode.h>
31 struct MapDrawControl;
35 Client camera class, manages the player and camera scene nodes, the viewing distance
36 and performs view bobbing etc. It also displays the wielded tool in front of the
42 Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control);
45 // Get player scene node.
46 // This node is positioned at the player's torso (without any view bobbing),
47 // as given by Player::m_position. Yaw is applied but not pitch.
48 inline scene::ISceneNode* getPlayerNode() const
53 // Get head scene node.
54 // It has the eye transformation and pitch applied,
55 // but no view bobbing.
56 inline scene::ISceneNode* getHeadNode() const
61 // Get camera scene node.
62 // It has the eye transformation, pitch and view bobbing applied.
63 inline scene::ICameraSceneNode* getCameraNode() const
68 // Get the camera position (in absolute scene coordinates).
69 // This has view bobbing applied.
70 inline v3f getPosition() const
72 return m_camera_position;
75 // Get the camera direction (in absolute camera coordinates).
76 // This has view bobbing applied.
77 inline v3f getDirection() const
79 return m_camera_direction;
82 // Horizontal field of view
83 inline f32 getFovX() const
88 // Vertical field of view
89 inline f32 getFovY() const
94 // Get maximum of getFovX() and getFovY()
95 inline f32 getFovMax() const
97 return MYMAX(m_fov_x, m_fov_y);
100 // Checks if the constructor was able to create the scene nodes
101 bool successfullyCreated(std::wstring& error_message);
103 // Step the camera: updates the viewing range and view bobbing.
104 void step(f32 dtime);
106 // Update the camera from the local player's position.
107 // frametime is used to adjust the viewing range.
108 void update(LocalPlayer* player, f32 frametime, v2u32 screensize,
109 f32 tool_reload_ratio);
111 // Render distance feedback loop
112 void updateViewingRange(f32 frametime_in);
114 // Start digging animation
115 // Pass 0 for left click, 1 for right click
116 void setDigging(s32 button);
118 // Replace the wielded item mesh
119 void wield(const ItemStack &item, IGameDef *gamedef);
121 // Draw the wielded tool.
122 // This has to happen *after* the main scene is drawn.
123 // Warning: This clears the Z buffer.
124 void drawWieldedTool();
127 // Scene manager and nodes
128 scene::ISceneManager* m_smgr;
129 scene::ISceneNode* m_playernode;
130 scene::ISceneNode* m_headnode;
131 scene::ICameraSceneNode* m_cameranode;
133 scene::ISceneManager* m_wieldmgr;
134 scene::IMeshSceneNode* m_wieldnode;
138 MapDrawControl& m_draw_control;
140 // Absolute camera position
141 v3f m_camera_position;
142 // Absolute camera direction
143 v3f m_camera_direction;
145 // Field of view and aspect ratio stuff
150 // Stuff for viewing range calculations
151 f32 m_added_frametime;
155 f32 m_frametime_counter;
156 f32 m_time_per_range;
158 // View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
159 f32 m_view_bobbing_anim;
160 // If 0, view bobbing is off (e.g. player is standing).
161 // If 1, view bobbing is on (player is walking).
162 // If 2, view bobbing is getting switched off.
163 s32 m_view_bobbing_state;
164 // Speed of view bobbing animation
165 f32 m_view_bobbing_speed;
167 // Digging animation frame (0 <= m_digging_anim < 1)
169 // If -1, no digging animation
170 // If 0, left-click digging animation
171 // If 1, right-click digging animation
172 s32 m_digging_button;