Vector3.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * This source file is part of rocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2014 Markus Schöngart
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCOREVECTOR3_H
  28. #define ROCKETCOREVECTOR3_H
  29. #include "Debug.h"
  30. #include "Math.h"
  31. namespace Rocket {
  32. namespace Core {
  33. /**
  34. Templated class for a generic three-component vector.
  35. @author Markus Schöngart
  36. */
  37. template < typename Type >
  38. class Vector3
  39. {
  40. public:
  41. /// Lightweight, non-initialising constructor.
  42. inline Vector3();
  43. /// Initialising constructor.
  44. /// @param[in] x Initial x-value of the vector.
  45. /// @param[in] y Initial y-value of the vector.
  46. /// @param[in] z Initial z-value of the vector.
  47. inline Vector3(Type x, Type y, Type z);
  48. /// Returns the magnitude of the vector.
  49. /// @return The computed magnitude.
  50. inline float Magnitude() const;
  51. /// Returns the squared magnitude of the vector.
  52. /// @return The computed squared magnitude.
  53. inline Type SquaredMagnitude() const;
  54. /// Generates a normalised vector from this vector.
  55. /// @return The normalised vector.
  56. inline Vector3 Normalise() const;
  57. /// Computes the dot-product between this vector and another.
  58. /// @param[in] rhs The other vector to use in the dot-product.
  59. /// @return The computed dot-product between the two vectors.
  60. inline Type DotProduct(const Vector3& rhs) const;
  61. /// Computes the cross-product between this vector and another.
  62. /// @param[in] rhs The other vector to use in the dot-product.
  63. /// @return The computed cross-product between the two vectors.
  64. inline Vector3 CrossProduct(const Vector3& rhs) const;
  65. /// Returns the negation of this vector.
  66. /// @return The negation of this vector.
  67. inline Vector3 operator-() const;
  68. /// Returns the sum of this vector and another.
  69. /// @param[in] rhs The vector to add this to.
  70. /// @return The sum of the two vectors.
  71. inline Vector3 operator+(const Vector3& rhs) const;
  72. /// Returns the result of subtracting another vector from this vector.
  73. /// @param[in] rhs The vector to subtract from this vector.
  74. /// @return The result of the subtraction.
  75. inline Vector3 operator-(const Vector3& rhs) const;
  76. /// Returns the result of multiplying this vector by a scalar.
  77. /// @param[in] rhs The scalar value to multiply by.
  78. /// @return The result of the scale.
  79. inline Vector3 operator*(Type rhs) const;
  80. /// Returns the result of dividing this vector by a scalar.
  81. /// @param[in] rhs The scalar value to divide by.
  82. /// @return The result of the scale.
  83. inline Vector3 operator/(Type rhs) const;
  84. /// Adds another vector to this in-place.
  85. /// @param[in] rhs The vector to add.
  86. /// @return This vector, post-operation.
  87. inline Vector3& operator+=(const Vector3& rhs);
  88. /// Subtracts another vector from this in-place.
  89. /// @param[in] rhs The vector to subtract.
  90. /// @return This vector, post-operation.
  91. inline Vector3& operator-=(const Vector3& rhs);
  92. /// Scales this vector in-place.
  93. /// @param[in] rhs The value to scale this vector's components by.
  94. /// @return This vector, post-operation.
  95. inline Vector3& operator*=(const Type& rhs);
  96. /// Scales this vector in-place by the inverse of a value.
  97. /// @param[in] rhs The value to divide this vector's components by.
  98. /// @return This vector, post-operation.
  99. inline Vector3& operator/=(const Type& rhs);
  100. /// Equality operator.
  101. /// @param[in] rhs The vector to compare this against.
  102. /// @return True if the two vectors are equal, false otherwise.
  103. inline bool operator==(const Vector3& rhs) const;
  104. /// Inequality operator.
  105. /// @param[in] rhs The vector to compare this against.
  106. /// @return True if the two vectors are not equal, false otherwise.
  107. inline bool operator!=(const Vector3& rhs) const;
  108. /// Constant auto-cast operator.
  109. /// @return A pointer to the first value.
  110. inline operator const Type*() const;
  111. /// Auto-cast operator.
  112. /// @return A constant pointer to the first value.
  113. inline operator Type*();
  114. // The components of the vector.
  115. Type x;
  116. Type y;
  117. Type z;
  118. };
  119. }
  120. }
  121. #include "Vector3.inl"
  122. #endif