1 /* -----------------------------------------------------------------------------
3 Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 -------------------------------------------------------------------------- */
26 #ifndef SQUISH_MATHS_H
27 #define SQUISH_MATHS_H
38 typedef Vec3
const& Arg
;
40 Vec3() : m_x(0.f
), m_y(0.f
), m_z(0.f
)
44 explicit Vec3( float s
) : m_x(s
), m_y(s
), m_z(s
)
48 Vec3( float x
, float y
, float z
) : m_x(x
), m_y(y
), m_z(z
)
52 float X() const { return m_x
; }
53 float Y() const { return m_y
; }
54 float Z() const { return m_z
; }
56 Vec3
operator-() const
58 return Vec3( -m_x
, -m_y
, -m_z
);
61 Vec3
& operator+=( Arg v
)
69 Vec3
& operator-=( Arg v
)
77 Vec3
& operator*=( Arg v
)
85 Vec3
& operator*=( float s
)
93 Vec3
& operator/=( Arg v
)
101 Vec3
& operator/=( float s
)
110 friend Vec3
operator+( Arg left
, Arg right
)
113 return copy
+= right
;
116 friend Vec3
operator-( Arg left
, Arg right
)
119 return copy
-= right
;
122 friend Vec3
operator*( Arg left
, Arg right
)
125 return copy
*= right
;
128 friend Vec3
operator*( Arg left
, float right
)
131 return copy
*= right
;
134 friend Vec3
operator*( float left
, Arg right
)
140 friend Vec3
operator/( Arg left
, Arg right
)
143 return copy
/= right
;
146 friend Vec3
operator/( Arg left
, float right
)
149 return copy
/= right
;
152 friend float Dot( Arg left
, Arg right
)
154 return left
.m_x
*right
.m_x
+ left
.m_y
*right
.m_y
+ left
.m_z
*right
.m_z
;
157 friend Vec3
Min( Arg left
, Arg right
)
160 std::min( left
.m_x
, right
.m_x
),
161 std::min( left
.m_y
, right
.m_y
),
162 std::min( left
.m_z
, right
.m_z
)
166 friend Vec3
Max( Arg left
, Arg right
)
169 std::max( left
.m_x
, right
.m_x
),
170 std::max( left
.m_y
, right
.m_y
),
171 std::max( left
.m_z
, right
.m_z
)
175 friend Vec3
Truncate( Arg v
)
178 v
.m_x
> 0.0f
? std::floor( v
.m_x
) : std::ceil( v
.m_x
),
179 v
.m_y
> 0.0f
? std::floor( v
.m_y
) : std::ceil( v
.m_y
),
180 v
.m_z
> 0.0f
? std::floor( v
.m_z
) : std::ceil( v
.m_z
)
190 inline float LengthSquared( Vec3::Arg v
)
204 for( int i
= 0; i
< 6; ++i
)
208 float operator[]( int index
) const
213 float& operator[]( int index
)
222 Sym3x3
ComputeWeightedCovariance( int n
, Vec3
const* points
, float const* weights
);
223 Vec3
ComputePrincipleComponent( Sym3x3
const& matrix
);
225 } // namespace squish
227 #endif // ndef SQUISH_MATHS_H