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"
29 class ExtrudedSpriteSceneNode;
32 Client camera class, manages the player and camera scene nodes, the viewing distance
33 and performs view bobbing etc. It also displays the wielded tool in front of the
39 Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control);
42 // Get player scene node.
43 // This node is positioned at the player's torso (without any view bobbing),
44 // as given by Player::m_position. Yaw is applied but not pitch.
45 inline scene::ISceneNode* getPlayerNode() const
50 // Get head scene node.
51 // It has the eye transformation and pitch applied,
52 // but no view bobbing.
53 inline scene::ISceneNode* getHeadNode() const
58 // Get camera scene node.
59 // It has the eye transformation, pitch and view bobbing applied.
60 inline scene::ICameraSceneNode* getCameraNode() const
65 // Get wielded item scene node.
66 inline ExtrudedSpriteSceneNode* getWieldNode() 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(InventoryItem* item);
122 // Start or stop digging animation
123 void setDigging(bool digging);
126 // Scene manager and nodes
127 scene::ISceneManager* m_smgr;
128 scene::ISceneNode* m_playernode;
129 scene::ISceneNode* m_headnode;
130 scene::ICameraSceneNode* m_cameranode;
131 ExtrudedSpriteSceneNode* m_wieldnode;
134 MapDrawControl& m_draw_control;
136 // viewing_range_min_nodes setting
137 f32 m_viewing_range_min;
138 // viewing_range_max_nodes setting
139 f32 m_viewing_range_max;
141 // Absolute camera position
142 v3f m_camera_position;
143 // Absolute camera direction
144 v3f m_camera_direction;
146 // Field of view and aspect ratio stuff
151 // Stuff for viewing range calculations
152 f32 m_wanted_frametime;
153 f32 m_added_frametime;
157 f32 m_frametime_counter;
158 f32 m_time_per_range;
160 // View bobbing animation frame (0 <= m_view_bobbing < 0x1000000)
161 s32 m_view_bobbing_anim;
162 // If 0, view bobbing is off (e.g. player is standing).
163 // If 1, view bobbing is on (player is walking).
164 // If 2, view bobbing is getting switched off.
165 s32 m_view_bobbing_state;
166 // Speed of view bobbing animation
167 f32 m_view_bobbing_speed;
172 A scene node that displays a 2D mesh extruded into the third dimension,
173 to add an illusion of depth.
175 Since this class was created to display the wielded tool of the local
176 player, and only tools and items are rendered like this (but not solid
177 content like stone and mud, which are shown as cubes), the option to
178 draw a textured cube instead is provided.
180 class ExtrudedSpriteSceneNode: public scene::ISceneNode
183 ExtrudedSpriteSceneNode(
184 scene::ISceneNode* parent,
185 scene::ISceneManager* mgr,
187 const v3f& position = v3f(0,0,0),
188 const v3f& rotation = v3f(0,0,0),
189 const v3f& scale = v3f(0,0,0));
190 ~ExtrudedSpriteSceneNode();
192 void setSprite(video::ITexture* texture);
193 void setCube(const TileSpec faces[6]);
195 f32 getSpriteThickness() const { return m_thickness; }
196 void setSpriteThickness(f32 thickness);
198 void removeSpriteFromCache(video::ITexture* texture);
200 virtual const core::aabbox3d<f32>& getBoundingBox() const;
201 virtual void OnRegisterSceneNode();
202 virtual void render();
205 scene::IMeshSceneNode* m_meshnode;
207 scene::IMesh* m_cubemesh;
210 // internal extrusion helper methods
211 io::path getExtrudedName(video::ITexture* texture);
212 scene::IAnimatedMesh* extrudeARGB(u32 width, u32 height, u8* data);
213 scene::IAnimatedMesh* extrude(video::ITexture* texture);
214 scene::IMesh* createCubeMesh();