Added new template versions of a commonly used maths functions.
This commit is contained in:
parent
a9ef1ecb1d
commit
567989839a
@ -70,12 +70,29 @@ const double PI = 3.14159265358979323846;
|
||||
const double PI_2 = 1.57079632679489661923;
|
||||
const double PI_4 = 0.78539816339744830962;
|
||||
|
||||
template<typename T>
|
||||
inline T clampTo(T v,T minimum,T maximum) { return v<minimum?minimum:v>maximum?maximum:v; }
|
||||
|
||||
inline double inDegrees(double angle) { return angle*PI/180.0; }
|
||||
inline double inRadians(double angle) { return angle; }
|
||||
template<typename T>
|
||||
inline T sign(T v) { return v<0?-1:1; }
|
||||
|
||||
inline double DegreesToRadians(double angle) { return angle*PI/180.0; }
|
||||
inline double RadiansToDegrees(double angle) { return angle*180.0/PI; }
|
||||
template<typename T>
|
||||
inline T square(T v) { return v*v; }
|
||||
|
||||
template<typename T>
|
||||
inline T signedSquare(T v) { return v<0?-v*v:v*v;; }
|
||||
|
||||
template<typename T>
|
||||
inline T inDegrees(T angle) { return angle*PI/180.0; }
|
||||
|
||||
template<typename T>
|
||||
inline T inRadians(T angle) { return angle; }
|
||||
|
||||
template<typename T>
|
||||
inline T DegreesToRadians(T angle) { return angle*PI/180.0; }
|
||||
|
||||
template<typename T>
|
||||
inline T RadiansToDegrees(T angle) { return angle*180.0/PI; }
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MWERKS__)
|
||||
inline bool isNaN(float v) { return _isnan(v)!=0; }
|
||||
|
@ -67,6 +67,17 @@ class Vec4
|
||||
inline float z() const { return _v[2]; }
|
||||
inline float w() const { return _v[3]; }
|
||||
|
||||
inline unsigned long asABGR() const { return clampTo((unsigned long)(_v[0]*255),0ul,255ul)<<24 |
|
||||
clampTo((unsigned long)(_v[1]*255),0ul,255ul)<<16 |
|
||||
clampTo((unsigned long)(_v[2]*255),0ul,255ul)<<8 |
|
||||
clampTo((unsigned long)(_v[3]*255),0ul,255ul); }
|
||||
|
||||
inline unsigned long asRGBA() const { return clampTo((unsigned long)(_v[3]*255),0ul,255ul)<<24 |
|
||||
clampTo((unsigned long)(_v[2]*255),0ul,255ul)<<16 |
|
||||
clampTo((unsigned long)(_v[1]*255),0ul,255ul)<<8 |
|
||||
clampTo((unsigned long)(_v[0]*255),0ul,255ul); }
|
||||
|
||||
|
||||
inline const bool valid() const { return !isNaN(); }
|
||||
inline const bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]) || osg::isNaN(_v[2]) || osg::isNaN(_v[3]); }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user