miniassimp

view include/miniassimp/vector3.h @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2018, assimp team
10 All rights reserved.
12 Redistribution and use of this software in source and binary forms,
13 with or without modification, are permitted provided that the following
14 conditions are met:
16 * Redistributions of source code must retain the above
17 copyright notice, this list of conditions and the
18 following disclaimer.
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.
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.
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 OF 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
50 #ifdef __cplusplus
51 # include <cmath>
52 #else
53 # include <math.h>
54 #endif
56 #include "defs.h"
58 #ifdef __cplusplus
60 template<typename TReal> class aiMatrix3x3t;
61 template<typename TReal> class aiMatrix4x4t;
63 // ---------------------------------------------------------------------------
64 /** Represents a three-dimensional vector. */
65 template <typename TReal>
66 class aiVector3t
67 {
68 public:
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) {}
73 public:
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);
81 // transform vector by matrix
82 aiVector3t& operator *= (const aiMatrix3x3t<TReal>& mat);
83 aiVector3t& operator *= (const aiMatrix4x4t<TReal>& mat);
85 // access a single element
86 TReal operator[](unsigned int i) const;
87 TReal& operator[](unsigned int i);
89 // comparison
90 bool operator== (const aiVector3t& other) const;
91 bool operator!= (const aiVector3t& other) const;
92 bool operator < (const aiVector3t& other) const;
94 bool Equal(const aiVector3t& other, TReal epsilon = 1e-6) const;
96 template <typename TOther>
97 operator aiVector3t<TOther> () const;
99 public:
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);
106 /** @brief Get the squared length of the vector
107 * @return Square length */
108 TReal SquareLength() const;
110 /** @brief Get the length of the vector
111 * @return length */
112 TReal Length() const;
115 /** @brief Normalize the vector */
116 aiVector3t& Normalize();
118 /** @brief Normalize the vector with extra check for zero vectors */
119 aiVector3t& NormalizeSafe();
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);
127 TReal x, y, z;
128 };
131 typedef aiVector3t<ai_real> aiVector3D;
133 #else
135 struct aiVector3D {
136 ai_real x, y, z;
137 };
139 #endif // __cplusplus
141 #ifdef __cplusplus
143 #endif // __cplusplus
145 #endif // AI_VECTOR3D_H_INC