Standardised the Vec* class interfaces, and added num_components enum to aid

generic programming.
This commit is contained in:
Robert Osfield
2005-09-04 11:17:00 +00:00
parent e404b95dc3
commit 14980872a7
14 changed files with 431 additions and 244 deletions

View File

@@ -28,6 +28,15 @@ class Vec2b
// Methods are defined here so that they are implicitly inlined
/** Type of Vec class.*/
typedef char value_type;
/** Number of vector components. */
enum { num_components = 2 };
/** Vec member varaible. */
value_type _v[2];
Vec2b() { _v[0]=0; _v[1]=0; }
Vec2b(char r, char g)
@@ -35,8 +44,6 @@ class Vec2b
_v[0]=r; _v[1]=g;
}
char _v[2];
inline bool operator == (const Vec2b& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Vec2b& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
@@ -48,22 +55,33 @@ class Vec2b
else return (_v[1]<v._v[1]);
}
inline char* ptr() { return _v; }
inline const char* ptr() const { return _v; }
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline void set(char r, char g)
inline void set( value_type x, value_type y)
{
_v[0]=r; _v[1]=g;
_v[0]=x; _v[1]=y;
}
inline char& operator [] (unsigned int i) { return _v[i]; }
inline char operator [] (unsigned int i) const { return _v[i]; }
inline void set( const Vec2b& rhs)
{
_v[0]=rhs._v[0]; _v[1]=rhs._v[1];
}
inline char& r() { return _v[0]; }
inline char& g() { return _v[1]; }
inline value_type& operator [] (int i) { return _v[i]; }
inline value_type operator [] (int i) const { return _v[i]; }
inline char r() const { return _v[0]; }
inline char g() const { return _v[1]; }
inline value_type& x() { return _v[0]; }
inline value_type& y() { return _v[1]; }
inline value_type x() const { return _v[0]; }
inline value_type y() const { return _v[1]; }
inline value_type& r() { return _v[0]; }
inline value_type& g() { return _v[1]; }
inline value_type r() const { return _v[0]; }
inline value_type g() const { return _v[1]; }
/** Multiply by scalar. */
inline Vec2b operator * (float rhs) const

View File

@@ -29,7 +29,13 @@ class Vec2d
{
public:
/** Type of Vec class.*/
typedef double value_type;
/** Number of vector components. */
enum { num_components = 2 };
/** Vec member varaible. */
value_type _v[2];
Vec2d() {_v[0]=0.0; _v[1]=0.0;}

View File

@@ -29,8 +29,15 @@ class Vec2f
{
public:
/** Type of Vec class.*/
typedef float value_type;
/** Number of vector components. */
enum { num_components = 2 };
/** Vec member varaible. */
value_type _v[2];
Vec2f() {_v[0]=0.0; _v[1]=0.0;}
Vec2f(value_type x,value_type y) { _v[0]=x; _v[1]=y; }

View File

@@ -18,65 +18,92 @@ namespace osg {
class Vec2s
{
public:
public:
typedef short value_type;
/** Type of Vec class.*/
typedef short value_type;
union
{
struct {value_type x,y;};
/** Number of vector components. */
enum { num_components = 2 };
/** Vec member varaible. */
value_type _v[2];
};
Vec2s() {}
Vec2s(value_type xx, value_type yy)
{ x = xx; y = yy; }
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline bool operator == (const Vec2s& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Vec2s& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Vec2s& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else return (_v[1]<v._v[1]);
}
inline Vec2s operator * (value_type rhs) const
{
return Vec2s(_v[0]*rhs, _v[1]*rhs);
}
inline Vec2s operator / (value_type rhs) const
{
return Vec2s(_v[0]/rhs, _v[1]/rhs);
}
inline Vec2s operator + (value_type rhs) const
{
return Vec2s(_v[0]+rhs, _v[1]+rhs);
}
inline Vec2s operator - (value_type rhs) const
{
return Vec2s(_v[0]-rhs, _v[1]-rhs);
}
inline Vec2s operator + (const Vec2s& rhs) const
{
return Vec2s(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
inline Vec2s operator - (const Vec2s& rhs) const
{
return Vec2s(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
inline Vec2s operator * (const Vec2s& rhs) const
{
return Vec2s(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);
}
Vec2s() { _v[0]=0; _v[1]=0; }
Vec2s(value_type x, value_type y) { _v[0] = x; _v[1] = y; }
inline bool operator == (const Vec2s& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Vec2s& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Vec2s& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else return (_v[1]<v._v[1]);
}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline void set( value_type x, value_type y)
{
_v[0]=x; _v[1]=y;
}
inline void set( const Vec2s& rhs)
{
_v[0]=rhs._v[0]; _v[1]=rhs._v[1];
}
inline value_type& operator [] (int i) { return _v[i]; }
inline value_type operator [] (int i) const { return _v[i]; }
inline value_type& x() { return _v[0]; }
inline value_type& y() { return _v[1]; }
inline value_type x() const { return _v[0]; }
inline value_type y() const { return _v[1]; }
inline value_type& r() { return _v[0]; }
inline value_type& g() { return _v[1]; }
inline value_type r() const { return _v[0]; }
inline value_type g() const { return _v[1]; }
inline Vec2s operator * (value_type rhs) const
{
return Vec2s(_v[0]*rhs, _v[1]*rhs);
}
inline Vec2s operator / (value_type rhs) const
{
return Vec2s(_v[0]/rhs, _v[1]/rhs);
}
inline Vec2s operator + (value_type rhs) const
{
return Vec2s(_v[0]+rhs, _v[1]+rhs);
}
inline Vec2s operator - (value_type rhs) const
{
return Vec2s(_v[0]-rhs, _v[1]-rhs);
}
inline Vec2s operator + (const Vec2s& rhs) const
{
return Vec2s(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
inline Vec2s operator - (const Vec2s& rhs) const
{
return Vec2s(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
inline Vec2s operator * (const Vec2s& rhs) const
{
return Vec2s(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);
}
};

View File

@@ -26,16 +26,18 @@ class Vec3b
{
public:
// Methods are defined here so that they are implicitly inlined
/** Type of Vec class.*/
typedef char value_type;
/** Number of vector components. */
enum { num_components = 3 };
/** Vec member varaible. */
value_type _v[3];
Vec3b() { _v[0]=0; _v[1]=0; _v[2]=0; }
Vec3b(char r, char g, char b)
{
_v[0]=r; _v[1]=g; _v[2]=b;
}
char _v[3];
Vec3b(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
inline bool operator == (const Vec3b& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
@@ -50,24 +52,37 @@ class Vec3b
else return (_v[2]<v._v[2]);
}
inline char* ptr() { return _v; }
inline const char* ptr() const { return _v; }
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline void set(char r, char g, char b)
inline void set(value_type r, value_type g, value_type b)
{
_v[0]=r; _v[1]=g; _v[2]=b;
}
inline char& operator [] (unsigned int i) { return _v[i]; }
inline char operator [] (unsigned int i) const { return _v[i]; }
inline void set( const Vec3b& rhs)
{
_v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
}
inline char& r() { return _v[0]; }
inline char& g() { return _v[1]; }
inline char& b() { return _v[2]; }
inline value_type& operator [] (unsigned int i) { return _v[i]; }
inline value_type operator [] (unsigned int i) const { return _v[i]; }
inline char r() const { return _v[0]; }
inline char g() const { return _v[1]; }
inline char b() const { return _v[2]; }
inline value_type& x() { return _v[0]; }
inline value_type& y() { return _v[1]; }
inline value_type& z() { return _v[2]; }
inline value_type x() const { return _v[0]; }
inline value_type y() const { return _v[1]; }
inline value_type z() const { return _v[2]; }
inline value_type& r() { return _v[0]; }
inline value_type& g() { return _v[1]; }
inline value_type& b() { return _v[2]; }
inline value_type r() const { return _v[0]; }
inline value_type g() const { return _v[1]; }
inline value_type b() const { return _v[2]; }
/** Multiply by scalar. */
inline Vec3b operator * (float rhs) const

View File

@@ -30,7 +30,13 @@ class Vec3d
{
public:
/** Type of Vec class.*/
typedef double value_type;
/** Number of vector components. */
enum { num_components = 3 };
/** Vec member varaible. */
value_type _v[3];
Vec3d() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0;}

View File

@@ -29,10 +29,16 @@ class Vec3f
{
public:
/** Type of Vec class.*/
typedef float value_type;
/** Number of vector components. */
enum { num_components = 3 };
/** Vec member varaible. */
value_type _v[3];
Vec3f() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0;}
Vec3f() { _v[0]=0.0f; _v[1]=0.0f; _v[2]=0.0f;}
Vec3f(value_type x,value_type y,value_type z) { _v[0]=x; _v[1]=y; _v[2]=z; }
Vec3f(const Vec2f& v2,value_type zz)
{

View File

@@ -18,68 +18,101 @@ namespace osg {
class Vec3s
{
public:
public:
typedef short value_type;
/** Type of Vec class.*/
typedef short value_type;
union
{
struct {value_type x,y,z;};
value_type _v[3];
};
Vec3s (){}
Vec3s (value_type xx, value_type yy, value_type zz)
{ x = xx; y = yy; z = zz;}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
/** Number of vector components. */
enum { num_components = 3 };
inline bool operator == (const Vec3s& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Vec3s& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Vec3s& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else if (_v[1]<v._v[1]) return true;
else if (_v[1]>v._v[1]) return false;
else return (_v[2]<v._v[2]);
}
inline Vec3s operator * (value_type rhs) const
{
return Vec3s(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
inline Vec3s operator / (value_type rhs) const
{
return Vec3s(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
inline Vec3s operator + (value_type rhs) const
{
return Vec3s(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs);
}
inline Vec3s operator - (value_type rhs) const
{
return Vec3s(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs);
}
inline Vec3s operator + (const Vec3s& rhs) const
{
return Vec3s(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
}
inline Vec3s operator - (const Vec3s& rhs) const
{
return Vec3s(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
inline Vec3s operator * (const Vec3s& rhs) const
{
return Vec3s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
}
/** Vec member varaible. */
value_type _v[3];
typedef short value_type;
Vec3s() { _v[0]=0; _v[1]=0; _v[2]=0; }
Vec3s(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
inline bool operator == (const Vec3s& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Vec3s& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Vec3s& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else if (_v[1]<v._v[1]) return true;
else if (_v[1]>v._v[1]) return false;
else return (_v[2]<v._v[2]);
}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline void set(value_type r, value_type g, value_type b)
{
_v[0]=r; _v[1]=g; _v[2]=b;
}
inline void set( const Vec3s& rhs)
{
_v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
}
inline value_type& operator [] (unsigned int i) { return _v[i]; }
inline value_type operator [] (unsigned int i) const { return _v[i]; }
inline value_type& x() { return _v[0]; }
inline value_type& y() { return _v[1]; }
inline value_type& z() { return _v[2]; }
inline value_type x() const { return _v[0]; }
inline value_type y() const { return _v[1]; }
inline value_type z() const { return _v[2]; }
inline value_type& r() { return _v[0]; }
inline value_type& g() { return _v[1]; }
inline value_type& b() { return _v[2]; }
inline value_type r() const { return _v[0]; }
inline value_type g() const { return _v[1]; }
inline value_type b() const { return _v[2]; }
/** Multiply by scalar. */
inline Vec3s operator * (value_type rhs) const
{
return Vec3s(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
inline Vec3s operator / (value_type rhs) const
{
return Vec3s(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
inline Vec3s operator + (value_type rhs) const
{
return Vec3s(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs);
}
inline Vec3s operator - (value_type rhs) const
{
return Vec3s(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs);
}
inline Vec3s operator + (const Vec3s& rhs) const
{
return Vec3s(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
}
inline Vec3s operator - (const Vec3s& rhs) const
{
return Vec3s(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
inline Vec3s operator * (const Vec3s& rhs) const
{
return Vec3s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
}
};
};

View File

@@ -26,16 +26,24 @@ class Vec4b
{
public:
// Methods are defined here so that they are implicitly inlined
/** Type of Vec class.*/
typedef char value_type;
/** Number of vector components. */
enum { num_components = 4 };
/** Vec member varaible. */
value_type _v[4];
Vec4b() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
Vec4b(char r, char g, char b, char a)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
}
char _v[4];
Vec4b(value_type x, value_type y, value_type z, value_type w)
{
_v[0]=x;
_v[1]=y;
_v[2]=z;
_v[3]=w;
}
inline bool operator == (const Vec4b& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
@@ -52,26 +60,36 @@ class Vec4b
else return (_v[3]<v._v[3]);
}
inline char* ptr() { return _v; }
inline const char* ptr() const { return _v; }
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline void set(char r, char g, char b, char a)
inline void set( value_type x, value_type y, value_type z, value_type w)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
_v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w;
}
inline char& operator [] (unsigned int i) { return _v[i]; }
inline char operator [] (unsigned int i) const { return _v[i]; }
inline value_type& operator [] (unsigned int i) { return _v[i]; }
inline value_type operator [] (unsigned int i) const { return _v[i]; }
inline char& r() { return _v[0]; }
inline char& g() { return _v[1]; }
inline char& b() { return _v[2]; }
inline char& a() { return _v[3]; }
inline value_type& x() { return _v[0]; }
inline value_type& y() { return _v[1]; }
inline value_type& z() { return _v[2]; }
inline value_type& w() { return _v[3]; }
inline char r() const { return _v[0]; }
inline char g() const { return _v[1]; }
inline char b() const { return _v[2]; }
inline char a() const { return _v[3]; }
inline value_type x() const { return _v[0]; }
inline value_type y() const { return _v[1]; }
inline value_type z() const { return _v[2]; }
inline value_type w() const { return _v[3]; }
inline value_type& r() { return _v[0]; }
inline value_type& g() { return _v[1]; }
inline value_type& b() { return _v[2]; }
inline value_type& a() { return _v[3]; }
inline value_type r() const { return _v[0]; }
inline value_type g() const { return _v[1]; }
inline value_type b() const { return _v[2]; }
inline value_type a() const { return _v[3]; }
/** Multiply by scalar. */
inline Vec4b operator * (float rhs) const

View File

@@ -29,14 +29,17 @@ class Vec4d
{
public:
/** Type of Vec class.*/
typedef double value_type;
/** Number of vector components. */
enum { num_components = 4 };
/** Vec member varaible. */
value_type _v[4];
// Methods are defined here so that they are implicitly inlined
Vec4d() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=0.0; }
Vec4d() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=0.0;}
Vec4d(value_type x, value_type y, value_type z, value_type w)
{
_v[0]=x;

View File

@@ -28,13 +28,18 @@ class Vec4f
{
public:
/** Type of Vec class.*/
typedef float value_type;
/** Number of vector components. */
enum { num_components = 4 };
/** Vec member varaible. */
value_type _v[4];
// Methods are defined here so that they are implicitly inlined
Vec4f() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=0.0;}
Vec4f() { _v[0]=0.0f; _v[1]=0.0f; _v[2]=0.0f; _v[3]=0.0f;}
Vec4f(value_type x, value_type y, value_type z, value_type w)
{

View File

@@ -18,70 +18,105 @@ namespace osg {
class Vec4s
{
public:
public:
typedef short value_type;
/** Type of Vec class.*/
typedef short value_type;
union
{
struct {value_type x,y,z,w;};
/** Number of vector components. */
enum { num_components = 4 };
/** Vec member varaible. */
value_type _v[4];
};
Vec4s (){}
Vec4s (value_type xx, value_type yy, value_type zz, value_type ww)
{x = xx; y = yy; z = zz; w = ww;}
Vec4s() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
Vec4s(value_type x, value_type y, value_type z, value_type w)
{
_v[0]=x;
_v[1]=y;
_v[2]=z;
_v[3]=w;
}
inline bool operator == (const Vec4s& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
inline bool operator != (const Vec4s& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
inline bool operator < (const Vec4s& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else if (_v[1]<v._v[1]) return true;
else if (_v[1]>v._v[1]) return false;
else if (_v[2]<v._v[2]) return true;
else if (_v[2]>v._v[2]) return false;
else return (_v[3]<v._v[3]);
}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline bool operator == (const Vec4s& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
inline bool operator != (const Vec4s& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
inline bool operator < (const Vec4s& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else if (_v[1]<v._v[1]) return true;
else if (_v[1]>v._v[1]) return false;
else if (_v[2]<v._v[2]) return true;
else if (_v[2]>v._v[2]) return false;
else return (_v[3]<v._v[3]);
}
inline Vec4s operator * (value_type rhs) const
{
return Vec4s(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
inline Vec4s operator / (value_type rhs) const
{
return Vec4s(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
inline Vec4s operator + (value_type rhs) const
{
return Vec4s(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs, _v[3]+rhs);
}
inline Vec4s operator - (value_type rhs) const
{
return Vec4s(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs, _v[3]-rhs);
}
inline Vec4s operator + (const Vec4s& rhs) const
{
return Vec4s(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
inline Vec4s operator - (const Vec4s& rhs) const
{
return Vec4s(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2], _v[3]-rhs._v[3]);
}
inline Vec4s operator * (const Vec4s& rhs) const
{
return Vec4s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
}
inline const value_type* ptr() const { return _v; }
inline void set( value_type x, value_type y, value_type z, value_type w)
{
_v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w;
}
inline value_type& operator [] (unsigned int i) { return _v[i]; }
inline value_type operator [] (unsigned int i) const { return _v[i]; }
inline value_type& x() { return _v[0]; }
inline value_type& y() { return _v[1]; }
inline value_type& z() { return _v[2]; }
inline value_type& w() { return _v[3]; }
inline value_type x() const { return _v[0]; }
inline value_type y() const { return _v[1]; }
inline value_type z() const { return _v[2]; }
inline value_type w() const { return _v[3]; }
inline value_type& r() { return _v[0]; }
inline value_type& g() { return _v[1]; }
inline value_type& b() { return _v[2]; }
inline value_type& a() { return _v[3]; }
inline value_type r() const { return _v[0]; }
inline value_type g() const { return _v[1]; }
inline value_type b() const { return _v[2]; }
inline value_type a() const { return _v[3]; }
inline Vec4s operator * (value_type rhs) const
{
return Vec4s(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
inline Vec4s operator / (value_type rhs) const
{
return Vec4s(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
inline Vec4s operator + (value_type rhs) const
{
return Vec4s(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs, _v[3]+rhs);
}
inline Vec4s operator - (value_type rhs) const
{
return Vec4s(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs, _v[3]-rhs);
}
inline Vec4s operator + (const Vec4s& rhs) const
{
return Vec4s(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
inline Vec4s operator - (const Vec4s& rhs) const
{
return Vec4s(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2], _v[3]-rhs._v[3]);
}
inline Vec4s operator * (const Vec4s& rhs) const
{
return Vec4s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
}
};
};

View File

@@ -28,16 +28,24 @@ class Vec4ub
{
public:
// Methods are defined here so that they are implicitly inlined
/** Type of Vec class.*/
typedef unsigned char value_type;
Vec4ub() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0;}
/** Number of vector components. */
enum { num_components = 4 };
Vec4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
}
/** Vec member varaible. */
value_type _v[4];
unsigned char _v[4];
Vec4ub() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
Vec4ub(value_type x, value_type y, value_type z, value_type w)
{
_v[0]=x;
_v[1]=y;
_v[2]=z;
_v[3]=w;
}
inline bool operator == (const Vec4ub& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }

View File

@@ -490,8 +490,8 @@ void DataOutputStream::writeVec2sArray(const osg::Vec2sArray* a)
int size = a->getNumElements();
writeInt(size);
for(int i =0; i<size ;i++){
writeShort((*a)[i].x);
writeShort((*a)[i].y);
writeShort((*a)[i].x());
writeShort((*a)[i].y());
}
if (_verboseOutput) std::cout<<"read/writeVec2sArray() ["<<size<<"]"<<std::endl;
@@ -502,9 +502,9 @@ void DataOutputStream::writeVec3sArray(const osg::Vec3sArray* a)
int size = a->getNumElements();
writeInt(size);
for(int i =0; i<size ;i++){
writeShort((*a)[i].x);
writeShort((*a)[i].y);
writeShort((*a)[i].z);
writeShort((*a)[i].x());
writeShort((*a)[i].y());
writeShort((*a)[i].z());
}
if (_verboseOutput) std::cout<<"read/writeVec3sArray() ["<<size<<"]"<<std::endl;
@@ -515,10 +515,10 @@ void DataOutputStream::writeVec4sArray(const osg::Vec4sArray* a)
int size = a->getNumElements();
writeInt(size);
for(int i =0; i<size ;i++){
writeShort((*a)[i].x);
writeShort((*a)[i].y);
writeShort((*a)[i].z);
writeShort((*a)[i].w);
writeShort((*a)[i].x());
writeShort((*a)[i].y());
writeShort((*a)[i].z());
writeShort((*a)[i].w());
}
if (_verboseOutput) std::cout<<"read/writeVec4sArray() ["<<size<<"]"<<std::endl;