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"
30 class ExtrudedSpriteSceneNode;
33 Client camera class, manages the player and camera scene nodes, the viewing distance
34 and performs view bobbing etc. It also displays the wielded tool in front of the
40 Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control);
43 // Get player scene node.
44 // This node is positioned at the player's torso (without any view bobbing),
45 // as given by Player::m_position. Yaw is applied but not pitch.
46 inline scene::ISceneNode* getPlayerNode() const
51 // Get head scene node.
52 // It has the eye transformation and pitch applied,
53 // but no view bobbing.
54 inline scene::ISceneNode* getHeadNode() const
59 // Get camera scene node.
60 // It has the eye transformation, pitch and view bobbing applied.
61 inline scene::ICameraSceneNode* getCameraNode() const
66 // Get the camera position (in absolute scene coordinates).
67 // This has view bobbing applied.
68 inline v3f getPosition() const
70 return m_camera_position;
73 // Get the camera direction (in absolute camera coordinates).
74 // This has view bobbing applied.
75 inline v3f getDirection() const
77 return m_camera_direction;
80 // Horizontal field of view
81 inline f32 getFovX() const
86 // Vertical field of view
87 inline f32 getFovY() const
92 // Get maximum of getFovX() and getFovY()
93 inline f32 getFovMax() const
95 return MYMAX(m_fov_x, m_fov_y);
98 // Checks if the constructor was able to create the scene nodes
99 bool successfullyCreated(std::wstring& error_message);
101 // Step the camera: updates the viewing range and view bobbing.
102 void step(f32 dtime);
104 // Update the camera from the local player's position.
105 // frametime is used to adjust the viewing range.
106 void update(LocalPlayer* player, f32 frametime, v2u32 screensize);
108 // Render distance feedback loop
109 void updateViewingRange(f32 frametime_in);
111 // Update settings from g_settings
112 void updateSettings();
114 // Replace the wielded item mesh
115 void wield(const InventoryItem* item);
117 // Start digging animation
118 // Pass 0 for left click, 1 for right click
119 void setDigging(s32 button);
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 ExtrudedSpriteSceneNode* m_wieldnode;
137 MapDrawControl& m_draw_control;
139 // viewing_range_min_nodes setting
140 f32 m_viewing_range_min;
141 // viewing_range_max_nodes setting
142 f32 m_viewing_range_max;
144 // Absolute camera position
145 v3f m_camera_position;
146 // Absolute camera direction
147 v3f m_camera_direction;
149 // Field of view and aspect ratio stuff
154 // Stuff for viewing range calculations
155 f32 m_wanted_frametime;
156 f32 m_added_frametime;
160 f32 m_frametime_counter;
161 f32 m_time_per_range;
163 // View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
164 f32 m_view_bobbing_anim;
165 // If 0, view bobbing is off (e.g. player is standing).
166 // If 1, view bobbing is on (player is walking).
167 // If 2, view bobbing is getting switched off.
168 s32 m_view_bobbing_state;
169 // Speed of view bobbing animation
170 f32 m_view_bobbing_speed;
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;
182 A scene node that displays a 2D mesh extruded into the third dimension,
183 to add an illusion of depth.
185 Since this class was created to display the wielded tool of the local
186 player, and only tools and items are rendered like this (but not solid
187 content like stone and mud, which are shown as cubes), the option to
188 draw a textured cube instead is provided.
190 class ExtrudedSpriteSceneNode: public scene::ISceneNode
193 ExtrudedSpriteSceneNode(
194 scene::ISceneNode* parent,
195 scene::ISceneManager* mgr,
197 const v3f& position = v3f(0,0,0),
198 const v3f& rotation = v3f(0,0,0),
199 const v3f& scale = v3f(1,1,1));
200 ~ExtrudedSpriteSceneNode();
202 void setSprite(video::ITexture* texture);
203 void setCube(const TileSpec tiles[6]);
205 f32 getSpriteThickness() const { return m_thickness; }
206 void setSpriteThickness(f32 thickness);
208 void updateLight(u8 light);
210 void removeSpriteFromCache(video::ITexture* texture);
212 virtual const core::aabbox3d<f32>& getBoundingBox() const;
213 virtual void OnRegisterSceneNode();
214 virtual void render();
217 scene::IMeshSceneNode* m_meshnode;
219 scene::IMesh* m_cubemesh;
223 // internal extrusion helper methods
224 io::path getExtrudedName(video::ITexture* texture);
225 scene::IAnimatedMesh* extrudeARGB(u32 width, u32 height, u8* data);
226 scene::IAnimatedMesh* extrude(video::ITexture* texture);
227 scene::IMesh* createCubeMesh();