Fixed the Vec*d class so there have value_type set to double.
This commit is contained in:
parent
4bb147aed4
commit
1f4417ab2b
@ -31,12 +31,12 @@ class Vec2d
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef float value_type;
|
typedef double value_type;
|
||||||
value_type _v[2];
|
value_type _v[2];
|
||||||
|
|
||||||
Vec2d() {_v[0]=0.0; _v[1]=0.0;}
|
Vec2d() {_v[0]=0.0; _v[1]=0.0;}
|
||||||
|
|
||||||
Vec2d(float x,float y) { _v[0]=x; _v[1]=y; }
|
Vec2d(value_type x,value_type y) { _v[0]=x; _v[1]=y; }
|
||||||
|
|
||||||
inline Vec2d(const Vec2f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; }
|
inline Vec2d(const Vec2f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; }
|
||||||
|
|
||||||
@ -54,19 +54,19 @@ class Vec2d
|
|||||||
else return (_v[1]<v._v[1]);
|
else return (_v[1]<v._v[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float* ptr() { return _v; }
|
inline value_type* ptr() { return _v; }
|
||||||
inline const float* ptr() const { return _v; }
|
inline const value_type* ptr() const { return _v; }
|
||||||
|
|
||||||
inline void set( float x, float y ) { _v[0]=x; _v[1]=y; }
|
inline void set( value_type x, value_type y ) { _v[0]=x; _v[1]=y; }
|
||||||
|
|
||||||
inline float& operator [] (int i) { return _v[i]; }
|
inline value_type& operator [] (int i) { return _v[i]; }
|
||||||
inline float operator [] (int i) const { return _v[i]; }
|
inline value_type operator [] (int i) const { return _v[i]; }
|
||||||
|
|
||||||
inline float& x() { return _v[0]; }
|
inline value_type& x() { return _v[0]; }
|
||||||
inline float& y() { return _v[1]; }
|
inline value_type& y() { return _v[1]; }
|
||||||
|
|
||||||
inline float x() const { return _v[0]; }
|
inline value_type x() const { return _v[0]; }
|
||||||
inline float y() const { return _v[1]; }
|
inline value_type y() const { return _v[1]; }
|
||||||
|
|
||||||
inline bool valid() const { return !isNaN(); }
|
inline bool valid() const { return !isNaN(); }
|
||||||
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
|
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
|
||||||
@ -78,13 +78,13 @@ class Vec2d
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// multiply by scalar
|
/// multiply by scalar
|
||||||
inline const Vec2d operator * (float rhs) const
|
inline const Vec2d operator * (value_type rhs) const
|
||||||
{
|
{
|
||||||
return Vec2d(_v[0]*rhs, _v[1]*rhs);
|
return Vec2d(_v[0]*rhs, _v[1]*rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// unary multiply by scalar
|
/// unary multiply by scalar
|
||||||
inline Vec2d& operator *= (float rhs)
|
inline Vec2d& operator *= (value_type rhs)
|
||||||
{
|
{
|
||||||
_v[0]*=rhs;
|
_v[0]*=rhs;
|
||||||
_v[1]*=rhs;
|
_v[1]*=rhs;
|
||||||
@ -92,13 +92,13 @@ class Vec2d
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// divide by scalar
|
/// divide by scalar
|
||||||
inline const Vec2d operator / (float rhs) const
|
inline const Vec2d operator / (value_type rhs) const
|
||||||
{
|
{
|
||||||
return Vec2d(_v[0]/rhs, _v[1]/rhs);
|
return Vec2d(_v[0]/rhs, _v[1]/rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// unary divide by scalar
|
/// unary divide by scalar
|
||||||
inline Vec2d& operator /= (float rhs)
|
inline Vec2d& operator /= (value_type rhs)
|
||||||
{
|
{
|
||||||
_v[0]/=rhs;
|
_v[0]/=rhs;
|
||||||
_v[1]/=rhs;
|
_v[1]/=rhs;
|
||||||
@ -154,12 +154,12 @@ class Vec2d
|
|||||||
|
|
||||||
/** normalize the vector so that it has length unity
|
/** normalize the vector so that it has length unity
|
||||||
returns the previous length of the vector*/
|
returns the previous length of the vector*/
|
||||||
inline float normalize()
|
inline value_type normalize()
|
||||||
{
|
{
|
||||||
float norm = Vec2d::length();
|
value_type norm = Vec2d::length();
|
||||||
if (norm>0.0)
|
if (norm>0.0)
|
||||||
{
|
{
|
||||||
float inv = 1.0/norm;
|
value_type inv = 1.0/norm;
|
||||||
_v[0] *= inv;
|
_v[0] *= inv;
|
||||||
_v[1] *= inv;
|
_v[1] *= inv;
|
||||||
}
|
}
|
||||||
|
@ -20,18 +20,18 @@
|
|||||||
|
|
||||||
namespace osg {
|
namespace osg {
|
||||||
|
|
||||||
/** General purpose float triple for use as vertices, vectors and normals.
|
/** General purpose double triple for use as vertices, vectors and normals.
|
||||||
Provides general maths operations from addition through to cross products.
|
Provides general maths operations from addition through to cross products.
|
||||||
No support yet added for float * Vec3d - is it necessary?
|
No support yet added for double * Vec3d - is it necessary?
|
||||||
Need to define a non-member non-friend operator* etc.
|
Need to define a non-member non-friend operator* etc.
|
||||||
Vec3d * float is okay
|
Vec3d * double is okay
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Vec3d
|
class Vec3d
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef float value_type;
|
typedef double value_type;
|
||||||
value_type _v[3];
|
value_type _v[3];
|
||||||
|
|
||||||
Vec3d() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0;}
|
Vec3d() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0;}
|
||||||
|
@ -19,17 +19,17 @@
|
|||||||
|
|
||||||
namespace osg {
|
namespace osg {
|
||||||
|
|
||||||
/** General purpose float quad, uses include representation
|
/** General purpose double quad, uses include representation
|
||||||
of colour coordinates.
|
of colour coordinates.
|
||||||
No support yet added for float * Vec4d - is it necessary?
|
No support yet added for double * Vec4d - is it necessary?
|
||||||
Need to define a non-member non-friend operator* etc.
|
Need to define a non-member non-friend operator* etc.
|
||||||
Vec4d * float is okay
|
Vec4d * double is okay
|
||||||
*/
|
*/
|
||||||
class Vec4d
|
class Vec4d
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef float value_type;
|
typedef double value_type;
|
||||||
|
|
||||||
value_type _v[4];
|
value_type _v[4];
|
||||||
|
|
||||||
@ -96,18 +96,18 @@ class Vec4d
|
|||||||
|
|
||||||
inline unsigned long asABGR() const
|
inline unsigned long asABGR() const
|
||||||
{
|
{
|
||||||
return (unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f)<<24 |
|
return (unsigned long)clampTo((_v[0]*255.0),0.0,255.0)<<24 |
|
||||||
(unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<16 |
|
(unsigned long)clampTo((_v[1]*255.0),0.0,255.0)<<16 |
|
||||||
(unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<8 |
|
(unsigned long)clampTo((_v[2]*255.0),0.0,255.0)<<8 |
|
||||||
(unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f);
|
(unsigned long)clampTo((_v[3]*255.0),0.0,255.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned long asRGBA() const
|
inline unsigned long asRGBA() const
|
||||||
{
|
{
|
||||||
return (unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f)<<24 |
|
return (unsigned long)clampTo((_v[3]*255.0),0.0,255.0)<<24 |
|
||||||
(unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<16 |
|
(unsigned long)clampTo((_v[2]*255.0),0.0,255.0)<<16 |
|
||||||
(unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<8 |
|
(unsigned long)clampTo((_v[1]*255.0),0.0,255.0)<<8 |
|
||||||
(unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f);
|
(unsigned long)clampTo((_v[0]*255.0),0.0,255.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool valid() const { return !isNaN(); }
|
inline bool valid() const { return !isNaN(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user