| 1 | /* |
|---|
| 2 | ================================================================================= |
|---|
| 3 | This file is part of Cafu, the open-source game engine and graphics engine |
|---|
| 4 | for multiplayer, cross-platform, real-time 3D action. |
|---|
| 5 | Copyright (C) 2002-2012 Carsten Fuchs Software. |
|---|
| 6 | |
|---|
| 7 | Cafu is free software: you can redistribute it and/or modify it under the terms |
|---|
| 8 | of the GNU General Public License as published by the Free Software Foundation, |
|---|
| 9 | either version 3 of the License, or (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 12 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|---|
| 13 | PURPOSE. See the GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with Cafu. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | For support and more information about Cafu, visit us at <http://www.cafu.de>. |
|---|
| 19 | ================================================================================= |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #ifndef CAFU_CAMERA_HPP_INCLUDED |
|---|
| 23 | #define CAFU_CAMERA_HPP_INCLUDED |
|---|
| 24 | |
|---|
| 25 | #include "Math3D/Angles.hpp" |
|---|
| 26 | #include "Math3D/Matrix.hpp" |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | /// This class implements a camera. Cameras are associated with the 3D views and controlled with the Camera tool. |
|---|
| 30 | /// A camera is represented by an orthogonal, right-handed coordinate system, |
|---|
| 31 | /// where the x-axis points right, the y-axis points forward (the viewing direction) and the z-axis points up. |
|---|
| 32 | class CameraT |
|---|
| 33 | { |
|---|
| 34 | public: |
|---|
| 35 | |
|---|
| 36 | CameraT(); |
|---|
| 37 | |
|---|
| 38 | Vector3fT GetXAxis() const; ///< Returns the x-axis (pointing right) of the camera space. |
|---|
| 39 | Vector3fT GetYAxis() const; ///< Returns the y-axis (pointing forward) of the camera space. This is the direction the camera is looking into! |
|---|
| 40 | Vector3fT GetZAxis() const; ///< Returns the z-axis (pointing up) of the camera space. |
|---|
| 41 | const MatrixT& GetMatrix() const; ///< Returns the matrix that represents the position and orientation of this camera. |
|---|
| 42 | |
|---|
| 43 | void SetLookAtPos(const Vector3fT& LookAtPos); ///< This method automatically computes the orientation of the camera so that it looks at the given point. |
|---|
| 44 | void LimitAngles(); ///< This method wraps the yaw into the [0°, 360°[ intervall and clamps the pitch to -90° and +90°. Call this method after each manipulation of the angles! |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | // Regular members that define the essential properties of the camera. |
|---|
| 48 | Vector3fT Pos; ///< The cameras position in the world. |
|---|
| 49 | cf::math::AnglesfT Angles; ///< The angles that describe the cameras orientation. The pitch value is limited/clamped to the interval from -90° to +90°, and roll is not used at all. |
|---|
| 50 | float ViewDirLength; ///< This member defines how long the view direction vector (GetYAxis()) is drawn in the 2D views. |
|---|
| 51 | |
|---|
| 52 | // Additional members that augment the definition of the cameras view pyramid (frustum). |
|---|
| 53 | float VerticalFOV; ///< The cameras field-of-view angle, in vertical (up/down) direction. |
|---|
| 54 | float NearPlaneDist; ///< The distance of the near clip plane to the tip of the view pyramid. |
|---|
| 55 | float FarPlaneDist; ///< The distance of the far clip plane to the tip of the view pyramid. |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | private: |
|---|
| 59 | |
|---|
| 60 | mutable Vector3fT m_MatrixPos; ///< The position with which the m_Matrix was built. |
|---|
| 61 | mutable cf::math::AnglesfT m_MatrixAngles; ///< The angles with which the m_Matrix was built. |
|---|
| 62 | mutable MatrixT m_Matrix; ///< The matrix that transforms from world to camera space. |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | #endif |
|---|