1 // 2 // SuperTuxKart - a fun racing game with go-kart 3 // Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net> 4 // Copyright (C) 2006-2015 SuperTuxKart-Team, Steve Baker 5 // 6 // This program is free software; you can redistribute it and/or 7 // modify it under the terms of the GNU General Public License 8 // as published by the Free Software Foundation; either version 3 9 // of the License, or (at your option) any later version. 10 // 11 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 // You should have received a copy of the GNU General Public License 18 // along with this program; if not, write to the Free Software 19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 21 #ifndef HEADER_CAMERA_FPS_HPP 22 #define HEADER_CAMERA_FPS_HPP 23 24 #include "graphics/camera.hpp" 25 26 #include "utils/cpp2011.hpp" 27 28 class AbstractKart; 29 30 /** 31 * \brief Handles the game camera 32 * \ingroup graphics 33 */ 34 class CameraFPS : public Camera 35 { 36 private: 37 /** The speed at which the camera changes position. */ 38 float m_position_speed; 39 40 /** The speed at which the camera target changes position. */ 41 float m_target_speed; 42 43 /** Factor of the effects of steering in camera aim. */ 44 float m_rotation_range; 45 46 /** Smooth acceleration with the first person camera. */ 47 bool m_smooth; 48 49 /** Attache the first person camera to a kart. 50 That means moving the kart also moves the camera. */ 51 bool m_attached; 52 53 /** The speed at which the up-vector rotates, only used for the first person camera. */ 54 float m_angular_velocity; 55 56 /** Target angular velocity. Used for smooth movement in fps perpective. */ 57 float m_target_angular_velocity; 58 59 /** Maximum velocity for fps camera. */ 60 float m_max_velocity; 61 62 /** Linear velocity of the camera, used for end and first person camera. 63 It's stored relative to the camera direction for the first person view. */ 64 core::vector3df m_lin_velocity; 65 66 /** Velocity of the target of the camera, used for end and first person camera. */ 67 core::vector3df m_target_velocity; 68 69 /** The target direction for the camera, only used for the first person camera. */ 70 core::vector3df m_target_direction; 71 72 /** The speed at which the direction changes, only used for the first person camera. */ 73 core::vector3df m_direction_velocity; 74 75 /** The up vector the camera should have, only used for the first person camera. */ 76 core::vector3df m_target_up_vector; 77 78 /** Save the local position if the first person camera is attached to the kart. */ 79 core::vector3df m_local_position; 80 81 /** Save the local direction if the first person camera is attached to the kart. */ 82 core::vector3df m_local_direction; 83 84 /** Save the local up vector if the first person camera is attached to the kart. */ 85 core::vector3df m_local_up; 86 87 88 89 void positionCamera(float dt, float above_kart, float cam_angle, 90 float side_way, float distance, float smoothing); 91 92 friend class Camera; 93 CameraFPS(int camera_index, AbstractKart* kart); 94 virtual ~CameraFPS(); 95 public: 96 // ------------------------------------------------------------------------ isFPS()97 static bool isFPS() { return true; } 98 // ------------------------------------------------------------------------ 99 100 virtual void update(float dt) OVERRIDE; 101 // ------------------------------------------------------------------------ 102 /** Applies mouse movement to the first person camera. */ 103 void applyMouseMovement (float x, float y); 104 105 // ------------------------------------------------------------------------ 106 /** Sets if the first person camera should be moved smooth. */ setSmoothMovement(bool value)107 void setSmoothMovement (bool value) { m_smooth = value; } 108 109 // ------------------------------------------------------------------------ 110 /** If the first person camera should be moved smooth. */ getSmoothMovement()111 bool getSmoothMovement () { return m_smooth; } 112 113 // ------------------------------------------------------------------------ 114 /** Sets if the first person camera should be moved with the kart. */ setAttachedFpsCam(bool value)115 void setAttachedFpsCam (bool value) { m_attached = value; } 116 117 // ------------------------------------------------------------------------ 118 /** If the first person camera should be moved with the kart. */ getAttachedFpsCam()119 bool getAttachedFpsCam () { return m_attached; } 120 121 // ------------------------------------------------------------------------ 122 /** Sets the angular velocity for this camera. */ setMaximumVelocity(float vel)123 void setMaximumVelocity (float vel) { m_max_velocity = vel; } 124 125 // ------------------------------------------------------------------------ 126 /** Returns the current angular velocity. */ getMaximumVelocity()127 float getMaximumVelocity () { return m_max_velocity; } 128 129 // ------------------------------------------------------------------------ 130 /** Sets the vector, the first person camera should look at. */ setDirection(core::vector3df target)131 void setDirection (core::vector3df target) { m_target_direction = target; } 132 133 // ------------------------------------------------------------------------ 134 /** Gets the vector, the first person camera should look at. */ getDirection()135 const core::vector3df &getDirection () { return m_target_direction; } 136 137 // ------------------------------------------------------------------------ 138 /** Sets the up vector, the first person camera should use. */ setUpVector(core::vector3df target)139 void setUpVector (core::vector3df target) { m_target_up_vector = target; } 140 141 // ------------------------------------------------------------------------ 142 /** Gets the up vector, the first person camera should use. */ getUpVector()143 const core::vector3df &getUpVector () { return m_target_up_vector; } 144 145 // ------------------------------------------------------------------------ 146 /** Sets the angular velocity for this camera. */ 147 void setAngularVelocity (float vel); 148 149 // ------------------------------------------------------------------------ 150 /** Returns the current target angular velocity. */ 151 float getAngularVelocity (); 152 153 // ------------------------------------------------------------------------ 154 /** Sets the linear velocity for this camera. */ 155 void setLinearVelocity (core::vector3df vel); 156 157 // ------------------------------------------------------------------------ 158 /** Returns the current linear velocity. */ 159 const core::vector3df &getLinearVelocity (); 160 161 }; // class CameraFPS 162 163 #endif 164 165 /* EOF */ 166