Bullet Collision Detection & Physics Library
scalar/floatInVec.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Sony Computer Entertainment Inc.
3  All rights reserved.
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 
15 */
16 #ifndef _FLOATINVEC_H
17 #define _FLOATINVEC_H
18 
19 #include <math.h>
20 namespace Vectormath {
21 
22 class boolInVec;
23 
24 //--------------------------------------------------------------------------------------------------
25 // floatInVec class
26 //
27 
28 // A class representing a scalar float value contained in a vector register
29 // This class does not support fastmath
30 class floatInVec
31 {
32 private:
33  float mData;
34 
35 public:
36  // Default constructor; does no initialization
37  //
38  inline floatInVec( ) { };
39 
40  // Construct from a value converted from bool
41  //
42  inline floatInVec(boolInVec vec);
43 
44  // Explicit cast from float
45  //
46  explicit inline floatInVec(float scalar);
47 
48  // Explicit cast to float
49  //
50  inline float getAsFloat() const;
51 
52 #ifndef _VECTORMATH_NO_SCALAR_CAST
53  // Implicit cast to float
54  //
55  inline operator float() const;
56 #endif
57 
58  // Post increment (add 1.0f)
59  //
60  inline const floatInVec operator ++ (int);
61 
62  // Post decrement (subtract 1.0f)
63  //
64  inline const floatInVec operator -- (int);
65 
66  // Pre increment (add 1.0f)
67  //
68  inline floatInVec& operator ++ ();
69 
70  // Pre decrement (subtract 1.0f)
71  //
72  inline floatInVec& operator -- ();
73 
74  // Negation operator
75  //
76  inline const floatInVec operator - () const;
77 
78  // Assignment operator
79  //
80  inline floatInVec& operator = (floatInVec vec);
81 
82  // Multiplication assignment operator
83  //
84  inline floatInVec& operator *= (floatInVec vec);
85 
86  // Division assignment operator
87  //
88  inline floatInVec& operator /= (floatInVec vec);
89 
90  // Addition assignment operator
91  //
92  inline floatInVec& operator += (floatInVec vec);
93 
94  // Subtraction assignment operator
95  //
96  inline floatInVec& operator -= (floatInVec vec);
97 
98 };
99 
100 // Multiplication operator
101 //
102 inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);
103 
104 // Division operator
105 //
106 inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);
107 
108 // Addition operator
109 //
110 inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);
111 
112 // Subtraction operator
113 //
114 inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);
115 
116 // Less than operator
117 //
118 inline const boolInVec operator < (floatInVec vec0, floatInVec vec1);
119 
120 // Less than or equal operator
121 //
122 inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1);
123 
124 // Greater than operator
125 //
126 inline const boolInVec operator > (floatInVec vec0, floatInVec vec1);
127 
128 // Greater than or equal operator
129 //
130 inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1);
131 
132 // Equal operator
133 //
134 inline const boolInVec operator == (floatInVec vec0, floatInVec vec1);
135 
136 // Not equal operator
137 //
138 inline const boolInVec operator != (floatInVec vec0, floatInVec vec1);
139 
140 // Conditionally select between two values
141 //
142 inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
143 
144 
145 } // namespace Vectormath
146 
147 
148 //--------------------------------------------------------------------------------------------------
149 // floatInVec implementation
150 //
151 
152 #include "boolInVec.h"
153 
154 namespace Vectormath {
155 
156 inline
157 floatInVec::floatInVec(boolInVec vec)
158 {
159  mData = float(vec.getAsBool());
160 }
161 
162 inline
163 floatInVec::floatInVec(float scalar)
164 {
165  mData = scalar;
166 }
167 
168 inline
169 float
171 {
172  return mData;
173 }
174 
175 #ifndef _VECTORMATH_NO_SCALAR_CAST
176 inline
177 floatInVec::operator float() const
178 {
179  return getAsFloat();
180 }
181 #endif
182 
183 inline
184 const floatInVec
186 {
187  float olddata = mData;
188  operator ++();
189  return floatInVec(olddata);
190 }
191 
192 inline
193 const floatInVec
195 {
196  float olddata = mData;
197  operator --();
198  return floatInVec(olddata);
199 }
200 
201 inline
202 floatInVec&
204 {
205  *this += floatInVec(1.0f);
206  return *this;
207 }
208 
209 inline
210 floatInVec&
212 {
213  *this -= floatInVec(1.0f);
214  return *this;
215 }
216 
217 inline
218 const floatInVec
220 {
221  return floatInVec(-mData);
222 }
223 
224 inline
225 floatInVec&
226 floatInVec::operator = (floatInVec vec)
227 {
228  mData = vec.mData;
229  return *this;
230 }
231 
232 inline
233 floatInVec&
234 floatInVec::operator *= (floatInVec vec)
235 {
236  *this = *this * vec;
237  return *this;
238 }
239 
240 inline
241 floatInVec&
242 floatInVec::operator /= (floatInVec vec)
243 {
244  *this = *this / vec;
245  return *this;
246 }
247 
248 inline
249 floatInVec&
250 floatInVec::operator += (floatInVec vec)
251 {
252  *this = *this + vec;
253  return *this;
254 }
255 
256 inline
257 floatInVec&
258 floatInVec::operator -= (floatInVec vec)
259 {
260  *this = *this - vec;
261  return *this;
262 }
263 
264 inline
265 const floatInVec
266 operator * (floatInVec vec0, floatInVec vec1)
267 {
268  return floatInVec(vec0.getAsFloat() * vec1.getAsFloat());
269 }
270 
271 inline
272 const floatInVec
273 operator / (floatInVec num, floatInVec den)
274 {
275  return floatInVec(num.getAsFloat() / den.getAsFloat());
276 }
277 
278 inline
279 const floatInVec
280 operator + (floatInVec vec0, floatInVec vec1)
281 {
282  return floatInVec(vec0.getAsFloat() + vec1.getAsFloat());
283 }
284 
285 inline
286 const floatInVec
287 operator - (floatInVec vec0, floatInVec vec1)
288 {
289  return floatInVec(vec0.getAsFloat() - vec1.getAsFloat());
290 }
291 
292 inline
293 const boolInVec
294 operator < (floatInVec vec0, floatInVec vec1)
295 {
296  return boolInVec(vec0.getAsFloat() < vec1.getAsFloat());
297 }
298 
299 inline
300 const boolInVec
301 operator <= (floatInVec vec0, floatInVec vec1)
302 {
303  return !(vec0 > vec1);
304 }
305 
306 inline
307 const boolInVec
308 operator > (floatInVec vec0, floatInVec vec1)
309 {
310  return boolInVec(vec0.getAsFloat() > vec1.getAsFloat());
311 }
312 
313 inline
314 const boolInVec
315 operator >= (floatInVec vec0, floatInVec vec1)
316 {
317  return !(vec0 < vec1);
318 }
319 
320 inline
321 const boolInVec
322 operator == (floatInVec vec0, floatInVec vec1)
323 {
324  return boolInVec(vec0.getAsFloat() == vec1.getAsFloat());
325 }
326 
327 inline
328 const boolInVec
329 operator != (floatInVec vec0, floatInVec vec1)
330 {
331  return !(vec0 == vec1);
332 }
333 
334 inline
335 const floatInVec
336 select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1)
337 {
338  return (select_vec1.getAsBool() == 0) ? vec0 : vec1;
339 }
340 
341 } // namespace Vectormath
342 
343 #endif // floatInVec_h
const boolInVec operator!=(boolInVec vec0, boolInVec vec1)
const floatInVec operator+(floatInVec vec0, floatInVec vec1)
const boolInVec operator<(floatInVec vec0, floatInVec vec1)
floatInVec & operator-=(floatInVec vec)
floatInVec & operator=(floatInVec vec)
const floatInVec operator*(floatInVec vec0, floatInVec vec1)
const boolInVec operator>=(floatInVec vec0, floatInVec vec1)
const floatInVec operator-() const
floatInVec & operator--()
const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1)
const boolInVec operator>(floatInVec vec0, floatInVec vec1)
floatInVec & operator++()
floatInVec & operator+=(floatInVec vec)
floatInVec & operator/=(floatInVec vec)
floatInVec & operator*=(floatInVec vec)
const boolInVec operator==(boolInVec vec0, boolInVec vec1)
float getAsFloat() const
const boolInVec operator<=(floatInVec vec0, floatInVec vec1)
const floatInVec operator/(floatInVec vec0, floatInVec vec1)
const floatInVec operator-(floatInVec vec0, floatInVec vec1)