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, Player::m_pitch and Player::m_yaw.
42 // Things like wielded tools should be positioned relative to this node.
43 inline scene::ISceneNode* getPlayerNode() const
48 // Get camera scene node.
49 // The camera node is a child of the player node.
50 // It has the eye transformation and view bobbing applied.
51 inline scene::ICameraSceneNode* getCameraNode() const
56 // Get the camera position (in absolute scene coordinates).
57 // This has view bobbing applied.
58 inline v3f getPosition() const
60 return m_camera_position;
63 // Get the camera direction (in absolute camera coordinates).
64 // This has view bobbing applied.
65 inline v3f getDirection() const
67 return m_camera_direction;
70 // Horizontal field of view
71 inline f32 getFovX() const
76 // Vertical field of view
77 inline f32 getFovY() const
82 // Get maximum of getFovX() and getFovY()
83 inline f32 getFovMax() const
85 return MYMAX(m_fov_x, m_fov_y);
88 // Step the camera: updates the viewing range and view bobbing.
91 // Update the camera from the local player's position.
92 // frametime is used to adjust the viewing range.
93 void update(LocalPlayer* player, f32 frametime, v2u32 screensize);
95 // Render distance feedback loop
96 void updateViewingRange(f32 frametime_in);
98 // Update settings from g_settings
99 void updateSettings();
102 // Scene manager and nodes
103 scene::ISceneManager* m_smgr;
104 scene::ISceneNode* m_playernode;
105 scene::ICameraSceneNode* m_cameranode;
108 MapDrawControl& m_draw_control;
110 // viewing_range_min_nodes setting
111 f32 m_viewing_range_min;
112 // viewing_range_max_nodes setting
113 f32 m_viewing_range_max;
115 // Absolute camera position
116 v3f m_camera_position;
117 // Absolute camera direction
118 v3f m_camera_direction;
120 // Field of view and aspect ratio stuff
125 // Stuff for viewing range calculations
126 f32 m_wanted_frametime;
127 f32 m_added_frametime;
131 f32 m_frametime_counter;
132 f32 m_time_per_range;
134 // View bobbing animation frame (0 <= m_view_bobbing < 0x10000)
135 u32 m_view_bobbing_anim;
136 // Number of frames to continue the view bobbing animation.
137 u32 m_view_bobbing_anim_left;