Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:58:14

0001 ////////////////////////////////////////////////////////////
0002 //
0003 // SFML - Simple and Fast Multimedia Library
0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
0005 //
0006 // This software is provided 'as-is', without any express or implied warranty.
0007 // In no event will the authors be held liable for any damages arising from the use of this software.
0008 //
0009 // Permission is granted to anyone to use this software for any purpose,
0010 // including commercial applications, and to alter it and redistribute it freely,
0011 // subject to the following restrictions:
0012 //
0013 // 1. The origin of this software must not be misrepresented;
0014 //    you must not claim that you wrote the original software.
0015 //    If you use this software in a product, an acknowledgment
0016 //    in the product documentation would be appreciated but is not required.
0017 //
0018 // 2. Altered source versions must be plainly marked as such,
0019 //    and must not be misrepresented as being the original software.
0020 //
0021 // 3. This notice may not be removed or altered from any source distribution.
0022 //
0023 ////////////////////////////////////////////////////////////
0024 
0025 #ifndef SFML_VECTOR3_HPP
0026 #define SFML_VECTOR3_HPP
0027 
0028 
0029 namespace sf
0030 {
0031 ////////////////////////////////////////////////////////////
0032 /// \brief Utility template class for manipulating
0033 ///        3-dimensional vectors
0034 ///
0035 ////////////////////////////////////////////////////////////
0036 template <typename T>
0037 class Vector3
0038 {
0039 public:
0040 
0041     ////////////////////////////////////////////////////////////
0042     /// \brief Default constructor
0043     ///
0044     /// Creates a Vector3(0, 0, 0).
0045     ///
0046     ////////////////////////////////////////////////////////////
0047     Vector3();
0048 
0049     ////////////////////////////////////////////////////////////
0050     /// \brief Construct the vector from its coordinates
0051     ///
0052     /// \param X X coordinate
0053     /// \param Y Y coordinate
0054     /// \param Z Z coordinate
0055     ///
0056     ////////////////////////////////////////////////////////////
0057     Vector3(T X, T Y, T Z);
0058 
0059     ////////////////////////////////////////////////////////////
0060     /// \brief Construct the vector from another type of vector
0061     ///
0062     /// This constructor doesn't replace the copy constructor,
0063     /// it's called only when U != T.
0064     /// A call to this constructor will fail to compile if U
0065     /// is not convertible to T.
0066     ///
0067     /// \param vector Vector to convert
0068     ///
0069     ////////////////////////////////////////////////////////////
0070     template <typename U>
0071     explicit Vector3(const Vector3<U>& vector);
0072 
0073     ////////////////////////////////////////////////////////////
0074     // Member data
0075     ////////////////////////////////////////////////////////////
0076     T x; //!< X coordinate of the vector
0077     T y; //!< Y coordinate of the vector
0078     T z; //!< Z coordinate of the vector
0079 };
0080 
0081 ////////////////////////////////////////////////////////////
0082 /// \relates Vector3
0083 /// \brief Overload of unary operator -
0084 ///
0085 /// \param left Vector to negate
0086 ///
0087 /// \return Memberwise opposite of the vector
0088 ///
0089 ////////////////////////////////////////////////////////////
0090 template <typename T>
0091 Vector3<T> operator -(const Vector3<T>& left);
0092 
0093 ////////////////////////////////////////////////////////////
0094 /// \relates Vector3
0095 /// \brief Overload of binary operator +=
0096 ///
0097 /// This operator performs a memberwise addition of both vectors,
0098 /// and assigns the result to \a left.
0099 ///
0100 /// \param left  Left operand (a vector)
0101 /// \param right Right operand (a vector)
0102 ///
0103 /// \return Reference to \a left
0104 ///
0105 ////////////////////////////////////////////////////////////
0106 template <typename T>
0107 Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right);
0108 
0109 ////////////////////////////////////////////////////////////
0110 /// \relates Vector3
0111 /// \brief Overload of binary operator -=
0112 ///
0113 /// This operator performs a memberwise subtraction of both vectors,
0114 /// and assigns the result to \a left.
0115 ///
0116 /// \param left  Left operand (a vector)
0117 /// \param right Right operand (a vector)
0118 ///
0119 /// \return Reference to \a left
0120 ///
0121 ////////////////////////////////////////////////////////////
0122 template <typename T>
0123 Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right);
0124 
0125 ////////////////////////////////////////////////////////////
0126 /// \relates Vector3
0127 /// \brief Overload of binary operator +
0128 ///
0129 /// \param left  Left operand (a vector)
0130 /// \param right Right operand (a vector)
0131 ///
0132 /// \return Memberwise addition of both vectors
0133 ///
0134 ////////////////////////////////////////////////////////////
0135 template <typename T>
0136 Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right);
0137 
0138 ////////////////////////////////////////////////////////////
0139 /// \relates Vector3
0140 /// \brief Overload of binary operator -
0141 ///
0142 /// \param left  Left operand (a vector)
0143 /// \param right Right operand (a vector)
0144 ///
0145 /// \return Memberwise subtraction of both vectors
0146 ///
0147 ////////////////////////////////////////////////////////////
0148 template <typename T>
0149 Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right);
0150 
0151 ////////////////////////////////////////////////////////////
0152 /// \relates Vector3
0153 /// \brief Overload of binary operator *
0154 ///
0155 /// \param left  Left operand (a vector)
0156 /// \param right Right operand (a scalar value)
0157 ///
0158 /// \return Memberwise multiplication by \a right
0159 ///
0160 ////////////////////////////////////////////////////////////
0161 template <typename T>
0162 Vector3<T> operator *(const Vector3<T>& left, T right);
0163 
0164 ////////////////////////////////////////////////////////////
0165 /// \relates Vector3
0166 /// \brief Overload of binary operator *
0167 ///
0168 /// \param left  Left operand (a scalar value)
0169 /// \param right Right operand (a vector)
0170 ///
0171 /// \return Memberwise multiplication by \a left
0172 ///
0173 ////////////////////////////////////////////////////////////
0174 template <typename T>
0175 Vector3<T> operator *(T left, const Vector3<T>& right);
0176 
0177 ////////////////////////////////////////////////////////////
0178 /// \relates Vector3
0179 /// \brief Overload of binary operator *=
0180 ///
0181 /// This operator performs a memberwise multiplication by \a right,
0182 /// and assigns the result to \a left.
0183 ///
0184 /// \param left  Left operand (a vector)
0185 /// \param right Right operand (a scalar value)
0186 ///
0187 /// \return Reference to \a left
0188 ///
0189 ////////////////////////////////////////////////////////////
0190 template <typename T>
0191 Vector3<T>& operator *=(Vector3<T>& left, T right);
0192 
0193 ////////////////////////////////////////////////////////////
0194 /// \relates Vector3
0195 /// \brief Overload of binary operator /
0196 ///
0197 /// \param left  Left operand (a vector)
0198 /// \param right Right operand (a scalar value)
0199 ///
0200 /// \return Memberwise division by \a right
0201 ///
0202 ////////////////////////////////////////////////////////////
0203 template <typename T>
0204 Vector3<T> operator /(const Vector3<T>& left, T right);
0205 
0206 ////////////////////////////////////////////////////////////
0207 /// \relates Vector3
0208 /// \brief Overload of binary operator /=
0209 ///
0210 /// This operator performs a memberwise division by \a right,
0211 /// and assigns the result to \a left.
0212 ///
0213 /// \param left  Left operand (a vector)
0214 /// \param right Right operand (a scalar value)
0215 ///
0216 /// \return Reference to \a left
0217 ///
0218 ////////////////////////////////////////////////////////////
0219 template <typename T>
0220 Vector3<T>& operator /=(Vector3<T>& left, T right);
0221 
0222 ////////////////////////////////////////////////////////////
0223 /// \relates Vector3
0224 /// \brief Overload of binary operator ==
0225 ///
0226 /// This operator compares strict equality between two vectors.
0227 ///
0228 /// \param left  Left operand (a vector)
0229 /// \param right Right operand (a vector)
0230 ///
0231 /// \return True if \a left is equal to \a right
0232 ///
0233 ////////////////////////////////////////////////////////////
0234 template <typename T>
0235 bool operator ==(const Vector3<T>& left, const Vector3<T>& right);
0236 
0237 ////////////////////////////////////////////////////////////
0238 /// \relates Vector3
0239 /// \brief Overload of binary operator !=
0240 ///
0241 /// This operator compares strict difference between two vectors.
0242 ///
0243 /// \param left  Left operand (a vector)
0244 /// \param right Right operand (a vector)
0245 ///
0246 /// \return True if \a left is not equal to \a right
0247 ///
0248 ////////////////////////////////////////////////////////////
0249 template <typename T>
0250 bool operator !=(const Vector3<T>& left, const Vector3<T>& right);
0251 
0252 #include <SFML/System/Vector3.inl>
0253 
0254 // Define the most common types
0255 typedef Vector3<int>   Vector3i;
0256 typedef Vector3<float> Vector3f;
0257 
0258 } // namespace sf
0259 
0260 
0261 #endif // SFML_VECTOR3_HPP
0262 
0263 
0264 ////////////////////////////////////////////////////////////
0265 /// \class sf::Vector3
0266 /// \ingroup system
0267 ///
0268 /// sf::Vector3 is a simple class that defines a mathematical
0269 /// vector with three coordinates (x, y and z). It can be used to
0270 /// represent anything that has three dimensions: a size, a point,
0271 /// a velocity, etc.
0272 ///
0273 /// The template parameter T is the type of the coordinates. It
0274 /// can be any type that supports arithmetic operations (+, -, /, *)
0275 /// and comparisons (==, !=), for example int or float.
0276 ///
0277 /// You generally don't have to care about the templated form (sf::Vector3<T>),
0278 /// the most common specializations have special typedefs:
0279 /// \li sf::Vector3<float> is sf::Vector3f
0280 /// \li sf::Vector3<int> is sf::Vector3i
0281 ///
0282 /// The sf::Vector3 class has a small and simple interface, its x and y members
0283 /// can be accessed directly (there are no accessors like setX(), getX()) and it
0284 /// contains no mathematical function like dot product, cross product, length, etc.
0285 ///
0286 /// Usage example:
0287 /// \code
0288 /// sf::Vector3f v1(16.5f, 24.f, -8.2f);
0289 /// v1.x = 18.2f;
0290 /// float y = v1.y;
0291 /// float z = v1.z;
0292 ///
0293 /// sf::Vector3f v2 = v1 * 5.f;
0294 /// sf::Vector3f v3;
0295 /// v3 = v1 + v2;
0296 ///
0297 /// bool different = (v2 != v3);
0298 /// \endcode
0299 ///
0300 /// Note: for 2-dimensional vectors, see sf::Vector2.
0301 ///
0302 ////////////////////////////////////////////////////////////