| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 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 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class floatInVec |
| 31 |
{ |
| 32 |
private: |
| 33 |
float mData; |
| 34 |
|
| 35 |
public: |
| 36 |
|
| 37 |
|
| 38 |
inline floatInVec(){}; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
inline floatInVec(boolInVec vec); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
explicit inline floatInVec(float scalar); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
inline float getAsFloat() const; |
| 51 |
|
| 52 |
#ifndef _VECTORMATH_NO_SCALAR_CAST |
| 53 |
|
| 54 |
|
| 55 |
inline operator float() const; |
| 56 |
#endif |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
inline const floatInVec operator++(int); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
inline const floatInVec operator--(int); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
inline floatInVec& operator++(); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
inline floatInVec& operator--(); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
inline const floatInVec operator-() const; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
inline floatInVec& operator=(floatInVec vec); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
inline floatInVec& operator*=(floatInVec vec); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
inline floatInVec& operator/=(floatInVec vec); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
inline floatInVec& operator+=(floatInVec vec); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
inline floatInVec& operator-=(floatInVec vec); |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
inline const floatInVec operator*(floatInVec vec0, floatInVec vec1); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
inline const floatInVec operator/(floatInVec vec0, floatInVec vec1); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
inline const floatInVec operator+(floatInVec vec0, floatInVec vec1); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
inline const floatInVec operator-(floatInVec vec0, floatInVec vec1); |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
inline const boolInVec operator<(floatInVec vec0, floatInVec vec1); |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
inline const boolInVec operator<=(floatInVec vec0, floatInVec vec1); |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
inline const boolInVec operator>(floatInVec vec0, floatInVec vec1); |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
inline const boolInVec operator>=(floatInVec vec0, floatInVec vec1); |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
inline const boolInVec operator==(floatInVec vec0, floatInVec vec1); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
inline const boolInVec operator!=(floatInVec vec0, floatInVec vec1); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1); |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
#include "boolInVec.h" |
| 150 |
|
| 151 |
namespace Vectormath |
| 152 |
{ |
| 153 |
inline floatInVec::floatInVec(boolInVec vec) |
| 154 |
{ |
| 155 |
mData = float(vec.getAsBool()); |
| 156 |
} |
| 157 |
|
| 158 |
inline floatInVec::floatInVec(float scalar) |
| 159 |
{ |
| 160 |
mData = scalar; |
| 161 |
} |
| 162 |
|
| 163 |
inline float |
| 164 |
floatInVec::getAsFloat() const |
| 165 |
{ |
| 166 |
return mData; |
| 167 |
} |
| 168 |
|
| 169 |
#ifndef _VECTORMATH_NO_SCALAR_CAST |
| 170 |
inline floatInVec::operator float() const |
| 171 |
{ |
| 172 |
return getAsFloat(); |
| 173 |
} |
| 174 |
#endif |
| 175 |
|
| 176 |
inline const floatInVec |
| 177 |
floatInVec::operator++(int) |
| 178 |
{ |
| 179 |
float olddata = mData; |
| 180 |
operator++(); |
| 181 |
return floatInVec(olddata); |
| 182 |
} |
| 183 |
|
| 184 |
inline const floatInVec |
| 185 |
floatInVec::operator--(int) |
| 186 |
{ |
| 187 |
float olddata = mData; |
| 188 |
operator--(); |
| 189 |
return floatInVec(olddata); |
| 190 |
} |
| 191 |
|
| 192 |
inline floatInVec& |
| 193 |
floatInVec::operator++() |
| 194 |
{ |
| 195 |
*this += floatInVec(1.0f); |
| 196 |
return *this; |
| 197 |
} |
| 198 |
|
| 199 |
inline floatInVec& |
| 200 |
floatInVec::operator--() |
| 201 |
{ |
| 202 |
*this -= floatInVec(1.0f); |
| 203 |
return *this; |
| 204 |
} |
| 205 |
|
| 206 |
inline const floatInVec |
| 207 |
floatInVec::operator-() const |
| 208 |
{ |
| 209 |
return floatInVec(-mData); |
| 210 |
} |
| 211 |
|
| 212 |
inline floatInVec& |
| 213 |
floatInVec::operator=(floatInVec vec) |
| 214 |
{ |
| 215 |
mData = vec.mData; |
| 216 |
return *this; |
| 217 |
} |
| 218 |
|
| 219 |
inline floatInVec& |
| 220 |
floatInVec::operator*=(floatInVec vec) |
| 221 |
{ |
| 222 |
*this = *this * vec; |
| 223 |
return *this; |
| 224 |
} |
| 225 |
|
| 226 |
inline floatInVec& |
| 227 |
floatInVec::operator/=(floatInVec vec) |
| 228 |
{ |
| 229 |
*this = *this / vec; |
| 230 |
return *this; |
| 231 |
} |
| 232 |
|
| 233 |
inline floatInVec& |
| 234 |
floatInVec::operator+=(floatInVec vec) |
| 235 |
{ |
| 236 |
*this = *this + vec; |
| 237 |
return *this; |
| 238 |
} |
| 239 |
|
| 240 |
inline floatInVec& |
| 241 |
floatInVec::operator-=(floatInVec vec) |
| 242 |
{ |
| 243 |
*this = *this - vec; |
| 244 |
return *this; |
| 245 |
} |
| 246 |
|
| 247 |
inline const floatInVec |
| 248 |
operator*(floatInVec vec0, floatInVec vec1) |
| 249 |
{ |
| 250 |
return floatInVec(vec0.getAsFloat() * vec1.getAsFloat()); |
| 251 |
} |
| 252 |
|
| 253 |
inline const floatInVec |
| 254 |
operator/(floatInVec num, floatInVec den) |
| 255 |
{ |
| 256 |
return floatInVec(num.getAsFloat() / den.getAsFloat()); |
| 257 |
} |
| 258 |
|
| 259 |
inline const floatInVec |
| 260 |
operator+(floatInVec vec0, floatInVec vec1) |
| 261 |
{ |
| 262 |
return floatInVec(vec0.getAsFloat() + vec1.getAsFloat()); |
| 263 |
} |
| 264 |
|
| 265 |
inline const floatInVec |
| 266 |
operator-(floatInVec vec0, floatInVec vec1) |
| 267 |
{ |
| 268 |
return floatInVec(vec0.getAsFloat() - vec1.getAsFloat()); |
| 269 |
} |
| 270 |
|
| 271 |
inline const boolInVec |
| 272 |
operator<(floatInVec vec0, floatInVec vec1) |
| 273 |
{ |
| 274 |
return boolInVec(vec0.getAsFloat() < vec1.getAsFloat()); |
| 275 |
} |
| 276 |
|
| 277 |
inline const boolInVec |
| 278 |
operator<=(floatInVec vec0, floatInVec vec1) |
| 279 |
{ |
| 280 |
return !(vec0 > vec1); |
| 281 |
} |
| 282 |
|
| 283 |
inline const boolInVec |
| 284 |
operator>(floatInVec vec0, floatInVec vec1) |
| 285 |
{ |
| 286 |
return boolInVec(vec0.getAsFloat() > vec1.getAsFloat()); |
| 287 |
} |
| 288 |
|
| 289 |
inline const boolInVec |
| 290 |
operator>=(floatInVec vec0, floatInVec vec1) |
| 291 |
{ |
| 292 |
return !(vec0 < vec1); |
| 293 |
} |
| 294 |
|
| 295 |
inline const boolInVec |
| 296 |
operator==(floatInVec vec0, floatInVec vec1) |
| 297 |
{ |
| 298 |
return boolInVec(vec0.getAsFloat() == vec1.getAsFloat()); |
| 299 |
} |
| 300 |
|
| 301 |
inline const boolInVec |
| 302 |
operator!=(floatInVec vec0, floatInVec vec1) |
| 303 |
{ |
| 304 |
return !(vec0 == vec1); |
| 305 |
} |
| 306 |
|
| 307 |
inline const floatInVec |
| 308 |
select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1) |
| 309 |
{ |
| 310 |
return (select_vec1.getAsBool() == 0) ? vec0 : vec1; |
| 311 |
} |
| 312 |
|
| 313 |
} |
| 314 |
|
| 315 |
#endif |