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"
30 Client camera class, manages the player and camera scene nodes, the viewing distance
31 and performs view bobbing etc.
36 Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control);
39 // Get player scene node.
40 // This node is positioned at the player's torso (without any view bobbing),
41 // as given by Player::m_position. Yaw is applied but not pitch.
42 // Things like wielded tools should be positioned relative to this node.
43 inline scene::ISceneNode* getPlayerNode() const
48 // Get camera scene node.
49 // It has the eye transformation and view bobbing applied.
50 inline scene::ICameraSceneNode* getCameraNode() const
55 // Get the camera position (in absolute scene coordinates).
56 // This has view bobbing applied.
57 inline v3f getPosition() const
59 return m_camera_position;
62 // Get the camera direction (in absolute camera coordinates).
63 // This has view bobbing applied.
64 inline v3f getDirection() const
66 return m_camera_direction;
69 // Horizontal field of view
70 inline f32 getFovX() const
75 // Vertical field of view
76 inline f32 getFovY() const
81 // Get maximum of getFovX() and getFovY()
82 inline f32 getFovMax() const
84 return MYMAX(m_fov_x, m_fov_y);
87 // Step the camera: updates the viewing range and view bobbing.
90 // Update the camera from the local player's position.
91 // frametime is used to adjust the viewing range.
92 void update(LocalPlayer* player, f32 frametime, v2u32 screensize);
94 // Render distance feedback loop
95 void updateViewingRange(f32 frametime_in);
97 // Update settings from g_settings
98 void updateSettings();
101 // Scene manager and nodes
102 scene::ISceneManager* m_smgr;
103 scene::ISceneNode* m_playernode;
104 scene::ICameraSceneNode* m_cameranode;
107 MapDrawControl& m_draw_control;
109 // viewing_range_min_nodes setting
110 f32 m_viewing_range_min;
111 // viewing_range_max_nodes setting
112 f32 m_viewing_range_max;
114 // Absolute camera position
115 v3f m_camera_position;
116 // Absolute camera direction
117 v3f m_camera_direction;
119 // Field of view and aspect ratio stuff
124 // Stuff for viewing range calculations
125 f32 m_wanted_frametime;
126 f32 m_added_frametime;
130 f32 m_frametime_counter;
131 f32 m_time_per_range;
133 // View bobbing animation frame (0 <= m_view_bobbing < 0x1000000)
134 s32 m_view_bobbing_anim;
135 // If 0, view bobbing is off (e.g. player is standing).
136 // If 1, view bobbing is on (player is walking).
137 // If 2, view bobbing is getting switched off.
138 s32 m_view_bobbing_state;
139 // If true, view bobbing is slown down (player is swimming)
140 bool m_view_bobbing_slow;