aiVector3D.inl 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2010, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file aiVector3D.inl
  35. * @brief Inline implementation of aiVector3D operators
  36. */
  37. #ifndef AI_VECTOR3D_INL_INC
  38. #define AI_VECTOR3D_INL_INC
  39. #include "aiVector3D.h"
  40. #ifdef __cplusplus
  41. // ------------------------------------------------------------------------------------------------
  42. /** Transformation of a vector by a 3x3 matrix */
  43. inline aiVector3D operator * (const aiMatrix3x3& pMatrix, const aiVector3D& pVector)
  44. {
  45. aiVector3D res;
  46. res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z;
  47. res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z;
  48. res.z = pMatrix.c1 * pVector.x + pMatrix.c2 * pVector.y + pMatrix.c3 * pVector.z;
  49. return res;
  50. }
  51. // ------------------------------------------------------------------------------------------------
  52. /** Transformation of a vector by a 4x4 matrix */
  53. inline aiVector3D operator * (const aiMatrix4x4& pMatrix, const aiVector3D& pVector)
  54. {
  55. aiVector3D res;
  56. res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z + pMatrix.a4;
  57. res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z + pMatrix.b4;
  58. res.z = pMatrix.c1 * pVector.x + pMatrix.c2 * pVector.y + pMatrix.c3 * pVector.z + pMatrix.c4;
  59. return res;
  60. }
  61. // ------------------------------------------------------------------------------------------------
  62. AI_FORCE_INLINE void aiVector3D::Set( float pX, float pY, float pZ) {
  63. x = pX; y = pY; z = pZ;
  64. }
  65. // ------------------------------------------------------------------------------------------------
  66. AI_FORCE_INLINE float aiVector3D::SquareLength() const {
  67. return x*x + y*y + z*z;
  68. }
  69. // ------------------------------------------------------------------------------------------------
  70. AI_FORCE_INLINE float aiVector3D::Length() const {
  71. return sqrt( SquareLength());
  72. }
  73. // ------------------------------------------------------------------------------------------------
  74. AI_FORCE_INLINE aiVector3D& aiVector3D::Normalize() {
  75. *this /= Length(); return *this;
  76. }
  77. // ------------------------------------------------------------------------------------------------
  78. AI_FORCE_INLINE const aiVector3D& aiVector3D::operator += (const aiVector3D& o) {
  79. x += o.x; y += o.y; z += o.z; return *this;
  80. }
  81. // ------------------------------------------------------------------------------------------------
  82. AI_FORCE_INLINE const aiVector3D& aiVector3D::operator -= (const aiVector3D& o) {
  83. x -= o.x; y -= o.y; z -= o.z; return *this;
  84. }
  85. // ------------------------------------------------------------------------------------------------
  86. AI_FORCE_INLINE const aiVector3D& aiVector3D::operator *= (float f) {
  87. x *= f; y *= f; z *= f; return *this;
  88. }
  89. // ------------------------------------------------------------------------------------------------
  90. AI_FORCE_INLINE const aiVector3D& aiVector3D::operator /= (float f) {
  91. x /= f; y /= f; z /= f; return *this;
  92. }
  93. // ------------------------------------------------------------------------------------------------
  94. AI_FORCE_INLINE aiVector3D& aiVector3D::operator *= (const aiMatrix3x3& mat){
  95. return(*this = mat * (*this));
  96. }
  97. // ------------------------------------------------------------------------------------------------
  98. AI_FORCE_INLINE aiVector3D& aiVector3D::operator *= (const aiMatrix4x4& mat){
  99. return(*this = mat * (*this));
  100. }
  101. // ------------------------------------------------------------------------------------------------
  102. AI_FORCE_INLINE float aiVector3D::operator[](unsigned int i) const {
  103. return *(&x + i);
  104. }
  105. // ------------------------------------------------------------------------------------------------
  106. AI_FORCE_INLINE float& aiVector3D::operator[](unsigned int i) {
  107. return *(&x + i);
  108. }
  109. // ------------------------------------------------------------------------------------------------
  110. AI_FORCE_INLINE bool aiVector3D::operator== (const aiVector3D& other) const {
  111. return x == other.x && y == other.y && z == other.z;
  112. }
  113. // ------------------------------------------------------------------------------------------------
  114. AI_FORCE_INLINE bool aiVector3D::operator!= (const aiVector3D& other) const {
  115. return x != other.x || y != other.y || z != other.z;
  116. }
  117. // ------------------------------------------------------------------------------------------------
  118. AI_FORCE_INLINE const aiVector3D aiVector3D::SymMul(const aiVector3D& o) {
  119. return aiVector3D(x*o.x,y*o.y,z*o.z);
  120. }
  121. // ------------------------------------------------------------------------------------------------
  122. // symmetric addition
  123. AI_FORCE_INLINE aiVector3D operator + (const aiVector3D& v1, const aiVector3D& v2) {
  124. return aiVector3D( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
  125. }
  126. // ------------------------------------------------------------------------------------------------
  127. // symmetric subtraction
  128. AI_FORCE_INLINE aiVector3D operator - (const aiVector3D& v1, const aiVector3D& v2) {
  129. return aiVector3D( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
  130. }
  131. // ------------------------------------------------------------------------------------------------
  132. // scalar product
  133. AI_FORCE_INLINE float operator * (const aiVector3D& v1, const aiVector3D& v2) {
  134. return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
  135. }
  136. // ------------------------------------------------------------------------------------------------
  137. // scalar multiplication
  138. AI_FORCE_INLINE aiVector3D operator * ( float f, const aiVector3D& v) {
  139. return aiVector3D( f*v.x, f*v.y, f*v.z);
  140. }
  141. // ------------------------------------------------------------------------------------------------
  142. // and the other way around
  143. AI_FORCE_INLINE aiVector3D operator * ( const aiVector3D& v, float f) {
  144. return aiVector3D( f*v.x, f*v.y, f*v.z);
  145. }
  146. // ------------------------------------------------------------------------------------------------
  147. // scalar division
  148. AI_FORCE_INLINE aiVector3D operator / ( const aiVector3D& v, float f) {
  149. return v * (1/f);
  150. }
  151. // ------------------------------------------------------------------------------------------------
  152. // vector division
  153. AI_FORCE_INLINE aiVector3D operator / ( const aiVector3D& v, const aiVector3D& v2) {
  154. return aiVector3D(v.x / v2.x,v.y / v2.y,v.z / v2.z);
  155. }
  156. // ------------------------------------------------------------------------------------------------
  157. // cross product
  158. AI_FORCE_INLINE aiVector3D operator ^ ( const aiVector3D& v1, const aiVector3D& v2) {
  159. return aiVector3D( v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x);
  160. }
  161. // ------------------------------------------------------------------------------------------------
  162. // vector inversion
  163. AI_FORCE_INLINE aiVector3D operator - ( const aiVector3D& v) {
  164. return aiVector3D( -v.x, -v.y, -v.z);
  165. }
  166. #endif // __cplusplus
  167. #endif // AI_VECTOR3D_INL_INC