2 Copyright (C) 2006-2010 Sony Computer Entertainment Inc.
\r
5 Redistribution and use in source and binary forms,
\r
6 with or without modification, are permitted provided that the
\r
7 following conditions are met:
\r
8 * Redistributions of source code must retain the above copyright
\r
9 notice, this list of conditions and the following disclaimer.
\r
10 * Redistributions in binary form must reproduce the above copyright
\r
11 notice, this list of conditions and the following disclaimer in the
\r
12 documentation and/or other materials provided with the distribution.
\r
13 * Neither the name of the Sony Computer Entertainment Inc nor the names
\r
14 of its contributors may be used to endorse or promote products derived
\r
15 from this software without specific prior written permission.
\r
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
\r
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
27 POSSIBILITY OF SUCH DAMAGE.
\r
30 #ifndef _FLOATINVEC__SCALAR_H
\r
31 #define _FLOATINVEC__SCALAR_H
\r
34 namespace Vectormath {
\r
38 //--------------------------------------------------------------------------------------------------
\r
42 // A class representing a scalar float value contained in a vector register
\r
43 // This class does not support fastmath
\r
50 // Default constructor; does no initialization
\r
52 inline floatInVec( ) { };
\r
54 // Construct from a value converted from bool
\r
56 inline floatInVec(boolInVec vec);
\r
58 // Explicit cast from float
\r
60 explicit inline floatInVec(float scalar);
\r
62 // Explicit cast to float
\r
64 inline float getAsFloat() const;
\r
66 #ifndef _VECTORMATH_NO_SCALAR_CAST
\r
67 // Implicit cast to float
\r
69 inline operator float() const;
\r
72 // Post increment (add 1.0f)
\r
74 inline const floatInVec operator ++ (int);
\r
76 // Post decrement (subtract 1.0f)
\r
78 inline const floatInVec operator -- (int);
\r
80 // Pre increment (add 1.0f)
\r
82 inline floatInVec& operator ++ ();
\r
84 // Pre decrement (subtract 1.0f)
\r
86 inline floatInVec& operator -- ();
\r
88 // Negation operator
\r
90 inline const floatInVec operator - () const;
\r
92 // Assignment operator
\r
94 inline floatInVec& operator = (floatInVec vec);
\r
96 // Multiplication assignment operator
\r
98 inline floatInVec& operator *= (floatInVec vec);
\r
100 // Division assignment operator
\r
102 inline floatInVec& operator /= (floatInVec vec);
\r
104 // Addition assignment operator
\r
106 inline floatInVec& operator += (floatInVec vec);
\r
108 // Subtraction assignment operator
\r
110 inline floatInVec& operator -= (floatInVec vec);
\r
114 // Multiplication operator
\r
116 inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);
\r
118 // Division operator
\r
120 inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);
\r
122 // Addition operator
\r
124 inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);
\r
126 // Subtraction operator
\r
128 inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);
\r
130 // Less than operator
\r
132 inline const boolInVec operator < (floatInVec vec0, floatInVec vec1);
\r
134 // Less than or equal operator
\r
136 inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1);
\r
138 // Greater than operator
\r
140 inline const boolInVec operator > (floatInVec vec0, floatInVec vec1);
\r
142 // Greater than or equal operator
\r
144 inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1);
\r
148 inline const boolInVec operator == (floatInVec vec0, floatInVec vec1);
\r
150 // Not equal operator
\r
152 inline const boolInVec operator != (floatInVec vec0, floatInVec vec1);
\r
154 // Conditionally select between two values
\r
156 inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
\r
159 } // namespace Vectormath
\r
162 //--------------------------------------------------------------------------------------------------
\r
163 // floatInVec implementation
\r
166 #include "boolInVec.h"
\r
168 namespace Vectormath {
\r
171 floatInVec::floatInVec(boolInVec vec)
\r
173 mData = float(vec.getAsBool());
\r
177 floatInVec::floatInVec(float scalar)
\r
184 floatInVec::getAsFloat() const
\r
189 #ifndef _VECTORMATH_NO_SCALAR_CAST
\r
191 floatInVec::operator float() const
\r
193 return getAsFloat();
\r
199 floatInVec::operator ++ (int)
\r
201 float olddata = mData;
\r
203 return floatInVec(olddata);
\r
208 floatInVec::operator -- (int)
\r
210 float olddata = mData;
\r
212 return floatInVec(olddata);
\r
217 floatInVec::operator ++ ()
\r
219 *this += floatInVec(1.0f);
\r
225 floatInVec::operator -- ()
\r
227 *this -= floatInVec(1.0f);
\r
233 floatInVec::operator - () const
\r
235 return floatInVec(-mData);
\r
240 floatInVec::operator = (floatInVec vec)
\r
248 floatInVec::operator *= (floatInVec vec)
\r
250 *this = *this * vec;
\r
256 floatInVec::operator /= (floatInVec vec)
\r
258 *this = *this / vec;
\r
264 floatInVec::operator += (floatInVec vec)
\r
266 *this = *this + vec;
\r
272 floatInVec::operator -= (floatInVec vec)
\r
274 *this = *this - vec;
\r
280 operator * (floatInVec vec0, floatInVec vec1)
\r
282 return floatInVec(vec0.getAsFloat() * vec1.getAsFloat());
\r
287 operator / (floatInVec num, floatInVec den)
\r
289 return floatInVec(num.getAsFloat() / den.getAsFloat());
\r
294 operator + (floatInVec vec0, floatInVec vec1)
\r
296 return floatInVec(vec0.getAsFloat() + vec1.getAsFloat());
\r
301 operator - (floatInVec vec0, floatInVec vec1)
\r
303 return floatInVec(vec0.getAsFloat() - vec1.getAsFloat());
\r
308 operator < (floatInVec vec0, floatInVec vec1)
\r
310 return boolInVec(vec0.getAsFloat() < vec1.getAsFloat());
\r
315 operator <= (floatInVec vec0, floatInVec vec1)
\r
317 return !(vec0 > vec1);
\r
322 operator > (floatInVec vec0, floatInVec vec1)
\r
324 return boolInVec(vec0.getAsFloat() > vec1.getAsFloat());
\r
329 operator >= (floatInVec vec0, floatInVec vec1)
\r
331 return !(vec0 < vec1);
\r
336 operator == (floatInVec vec0, floatInVec vec1)
\r
338 return boolInVec(vec0.getAsFloat() == vec1.getAsFloat());
\r
343 operator != (floatInVec vec0, floatInVec vec1)
\r
345 return !(vec0 == vec1);
\r
350 select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1)
\r
352 return (select_vec1.getAsBool() == 0) ? vec0 : vec1;
\r
355 } // namespace Vectormath
\r
357 #endif // floatInVec_h
\r