Renamed Byte2,3,4 and Short2,3,4 and UByte4 to use the Vec*b, Vec*s and Vec4ub form

This commit is contained in:
Robert Osfield
2005-07-15 14:41:19 +00:00
parent 0c7f228224
commit d35ea68f3e
28 changed files with 594 additions and 549 deletions

View File

@@ -19,13 +19,13 @@
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/UByte4>
#include <osg/Short2>
#include <osg/Short3>
#include <osg/Short4>
#include <osg/Byte2>
#include <osg/Byte3>
#include <osg/Byte4>
#include <osg/Vec4ub>
#include <osg/Vec2s>
#include <osg/Vec3s>
#include <osg/Vec4s>
#include <osg/Vec2b>
#include <osg/Vec3b>
#include <osg/Vec4b>
#include <osg/Object>
@@ -53,17 +53,17 @@ class OSG_EXPORT Array : public Object
UByteArrayType = 4,
UShortArrayType = 5,
UIntArrayType = 6,
UByte4ArrayType = 7,
Vec4ubArrayType = 7,
FloatArrayType = 8,
Vec2ArrayType = 9,
Vec3ArrayType = 10,
Vec4ArrayType = 11,
Short2ArrayType = 12,
Short3ArrayType = 13,
Short4ArrayType = 14,
Byte2ArrayType = 15,
Byte3ArrayType = 16,
Byte4ArrayType = 17
Vec2sArrayType = 12,
Vec3sArrayType = 13,
Vec4sArrayType = 14,
Vec2bArrayType = 15,
Vec3bArrayType = 16,
Vec4bArrayType = 17
};
@@ -266,17 +266,24 @@ typedef TemplateIndexArray<GLushort,Array::UShortArrayType,1,GL_UNSIGNED_SHORT>
typedef TemplateIndexArray<GLuint,Array::UIntArrayType,1,GL_UNSIGNED_INT> UIntArray;
typedef TemplateArray<GLfloat,Array::FloatArrayType,1,GL_FLOAT> FloatArray;
typedef TemplateArray<UByte4,Array::UByte4ArrayType,4,GL_UNSIGNED_BYTE> UByte4Array;
typedef TemplateArray<Vec2,Array::Vec2ArrayType,2,GL_FLOAT> Vec2Array;
typedef TemplateArray<Vec3,Array::Vec3ArrayType,3,GL_FLOAT> Vec3Array;
typedef TemplateArray<Vec4,Array::Vec4ArrayType,4,GL_FLOAT> Vec4Array;
typedef TemplateArray<Short2,Array::Short2ArrayType,2,GL_SHORT> Short2Array;
typedef TemplateArray<Short3,Array::Short3ArrayType,3,GL_SHORT> Short3Array;
typedef TemplateArray<Short4,Array::Short4ArrayType,4,GL_SHORT> Short4Array;
typedef TemplateArray<Byte2,Array::Byte2ArrayType,2,GL_BYTE> Byte2Array;
typedef TemplateArray<Byte3,Array::Byte3ArrayType,3,GL_BYTE> Byte3Array;
typedef TemplateArray<Byte4,Array::Byte4ArrayType,4,GL_BYTE> Byte4Array;
typedef TemplateArray<Vec4ub,Array::Vec4ubArrayType,4,GL_UNSIGNED_BYTE> Vec4ubArray;
#ifdef USE_DEPRECATED_API
typedef Vec4ubArray UByte4Array;
#endif
typedef TemplateArray<Vec2s,Array::Vec2sArrayType,2,GL_SHORT> Vec2sArray;
typedef TemplateArray<Vec3s,Array::Vec3sArrayType,3,GL_SHORT> Vec3sArray;
typedef TemplateArray<Vec4s,Array::Vec4sArrayType,4,GL_SHORT> Vec4sArray;
typedef TemplateArray<Vec2b,Array::Vec2bArrayType,2,GL_BYTE> Vec2bArray;
typedef TemplateArray<Vec3b,Array::Vec3bArrayType,3,GL_BYTE> Vec3bArray;
typedef TemplateArray<Vec4b,Array::Vec4bArrayType,4,GL_BYTE> Vec4bArray;
class ArrayVisitor
@@ -291,18 +298,21 @@ class ArrayVisitor
virtual void apply(UByteArray&) {}
virtual void apply(UShortArray&) {}
virtual void apply(UIntArray&) {}
virtual void apply(UByte4Array&) {}
virtual void apply(FloatArray&) {}
virtual void apply(Vec2Array&) {}
virtual void apply(Vec3Array&) {}
virtual void apply(Vec4Array&) {}
virtual void apply(Short2Array&) {}
virtual void apply(Short3Array&) {}
virtual void apply(Short4Array&) {}
virtual void apply(Byte2Array&) {}
virtual void apply(Byte3Array&) {}
virtual void apply(Byte4Array&) {}
virtual void apply(Vec2sArray&) {}
virtual void apply(Vec3sArray&) {}
virtual void apply(Vec4sArray&) {}
virtual void apply(Vec2bArray&) {}
virtual void apply(Vec3bArray&) {}
virtual void apply(Vec4bArray&) {}
virtual void apply(Vec4ubArray&) {}
};
class ConstArrayVisitor
@@ -317,18 +327,21 @@ class ConstArrayVisitor
virtual void apply(const UByteArray&) {}
virtual void apply(const UShortArray&) {}
virtual void apply(const UIntArray&) {}
virtual void apply(const UByte4Array&) {}
virtual void apply(const FloatArray&) {}
virtual void apply(const Vec2Array&) {}
virtual void apply(const Vec3Array&) {}
virtual void apply(const Vec4Array&) {}
virtual void apply(const Short2Array&) {}
virtual void apply(const Short3Array&) {}
virtual void apply(const Short4Array&) {}
virtual void apply(const Byte2Array&) {}
virtual void apply(const Byte3Array&) {}
virtual void apply(const Byte4Array&) {}
virtual void apply(const Vec4ubArray&) {}
virtual void apply(const Vec2bArray&) {}
virtual void apply(const Vec3bArray&) {}
virtual void apply(const Vec4bArray&) {}
virtual void apply(const Vec2sArray&) {}
virtual void apply(const Vec3sArray&) {}
virtual void apply(const Vec4sArray&) {}
};
@@ -344,17 +357,20 @@ class ValueVisitor
virtual void apply(GLubyte&) {}
virtual void apply(GLuint&) {}
virtual void apply(GLfloat&) {}
virtual void apply(UByte4&) {}
virtual void apply(Vec4ub&) {}
virtual void apply(Vec2&) {}
virtual void apply(Vec3&) {}
virtual void apply(Vec4&) {}
virtual void apply(Short2&) {}
virtual void apply(Short3&) {}
virtual void apply(Short4&) {}
virtual void apply(Byte2&) {}
virtual void apply(Byte3&) {}
virtual void apply(Byte4&) {}
virtual void apply(Vec2s&) {}
virtual void apply(Vec3s&) {}
virtual void apply(Vec4s&) {}
virtual void apply(Vec2b&) {}
virtual void apply(Vec3b&) {}
virtual void apply(Vec4b&) {}
};
class ConstValueVisitor
@@ -369,17 +385,19 @@ class ConstValueVisitor
virtual void apply(const GLubyte&) {}
virtual void apply(const GLuint&) {}
virtual void apply(const GLfloat&) {}
virtual void apply(const UByte4&) {}
virtual void apply(const Vec4ub&) {}
virtual void apply(const Vec2&) {}
virtual void apply(const Vec3&) {}
virtual void apply(const Vec4&) {}
virtual void apply(const Short2&) {}
virtual void apply(const Short3&) {}
virtual void apply(const Short4&) {}
virtual void apply(const Byte2&) {}
virtual void apply(const Byte3&) {}
virtual void apply(const Byte4&) {}
virtual void apply(const Vec2s&) {}
virtual void apply(const Vec3s&) {}
virtual void apply(const Vec4s&) {}
virtual void apply(const Vec2b&) {}
virtual void apply(const Vec3b&) {}
virtual void apply(const Vec4b&) {}
};
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>

View File

@@ -49,7 +49,7 @@ namespace osg {
class Vec2f;
class Vec3f;
class Vec4f;
class UByte4;
class Vec4ub;
class Geometry;
class NodeVisitor;
@@ -467,7 +467,7 @@ class OSG_EXPORT Drawable : public Object
virtual void apply(AttributeType,unsigned int,Vec2*) {}
virtual void apply(AttributeType,unsigned int,Vec3*) {}
virtual void apply(AttributeType,unsigned int,Vec4*) {}
virtual void apply(AttributeType,unsigned int,UByte4*) {}
virtual void apply(AttributeType,unsigned int,Vec4ub*) {}
};
@@ -498,7 +498,7 @@ class OSG_EXPORT Drawable : public Object
virtual void apply(AttributeType,const unsigned int,const Vec2*) {}
virtual void apply(AttributeType,const unsigned int,const Vec3*) {}
virtual void apply(AttributeType,const unsigned int,const Vec4*) {}
virtual void apply(AttributeType,const unsigned int,const UByte4*) {}
virtual void apply(AttributeType,const unsigned int,const Vec4ub*) {}
};
/** Return true if the Drawable subclass supports accept(ConstAttributeFunctor&).*/

View File

@@ -14,138 +14,13 @@
#ifndef OSG_UBYTE4
#define OSG_UBYTE4 1
#include <osg/Vec3>
#include <osg/Vec4ub>
namespace osg {
/** General purpose float quad.
* Uses include representation of color coordinates.
* No support yet added for float * UByte4 - is it necessary?
* Need to define a non-member non-friend operator* etc.
* UByte4 * float is okay
*/
class UByte4
{
public:
// Methods are defined here so that they are implicitly inlined
UByte4() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0;}
UByte4(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
}
unsigned char _v[4];
inline bool operator == (const UByte4& 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 UByte4& 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 UByte4& 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 unsigned char* ptr() { return _v; }
inline const unsigned char* ptr() const { return _v; }
inline void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
}
inline unsigned char& operator [] (unsigned int i) { return _v[i]; }
inline unsigned char operator [] (unsigned int i) const { return _v[i]; }
inline unsigned char& r() { return _v[0]; }
inline unsigned char& g() { return _v[1]; }
inline unsigned char& b() { return _v[2]; }
inline unsigned char& a() { return _v[3]; }
inline unsigned char r() const { return _v[0]; }
inline unsigned char g() const { return _v[1]; }
inline unsigned char b() const { return _v[2]; }
inline unsigned char a() const { return _v[3]; }
/** Multiply by scalar. */
inline UByte4 operator * (float rhs) const
{
UByte4 col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline UByte4& operator *= (float rhs)
{
_v[0]=(unsigned char)((float)_v[0]*rhs);
_v[1]=(unsigned char)((float)_v[1]*rhs);
_v[2]=(unsigned char)((float)_v[2]*rhs);
_v[3]=(unsigned char)((float)_v[3]*rhs);
return *this;
}
/** Divide by scalar. */
inline UByte4 operator / (float rhs) const
{
UByte4 col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline UByte4& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline UByte4 operator + (const UByte4& rhs) const
{
return UByte4(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
/** Unary vector add. Slightly more efficient because no temporary
* intermediate object.
*/
inline UByte4& operator += (const UByte4& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
_v[3] += rhs._v[3];
return *this;
}
/** Binary vector subtract. */
inline UByte4 operator - (const UByte4& rhs) const
{
return UByte4(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2], _v[3]-rhs._v[3] );
}
/** Unary vector subtract. */
inline UByte4& operator -= (const UByte4& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
_v[3]-=rhs._v[3];
return *this;
}
}; // end of class UByte4
#ifdef USE_DEPRECATED_API
typedef UByte4 Vec4ub;
#endif
} // end of namespace osg

View File

@@ -11,37 +11,37 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BYTE2
#define OSG_BYTE2 1
#ifndef OSG_VEC2B
#define OSG_VEC2B 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Byte2 - is it necessary?
* No support yet added for float * Vec2b - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Byte2 * float is okay
* Vec2b * float is okay
*/
class Byte2
class Vec2b
{
public:
// Methods are defined here so that they are implicitly inlined
Byte2() { _v[0]=0; _v[1]=0; }
Vec2b() { _v[0]=0; _v[1]=0; }
Byte2(char r, char g)
Vec2b(char r, char g)
{
_v[0]=r; _v[1]=g;
}
char _v[2];
inline bool operator == (const Byte2& 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]; }
inline bool operator != (const Byte2& 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]; }
inline bool operator < (const Byte2& v) const
inline bool operator < (const Vec2b& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
@@ -66,15 +66,15 @@ class Byte2
inline char g() const { return _v[1]; }
/** Multiply by scalar. */
inline Byte2 operator * (float rhs) const
inline Vec2b operator * (float rhs) const
{
Byte2 col(*this);
Vec2b col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Byte2& operator *= (float rhs)
inline Vec2b& operator *= (float rhs)
{
_v[0]=(char)((float)_v[0]*rhs);
_v[1]=(char)((float)_v[1]*rhs);
@@ -82,15 +82,15 @@ class Byte2
}
/** Divide by scalar. */
inline Byte2 operator / (float rhs) const
inline Vec2b operator / (float rhs) const
{
Byte2 col(*this);
Vec2b col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Byte2& operator /= (float rhs)
inline Vec2b& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
@@ -98,15 +98,15 @@ class Byte2
}
/** Binary vector add. */
inline Byte2 operator + (const Byte2& rhs) const
inline Vec2b operator + (const Vec2b& rhs) const
{
return Byte2(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
return Vec2b(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
/** Unary vector add. Slightly more efficient because no temporary
* intermediate object.
*/
inline Byte2& operator += (const Byte2& rhs)
inline Vec2b& operator += (const Vec2b& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
@@ -114,20 +114,20 @@ class Byte2
}
/** Binary vector subtract. */
inline Byte2 operator - (const Byte2& rhs) const
inline Vec2b operator - (const Vec2b& rhs) const
{
return Byte2(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
return Vec2b(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
/** Unary vector subtract. */
inline Byte2& operator -= (const Byte2& rhs)
inline Vec2b& operator -= (const Vec2b& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
return *this;
}
}; // end of class Byte2
}; // end of class Vec2b

View File

@@ -11,12 +11,12 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_SHORT_2
#define OSG_SHORT_2 1
#ifndef OSG_VEC2S
#define OSG_VEC2S 1
namespace osg {
class Short2
class Vec2s
{
public:
@@ -27,55 +27,55 @@ public:
struct {value_type x,y;};
value_type _v[2];
};
Short2() {}
Short2(value_type xx, value_type yy)
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 Short2& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Short2& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Short2& v) const
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 Short2 operator * (value_type rhs) const
inline Vec2s operator * (value_type rhs) const
{
return Short2(_v[0]*rhs, _v[1]*rhs);
return Vec2s(_v[0]*rhs, _v[1]*rhs);
}
inline Short2 operator / (value_type rhs) const
inline Vec2s operator / (value_type rhs) const
{
return Short2(_v[0]/rhs, _v[1]/rhs);
return Vec2s(_v[0]/rhs, _v[1]/rhs);
}
inline Short2 operator + (value_type rhs) const
inline Vec2s operator + (value_type rhs) const
{
return Short2(_v[0]+rhs, _v[1]+rhs);
return Vec2s(_v[0]+rhs, _v[1]+rhs);
}
inline Short2 operator - (value_type rhs) const
inline Vec2s operator - (value_type rhs) const
{
return Short2(_v[0]-rhs, _v[1]-rhs);
return Vec2s(_v[0]-rhs, _v[1]-rhs);
}
inline Short2 operator + (const Short2& rhs) const
inline Vec2s operator + (const Vec2s& rhs) const
{
return Short2(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
return Vec2s(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
inline Short2 operator - (const Short2& rhs) const
inline Vec2s operator - (const Vec2s& rhs) const
{
return Short2(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
return Vec2s(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
inline Short2 operator * (const Short2& rhs) const
inline Vec2s operator * (const Vec2s& rhs) const
{
return Short2(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);
return Vec2s(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);
}
};

View File

@@ -11,37 +11,37 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BYTE3
#define OSG_BYTE3 1
#ifndef OSG_VEC3B
#define OSG_VEC3B 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Byte3 - is it necessary?
* No support yet added for float * Vec3b - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Byte3 * float is okay
* Vec3b * float is okay
*/
class Byte3
class Vec3b
{
public:
// Methods are defined here so that they are implicitly inlined
Byte3() { _v[0]=0; _v[1]=0; _v[2]=0; }
Vec3b() { _v[0]=0; _v[1]=0; _v[2]=0; }
Byte3(char r, char g, char b)
Vec3b(char r, char g, char b)
{
_v[0]=r; _v[1]=g; _v[2]=b;
}
char _v[3];
inline bool operator == (const Byte3& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator == (const Vec3b& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Byte3& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator != (const Vec3b& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Byte3& v) const
inline bool operator < (const Vec3b& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
@@ -70,15 +70,15 @@ class Byte3
inline char b() const { return _v[2]; }
/** Multiply by scalar. */
inline Byte3 operator * (float rhs) const
inline Vec3b operator * (float rhs) const
{
Byte3 col(*this);
Vec3b col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Byte3& operator *= (float rhs)
inline Vec3b& operator *= (float rhs)
{
_v[0]=(char)((float)_v[0]*rhs);
_v[1]=(char)((float)_v[1]*rhs);
@@ -87,15 +87,15 @@ class Byte3
}
/** Divide by scalar. */
inline Byte3 operator / (float rhs) const
inline Vec3b operator / (float rhs) const
{
Byte3 col(*this);
Vec3b col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Byte3& operator /= (float rhs)
inline Vec3b& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
@@ -103,16 +103,16 @@ class Byte3
}
/** Binary vector add. */
inline Byte3 operator + (const Byte3& rhs) const
inline Vec3b operator + (const Vec3b& rhs) const
{
return Byte3(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
return Vec3b(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2]);
}
/** Unary vector add. Slightly more efficient because no temporary
* intermediate object.
*/
inline Byte3& operator += (const Byte3& rhs)
inline Vec3b& operator += (const Vec3b& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
@@ -121,14 +121,14 @@ class Byte3
}
/** Binary vector subtract. */
inline Byte3 operator - (const Byte3& rhs) const
inline Vec3b operator - (const Vec3b& rhs) const
{
return Byte3(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
return Vec3b(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2]);
}
/** Unary vector subtract. */
inline Byte3& operator -= (const Byte3& rhs)
inline Vec3b& operator -= (const Vec3b& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
@@ -136,7 +136,7 @@ class Byte3
return *this;
}
}; // end of class Byte3
}; // end of class Vec3b

View File

@@ -11,12 +11,12 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_SHORT_3
#define OSG_SHORT_3 1
#ifndef OSG_VEC3S
#define OSG_VEC3S 1
namespace osg {
class Short3
class Vec3s
{
public:
@@ -28,16 +28,16 @@ public:
value_type _v[3];
};
Short3 (){}
Short3 (value_type xx, value_type yy, value_type zz)
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; }
inline bool operator == (const Short3& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Short3& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Short3& v) const
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;
@@ -46,39 +46,39 @@ public:
else return (_v[2]<v._v[2]);
}
inline Short3 operator * (value_type rhs) const
inline Vec3s operator * (value_type rhs) const
{
return Short3(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
return Vec3s(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
inline Short3 operator / (value_type rhs) const
inline Vec3s operator / (value_type rhs) const
{
return Short3(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
return Vec3s(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
inline Short3 operator + (value_type rhs) const
inline Vec3s operator + (value_type rhs) const
{
return Short3(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs);
return Vec3s(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs);
}
inline Short3 operator - (value_type rhs) const
inline Vec3s operator - (value_type rhs) const
{
return Short3(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs);
return Vec3s(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs);
}
inline Short3 operator + (const Short3& rhs) const
inline Vec3s operator + (const Vec3s& rhs) const
{
return Short3(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
return Vec3s(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
}
inline Short3 operator - (const Short3& rhs) const
inline Vec3s operator - (const Vec3s& rhs) const
{
return Short3(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
return Vec3s(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
inline Short3 operator * (const Short3& rhs) const
inline Vec3s operator * (const Vec3s& rhs) const
{
return Short3(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
return Vec3s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
}
};

View File

@@ -11,37 +11,37 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BYTE4
#define OSG_BYTE4 1
#ifndef OSG_VEC4B
#define OSG_VEC4B 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Byte4 - is it necessary?
* No support yet added for float * Vec4b - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Byte4 * float is okay
* Vec4b * float is okay
*/
class Byte4
class Vec4b
{
public:
// Methods are defined here so that they are implicitly inlined
Byte4() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
Vec4b() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
Byte4(char r, char g, char b, char a)
Vec4b(char r, char g, char b, char a)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
}
char _v[4];
inline bool operator == (const Byte4& 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 Vec4b& 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 Byte4& 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 Vec4b& 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 Byte4& v) const
inline bool operator < (const Vec4b& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
@@ -74,15 +74,15 @@ class Byte4
inline char a() const { return _v[3]; }
/** Multiply by scalar. */
inline Byte4 operator * (float rhs) const
inline Vec4b operator * (float rhs) const
{
Byte4 col(*this);
Vec4b col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Byte4& operator *= (float rhs)
inline Vec4b& operator *= (float rhs)
{
_v[0]=(char)((float)_v[0]*rhs);
_v[1]=(char)((float)_v[1]*rhs);
@@ -92,15 +92,15 @@ class Byte4
}
/** Divide by scalar. */
inline Byte4 operator / (float rhs) const
inline Vec4b operator / (float rhs) const
{
Byte4 col(*this);
Vec4b col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Byte4& operator /= (float rhs)
inline Vec4b& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
@@ -108,16 +108,16 @@ class Byte4
}
/** Binary vector add. */
inline Byte4 operator + (const Byte4& rhs) const
inline Vec4b operator + (const Vec4b& rhs) const
{
return Byte4(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
return Vec4b(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
/** Unary vector add. Slightly more efficient because no temporary
* intermediate object.
*/
inline Byte4& operator += (const Byte4& rhs)
inline Vec4b& operator += (const Vec4b& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
@@ -127,14 +127,14 @@ class Byte4
}
/** Binary vector subtract. */
inline Byte4 operator - (const Byte4& rhs) const
inline Vec4b operator - (const Vec4b& rhs) const
{
return Byte4(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
return Vec4b(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2], _v[3]-rhs._v[3]);
}
/** Unary vector subtract. */
inline Byte4& operator -= (const Byte4& rhs)
inline Vec4b& operator -= (const Vec4b& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
@@ -143,7 +143,7 @@ class Byte4
return *this;
}
}; // end of class Byte4
}; // end of class Vec4b

View File

@@ -11,12 +11,12 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_SHORT_4
#define OSG_SHORT_4 1
#ifndef OSG_VEC4S
#define OSG_VEC4S 1
namespace osg {
class Short4
class Vec4s
{
public:
@@ -28,16 +28,16 @@ public:
value_type _v[4];
};
Short4 (){}
Short4 (value_type xx, value_type yy, value_type zz, value_type ww)
Vec4s (){}
Vec4s (value_type xx, value_type yy, value_type zz, value_type ww)
{x = xx; y = yy; z = zz; w = ww;}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline bool operator == (const Short4& 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 Short4& 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 Short4& v) const
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;
@@ -48,39 +48,39 @@ public:
else return (_v[3]<v._v[3]);
}
inline Short4 operator * (value_type rhs) const
inline Vec4s operator * (value_type rhs) const
{
return Short4(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
return Vec4s(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
inline Short4 operator / (value_type rhs) const
inline Vec4s operator / (value_type rhs) const
{
return Short4(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
return Vec4s(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
inline Short4 operator + (value_type rhs) const
inline Vec4s operator + (value_type rhs) const
{
return Short4(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs, _v[3]+rhs);
return Vec4s(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs, _v[3]+rhs);
}
inline Short4 operator - (value_type rhs) const
inline Vec4s operator - (value_type rhs) const
{
return Short4(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs, _v[3]-rhs);
return Vec4s(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs, _v[3]-rhs);
}
inline Short4 operator + (const Short4& rhs) const
inline Vec4s operator + (const Vec4s& rhs) const
{
return Short4(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
return Vec4s(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
inline Short4 operator - (const Short4& rhs) const
inline Vec4s operator - (const Vec4s& rhs) const
{
return Short4(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2], _v[3]-rhs._v[3]);
return Vec4s(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2], _v[3]-rhs._v[3]);
}
inline Short4 operator * (const Short4& rhs) const
inline Vec4s operator * (const Vec4s& rhs) const
{
return Short4(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
return Vec4s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
}
};

152
include/osg/Vec4ub Normal file
View File

@@ -0,0 +1,152 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_VEC4UB
#define OSG_VEC4UB 1
#include <osg/Vec3>
namespace osg {
/** General purpose float quad.
* Uses include representation of color coordinates.
* No support yet added for float * Vec4ub - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Vec4ub * float is okay
*/
class Vec4ub
{
public:
// Methods are defined here so that they are implicitly inlined
Vec4ub() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0;}
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;
}
unsigned char _v[4];
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]; }
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]; }
inline bool operator < (const Vec4ub& 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 unsigned char* ptr() { return _v; }
inline const unsigned char* ptr() const { return _v; }
inline void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
}
inline unsigned char& operator [] (unsigned int i) { return _v[i]; }
inline unsigned char operator [] (unsigned int i) const { return _v[i]; }
inline unsigned char& r() { return _v[0]; }
inline unsigned char& g() { return _v[1]; }
inline unsigned char& b() { return _v[2]; }
inline unsigned char& a() { return _v[3]; }
inline unsigned char r() const { return _v[0]; }
inline unsigned char g() const { return _v[1]; }
inline unsigned char b() const { return _v[2]; }
inline unsigned char a() const { return _v[3]; }
/** Multiply by scalar. */
inline Vec4ub operator * (float rhs) const
{
Vec4ub col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Vec4ub& operator *= (float rhs)
{
_v[0]=(unsigned char)((float)_v[0]*rhs);
_v[1]=(unsigned char)((float)_v[1]*rhs);
_v[2]=(unsigned char)((float)_v[2]*rhs);
_v[3]=(unsigned char)((float)_v[3]*rhs);
return *this;
}
/** Divide by scalar. */
inline Vec4ub operator / (float rhs) const
{
Vec4ub col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Vec4ub& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline Vec4ub operator + (const Vec4ub& rhs) const
{
return Vec4ub(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
/** Unary vector add. Slightly more efficient because no temporary
* intermediate object.
*/
inline Vec4ub& operator += (const Vec4ub& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
_v[3] += rhs._v[3];
return *this;
}
/** Binary vector subtract. */
inline Vec4ub operator - (const Vec4ub& rhs) const
{
return Vec4ub(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2], _v[3]-rhs._v[3] );
}
/** Unary vector subtract. */
inline Vec4ub& operator -= (const Vec4ub& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
_v[3]-=rhs._v[3];
return *this;
}
}; // end of class Vec4ub
} // end of namespace osg
#endif

View File

@@ -18,13 +18,13 @@
#include <istream>
#include <osg/Vec4d>
#include <osg/UByte4>
#include <osg/Byte2>
#include <osg/Byte3>
#include <osg/Byte4>
#include <osg/Short2>
#include <osg/Short3>
#include <osg/Short4>
#include <osg/Vec4ub>
#include <osg/Vec2b>
#include <osg/Vec3b>
#include <osg/Vec4b>
#include <osg/Vec2s>
#include <osg/Vec3s>
#include <osg/Vec4s>
#include <osg/Matrixf>
#include <osg/Matrixd>
#include <osg/Plane>
@@ -131,23 +131,23 @@ inline std::istream& operator >> (std::istream& input, Vec4d& vec)
//////////////////////////////////////////////////////////////////////////
// Byte2 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Byte2& vec)
// Vec2b steaming operators.
inline std::ostream& operator << (std::ostream& output, const Vec2b& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Byte2& vec)
inline std::istream& operator >> (std::istream& input, Vec2b& vec)
{
input >> vec._v[0] >> vec._v[1];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Byte3 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Byte3& vec)
// Vec3b steaming operators.
inline std::ostream& operator << (std::ostream& output, const Vec3b& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
@@ -155,15 +155,15 @@ inline std::ostream& operator << (std::ostream& output, const Byte3& vec)
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Byte3& vec)
inline std::istream& operator >> (std::istream& input, Vec3b& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Byte4 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Byte4& vec)
// Vec4b steaming operators.
inline std::ostream& operator << (std::ostream& output, const Vec4b& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
@@ -172,7 +172,7 @@ inline std::ostream& operator << (std::ostream& output, const Byte4& vec)
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Byte4& vec)
inline std::istream& operator >> (std::istream& input, Vec4b& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2] >> vec._v[3];
return input;
@@ -180,23 +180,23 @@ inline std::istream& operator >> (std::istream& input, Byte4& vec)
//////////////////////////////////////////////////////////////////////////
// Short2 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Short2& vec)
// Vec2s steaming operators.
inline std::ostream& operator << (std::ostream& output, const Vec2s& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Short2& vec)
inline std::istream& operator >> (std::istream& input, Vec2s& vec)
{
input >> vec._v[0] >> vec._v[1];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Short3 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Short3& vec)
// Vec3s steaming operators.
inline std::ostream& operator << (std::ostream& output, const Vec3s& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
@@ -204,15 +204,15 @@ inline std::ostream& operator << (std::ostream& output, const Short3& vec)
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Short3& vec)
inline std::istream& operator >> (std::istream& input, Vec3s& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Short4 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Short4& vec)
// Vec4s steaming operators.
inline std::ostream& operator << (std::ostream& output, const Vec4s& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
@@ -221,7 +221,7 @@ inline std::ostream& operator << (std::ostream& output, const Short4& vec)
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Short4& vec)
inline std::istream& operator >> (std::istream& input, Vec4s& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2] >> vec._v[3];
return input;
@@ -260,8 +260,8 @@ inline std::ostream& operator<< (std::ostream& os, const Matrixd& m )
}
//////////////////////////////////////////////////////////////////////////
// UByte4 steaming operators.
inline std::ostream& operator << (std::ostream& output, const UByte4& vec)
// Vec4ub steaming operators.
inline std::ostream& operator << (std::ostream& output, const Vec4ub& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
@@ -270,7 +270,7 @@ inline std::ostream& operator << (std::ostream& output, const UByte4& vec)
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, UByte4& vec)
inline std::istream& operator >> (std::istream& input, Vec4ub& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2] >> vec._v[3];
return input;