Vector4.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 ROCKETCOREVECTOR4_H
  28. #define ROCKETCOREVECTOR4_H
  29. #include "Debug.h"
  30. #include "Math.h"
  31. #include "Vector3.h"
  32. namespace Rocket {
  33. namespace Core {
  34. /**
  35. Templated class for a generic four-component vector.
  36. @author Markus Schöngart
  37. */
  38. template < typename Type >
  39. class Vector4
  40. {
  41. public:
  42. /// Lightweight, non-initialising constructor.
  43. inline Vector4();
  44. /// Initialising constructor.
  45. /// @param[in] x Initial x-value of the vector.
  46. /// @param[in] y Initial y-value of the vector.
  47. /// @param[in] z Initial z-value of the vector.
  48. /// @param[in] w Initial omega-value of the vector.
  49. inline Vector4(Type x, Type y, Type z, Type w = 1);
  50. /// Implicit conversion from a 3D Vector.
  51. inline Vector4(Vector3< Type > const &v, Type w = 1);
  52. /// Returns the magnitude of the vector.
  53. /// @return The computed magnitude.
  54. inline float Magnitude() const;
  55. /// Returns the squared magnitude of the vector.
  56. /// @return The computed squared magnitude.
  57. inline Type SquaredMagnitude() const;
  58. /// Generates a normalised vector from this vector.
  59. /// @return The normalised vector.
  60. inline Vector4 Normalise() const;
  61. /// Computes the dot-product between this vector and another.
  62. /// @param[in] rhs The other vector to use in the dot-product.
  63. /// @return The computed dot-product between the two vectors.
  64. inline Type DotProduct(const Vector4& rhs) const;
  65. /// Returns the negation of this vector.
  66. /// @return The negation of this vector.
  67. inline Vector4 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 Vector4 operator+(const Vector4& 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 Vector4 operator-(const Vector4& 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 Vector4 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 Vector4 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 Vector4& operator+=(const Vector4& 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 Vector4& operator-=(const Vector4& 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 Vector4& 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 Vector4& 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 Vector4& 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 Vector4& rhs) const;
  108. /// Auto-cast operator to array of components.
  109. /// @return A pointer to the first value.
  110. inline operator const Type*() const;
  111. /// Constant auto-cast operator to array of components.
  112. /// @return A constant pointer to the first value.
  113. inline operator Type*();
  114. /// Auto-cast operator to 3D vector.
  115. /// @return Equivalent 3D vector.
  116. inline operator Vector3< Type >() const;
  117. // The components of the vector.
  118. Type x;
  119. Type y;
  120. Type z;
  121. Type w;
  122. };
  123. }
  124. }
  125. #include "Vector4.inl"
  126. #endif