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>
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,
46 // Get player scene node.
47 // This node is positioned at the player's torso (without any view bobbing),
48 // as given by Player::m_position. Yaw is applied but not pitch.
49 inline scene::ISceneNode* getPlayerNode() const
54 // Get head scene node.
55 // It has the eye transformation and pitch applied,
56 // but no view bobbing.
57 inline scene::ISceneNode* getHeadNode() const
62 // Get camera scene node.
63 // It has the eye transformation, pitch and view bobbing applied.
64 inline scene::ICameraSceneNode* getCameraNode() const
69 // Get the camera position (in absolute scene coordinates).
70 // This has view bobbing applied.
71 inline v3f getPosition() const
73 return m_camera_position;
76 // Get the camera direction (in absolute camera coordinates).
77 // This has view bobbing applied.
78 inline v3f getDirection() const
80 return m_camera_direction;
83 // Horizontal field of view
84 inline f32 getFovX() const
89 // Vertical field of view
90 inline f32 getFovY() const
95 // Get maximum of getFovX() and getFovY()
96 inline f32 getFovMax() const
98 return MYMAX(m_fov_x, m_fov_y);
101 // Checks if the constructor was able to create the scene nodes
102 bool successfullyCreated(std::wstring& error_message);
104 // Step the camera: updates the viewing range and view bobbing.
105 void step(f32 dtime);
107 // Update the camera from the local player's position.
108 // frametime is used to adjust the viewing range.
109 void update(LocalPlayer* player, f32 frametime, v2u32 screensize,
110 f32 tool_reload_ratio);
112 // Render distance feedback loop
113 void updateViewingRange(f32 frametime_in);
115 // Start digging animation
116 // Pass 0 for left click, 1 for right click
117 void setDigging(s32 button);
119 // Replace the wielded item mesh
120 void wield(const ItemStack &item);
122 // Draw the wielded tool.
123 // This has to happen *after* the main scene is drawn.
124 // Warning: This clears the Z buffer.
125 void drawWieldedTool();
128 // Scene manager and nodes
129 scene::ISceneManager* m_smgr;
130 scene::ISceneNode* m_playernode;
131 scene::ISceneNode* m_headnode;
132 scene::ICameraSceneNode* m_cameranode;
134 scene::ISceneManager* m_wieldmgr;
135 scene::IMeshSceneNode* m_wieldnode;
139 MapDrawControl& m_draw_control;
143 // Absolute camera position
144 v3f m_camera_position;
145 // Absolute camera direction
146 v3f m_camera_direction;
148 // Field of view and aspect ratio stuff
153 // Stuff for viewing range calculations
154 f32 m_added_frametime;
158 f32 m_frametime_counter;
159 f32 m_time_per_range;
161 // View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
162 f32 m_view_bobbing_anim;
163 // If 0, view bobbing is off (e.g. player is standing).
164 // If 1, view bobbing is on (player is walking).
165 // If 2, view bobbing is getting switched off.
166 s32 m_view_bobbing_state;
167 // Speed of view bobbing animation
168 f32 m_view_bobbing_speed;
170 f32 m_view_bobbing_fall;
172 // Digging animation frame (0 <= m_digging_anim < 1)
174 // If -1, no digging animation
175 // If 0, left-click digging animation
176 // If 1, right-click digging animation
177 s32 m_digging_button;
179 //dummymesh for camera
180 irr::scene::IAnimatedMesh* m_dummymesh;