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>
29 #include <IMeshCache.h>
30 #include <IAnimatedMesh.h>
33 struct MapDrawControl;
34 class ExtrudedSpriteSceneNode;
38 Client camera class, manages the player and camera scene nodes, the viewing distance
39 and performs view bobbing etc. It also displays the wielded tool in front of the
45 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 // Horizontal field of view
86 inline f32 getFovX() const
91 // Vertical field of view
92 inline f32 getFovY() const
97 // Get maximum of getFovX() and getFovY()
98 inline f32 getFovMax() const
100 return MYMAX(m_fov_x, m_fov_y);
103 // Checks if the constructor was able to create the scene nodes
104 bool successfullyCreated(std::wstring& error_message);
106 // Step the camera: updates the viewing range and view bobbing.
107 void step(f32 dtime);
109 // Update the camera from the local player's position.
110 // frametime is used to adjust the viewing range.
111 void update(LocalPlayer* player, f32 frametime, v2u32 screensize);
113 // Render distance feedback loop
114 void updateViewingRange(f32 frametime_in);
116 // Update settings from g_settings
117 void updateSettings();
119 // Replace the wielded item mesh
120 void wield(const InventoryItem* item, IGameDef *gamedef);
122 // Start digging animation
123 // Pass 0 for left click, 1 for right click
124 void setDigging(s32 button);
126 // Draw the wielded tool.
127 // This has to happen *after* the main scene is drawn.
128 // Warning: This clears the Z buffer.
129 void drawWieldedTool();
132 // Scene manager and nodes
133 scene::ISceneManager* m_smgr;
134 scene::ISceneNode* m_playernode;
135 scene::ISceneNode* m_headnode;
136 scene::ICameraSceneNode* m_cameranode;
138 scene::ISceneManager* m_wieldmgr;
139 ExtrudedSpriteSceneNode* m_wieldnode;
142 MapDrawControl& m_draw_control;
144 // viewing_range_min_nodes setting
145 f32 m_viewing_range_min;
146 // viewing_range_max_nodes setting
147 f32 m_viewing_range_max;
149 // Absolute camera position
150 v3f m_camera_position;
151 // Absolute camera direction
152 v3f m_camera_direction;
154 // Field of view and aspect ratio stuff
159 // Stuff for viewing range calculations
160 f32 m_wanted_frametime;
161 f32 m_added_frametime;
165 f32 m_frametime_counter;
166 f32 m_time_per_range;
168 // View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
169 f32 m_view_bobbing_anim;
170 // If 0, view bobbing is off (e.g. player is standing).
171 // If 1, view bobbing is on (player is walking).
172 // If 2, view bobbing is getting switched off.
173 s32 m_view_bobbing_state;
174 // Speed of view bobbing animation
175 f32 m_view_bobbing_speed;
177 // Digging animation frame (0 <= m_digging_anim < 1)
179 // If -1, no digging animation
180 // If 0, left-click digging animation
181 // If 1, right-click digging animation
182 s32 m_digging_button;
187 A scene node that displays a 2D mesh extruded into the third dimension,
188 to add an illusion of depth.
190 Since this class was created to display the wielded tool of the local
191 player, and only tools and items are rendered like this (but not solid
192 content like stone and mud, which are shown as cubes), the option to
193 draw a textured cube instead is provided.
195 class ExtrudedSpriteSceneNode: public scene::ISceneNode
198 ExtrudedSpriteSceneNode(
199 scene::ISceneNode* parent,
200 scene::ISceneManager* mgr,
202 const v3f& position = v3f(0,0,0),
203 const v3f& rotation = v3f(0,0,0),
204 const v3f& scale = v3f(1,1,1));
205 ~ExtrudedSpriteSceneNode();
207 void setSprite(video::ITexture* texture);
208 void setCube(const TileSpec tiles[6]);
210 void updateLight(u8 light);
212 void removeSpriteFromCache(video::ITexture* texture);
214 virtual const core::aabbox3d<f32>& getBoundingBox() const;
215 virtual void OnRegisterSceneNode();
216 virtual void render();
219 scene::IMeshSceneNode* m_meshnode;
220 scene::IMesh* m_cubemesh;
224 io::path getExtrudedName(video::ITexture* texture);