1/*
2---------------------------------------------------------------------------
3Open Asset Import Library (assimp)
4---------------------------------------------------------------------------
5
6Copyright (c) 2006-2019, assimp team
7
8
9
10All rights reserved.
11
12Redistribution and use of this software in source and binary forms,
13with or without modification, are permitted provided that the following
14conditions are met:
15
16* Redistributions of source code must retain the above
17 copyright notice, this list of conditions and the
18 following disclaimer.
19
20* Redistributions in binary form must reproduce the above
21 copyright notice, this list of conditions and the
22 following disclaimer in the documentation and/or other
23 materials provided with the distribution.
24
25* Neither the name of the assimp team, nor the names of its
26 contributors may be used to endorse or promote products
27 derived from this software without specific prior
28 written permission of the assimp team.
29
30THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41---------------------------------------------------------------------------
42*/
43/** @file vector3.h
44 * @brief 3D vector structure, including operators when compiling in C++
45 */
46#pragma once
47#ifndef AI_VECTOR3D_H_INC
48#define AI_VECTOR3D_H_INC
49
50#ifdef __cplusplus
51# include <cmath>
52#else
53# include <math.h>
54#endif
55
56#include "defs.h"
57
58#ifdef __cplusplus
59
60template<typename TReal> class aiMatrix3x3t;
61template<typename TReal> class aiMatrix4x4t;
62
63// ---------------------------------------------------------------------------
64/** Represents a three-dimensional vector. */
65template <typename TReal>
66class aiVector3t
67{
68public:
69 aiVector3t() AI_NO_EXCEPT : x(), y(), z() {}
70 aiVector3t(TReal _x, TReal _y, TReal _z) : x(_x), y(_y), z(_z) {}
71 explicit aiVector3t (TReal _xyz ) : x(_xyz), y(_xyz), z(_xyz) {}
72 aiVector3t( const aiVector3t& o ) = default;
73
74public:
75
76 // combined operators
77 const aiVector3t& operator += (const aiVector3t& o);
78 const aiVector3t& operator -= (const aiVector3t& o);
79 const aiVector3t& operator *= (TReal f);
80 const aiVector3t& operator /= (TReal f);
81
82 // transform vector by matrix
83 aiVector3t& operator *= (const aiMatrix3x3t<TReal>& mat);
84 aiVector3t& operator *= (const aiMatrix4x4t<TReal>& mat);
85
86 // access a single element
87 TReal operator[](unsigned int i) const;
88 TReal& operator[](unsigned int i);
89
90 // comparison
91 bool operator== (const aiVector3t& other) const;
92 bool operator!= (const aiVector3t& other) const;
93 bool operator < (const aiVector3t& other) const;
94
95 bool Equal(const aiVector3t& other, TReal epsilon = 1e-6) const;
96
97 template <typename TOther>
98 operator aiVector3t<TOther> () const;
99
100public:
101 /** @brief Set the components of a vector
102 * @param pX X component
103 * @param pY Y component
104 * @param pZ Z component */
105 void Set( TReal pX, TReal pY, TReal pZ);
106
107 /** @brief Get the squared length of the vector
108 * @return Square length */
109 TReal SquareLength() const;
110
111 /** @brief Get the length of the vector
112 * @return length */
113 TReal Length() const;
114
115
116 /** @brief Normalize the vector */
117 aiVector3t& Normalize();
118
119 /** @brief Normalize the vector with extra check for zero vectors */
120 aiVector3t& NormalizeSafe();
121
122 /** @brief Componentwise multiplication of two vectors
123 *
124 * Note that vec*vec yields the dot product.
125 * @param o Second factor */
126 const aiVector3t SymMul(const aiVector3t& o);
127
128 TReal x, y, z;
129};
130
131
132typedef aiVector3t<ai_real> aiVector3D;
133
134#else
135
136struct aiVector3D {
137 ai_real x, y, z;
138};
139
140#endif // __cplusplus
141
142#ifdef __cplusplus
143
144#endif // __cplusplus
145
146#endif // AI_VECTOR3D_H_INC
147

source code of qt3d/src/3rdparty/assimp/src/include/assimp/vector3.h