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