aiVector3D.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.h
  35. * @brief 3D vector structure, including operators when compiling in C++
  36. */
  37. #ifndef AI_VECTOR3D_H_INC
  38. #define AI_VECTOR3D_H_INC
  39. #include <math.h>
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #include "./Compiler/pushpack1.h"
  44. struct aiMatrix3x3;
  45. struct aiMatrix4x4;
  46. // ---------------------------------------------------------------------------
  47. /** Represents a three-dimensional vector. */
  48. struct aiVector3D
  49. {
  50. #ifdef __cplusplus
  51. aiVector3D () : x(0.0f), y(0.0f), z(0.0f) {}
  52. aiVector3D (float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
  53. aiVector3D (float _xyz) : x(_xyz), y(_xyz), z(_xyz) {}
  54. aiVector3D (const aiVector3D& o) : x(o.x), y(o.y), z(o.z) {}
  55. public:
  56. // combined operators
  57. const aiVector3D& operator += (const aiVector3D& o);
  58. const aiVector3D& operator -= (const aiVector3D& o);
  59. const aiVector3D& operator *= (float f);
  60. const aiVector3D& operator /= (float f);
  61. // transform vector by matrix
  62. aiVector3D& operator *= (const aiMatrix3x3& mat);
  63. aiVector3D& operator *= (const aiMatrix4x4& mat);
  64. // access a single element
  65. float operator[](unsigned int i) const;
  66. float& operator[](unsigned int i);
  67. // comparison
  68. bool operator== (const aiVector3D& other) const;
  69. bool operator!= (const aiVector3D& other) const;
  70. public:
  71. /** @brief Set the components of a vector
  72. * @param pX X component
  73. * @param pY Y component
  74. * @param pZ Z component */
  75. void Set( float pX, float pY, float pZ = 0.f);
  76. /** @brief Get the squared length of the vector
  77. * @return Square length */
  78. float SquareLength() const;
  79. /** @brief Get the length of the vector
  80. * @return length */
  81. float Length() const;
  82. /** @brief Normalize the vector */
  83. aiVector3D& Normalize();
  84. /** @brief Componentwise multiplication of two vectors
  85. *
  86. * Note that vec*vec yields the dot product.
  87. * @param o Second factor */
  88. const aiVector3D SymMul(const aiVector3D& o);
  89. #endif // __cplusplus
  90. float x, y, z;
  91. } PACK_STRUCT;
  92. #include "./Compiler/poppack1.h"
  93. #ifdef __cplusplus
  94. } // end extern "C"
  95. #endif // __cplusplus
  96. #endif // AI_VECTOR3D_H_INC