From Pavel Moloshtan, Byte2,3,4 and Short2,3,4 classes and their Array counterparts.

With a few build tweaks and bug fixes by Robert Osfield.
This commit is contained in:
Robert Osfield
2005-07-05 15:57:53 +00:00
parent ba5f3ce99a
commit facb0e2638
27 changed files with 1571 additions and 154 deletions

View File

@@ -20,6 +20,13 @@
#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/Object>
#include <osg/GL>
@@ -50,7 +57,14 @@ class OSG_EXPORT Array : public Object
FloatArrayType = 8,
Vec2ArrayType = 9,
Vec3ArrayType = 10,
Vec4ArrayType = 11
Vec4ArrayType = 11,
Short2ArrayType = 12,
Short3ArrayType = 13,
Short4ArrayType = 14,
Byte2ArrayType = 15,
Byte3ArrayType = 16,
Byte4ArrayType = 17
};
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
@@ -257,6 +271,14 @@ typedef TemplateArray<Vec2,Array::Vec2ArrayType,2,GL_FLOAT>
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;
class ArrayVisitor
{
public:
@@ -274,6 +296,13 @@ class ArrayVisitor
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&) {}
};
class ConstArrayVisitor
@@ -293,6 +322,13 @@ class ConstArrayVisitor
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&) {}
};
@@ -312,6 +348,13 @@ class ValueVisitor
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&) {}
};
class ConstValueVisitor
@@ -330,6 +373,13 @@ class ConstValueVisitor
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&) {}
};
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>

136
include/osg/Byte2 Normal file
View File

@@ -0,0 +1,136 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_BYTE2
#define OSG_BYTE2 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Byte2 - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Byte2 * float is okay
*/
class Byte2
{
public:
// Methods are defined here so that they are implicitly inlined
Byte2() { _v[0]=0; _v[1]=0; }
Byte2(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 Byte2& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Byte2& 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 char* ptr() { return _v; }
inline const char* ptr() const { return _v; }
inline void set(char r, char g)
{
_v[0]=r; _v[1]=g;
}
inline char& operator [] (unsigned int i) { return _v[i]; }
inline char operator [] (unsigned int i) const { return _v[i]; }
inline char& r() { return _v[0]; }
inline char& g() { return _v[1]; }
inline char r() const { return _v[0]; }
inline char g() const { return _v[1]; }
/** Multiply by scalar. */
inline Byte2 operator * (float rhs) const
{
Byte2 col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Byte2& operator *= (float rhs)
{
_v[0]=(char)((float)_v[0]*rhs);
_v[1]=(char)((float)_v[1]*rhs);
return *this;
}
/** Divide by scalar. */
inline Byte2 operator / (float rhs) const
{
Byte2 col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Byte2& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline Byte2 operator + (const Byte2& rhs) const
{
return Byte2(_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)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
return *this;
}
/** Binary vector subtract. */
inline Byte2 operator - (const Byte2& rhs) const
{
return Byte2(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
/** Unary vector subtract. */
inline Byte2& operator -= (const Byte2& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
return *this;
}
}; // end of class Byte2
} // end of namespace osg
#endif

145
include/osg/Byte3 Normal file
View File

@@ -0,0 +1,145 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_BYTE3
#define OSG_BYTE3 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Byte3 - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Byte3 * float is okay
*/
class Byte3
{
public:
// Methods are defined here so that they are implicitly inlined
Byte3() { _v[0]=0; _v[1]=0; _v[2]=0; }
Byte3(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 Byte3& 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
{
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 char* ptr() { return _v; }
inline const char* ptr() const { return _v; }
inline void set(char r, char g, char 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 char& r() { return _v[0]; }
inline char& g() { return _v[1]; }
inline char& b() { return _v[2]; }
inline char r() const { return _v[0]; }
inline char g() const { return _v[1]; }
inline char b() const { return _v[2]; }
/** Multiply by scalar. */
inline Byte3 operator * (float rhs) const
{
Byte3 col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Byte3& operator *= (float rhs)
{
_v[0]=(char)((float)_v[0]*rhs);
_v[1]=(char)((float)_v[1]*rhs);
_v[2]=(char)((float)_v[2]*rhs);
return *this;
}
/** Divide by scalar. */
inline Byte3 operator / (float rhs) const
{
Byte3 col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Byte3& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline Byte3 operator + (const Byte3& rhs) const
{
return Byte3(_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)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
return *this;
}
/** Binary vector subtract. */
inline Byte3 operator - (const Byte3& rhs) const
{
return Byte3(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2]);
}
/** Unary vector subtract. */
inline Byte3& operator -= (const Byte3& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
return *this;
}
}; // end of class Byte3
} // end of namespace osg
#endif

152
include/osg/Byte4 Normal file
View File

@@ -0,0 +1,152 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_BYTE4
#define OSG_BYTE4 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Byte4 - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Byte4 * float is okay
*/
class Byte4
{
public:
// Methods are defined here so that they are implicitly inlined
Byte4() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
Byte4(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 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 Byte4& 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 char* ptr() { return _v; }
inline const char* ptr() const { return _v; }
inline void set(char r, char g, char b, char a)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
}
inline char& operator [] (unsigned int i) { return _v[i]; }
inline char 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 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]; }
/** Multiply by scalar. */
inline Byte4 operator * (float rhs) const
{
Byte4 col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Byte4& operator *= (float rhs)
{
_v[0]=(char)((float)_v[0]*rhs);
_v[1]=(char)((float)_v[1]*rhs);
_v[2]=(char)((float)_v[2]*rhs);
_v[3]=(char)((float)_v[3]*rhs);
return *this;
}
/** Divide by scalar. */
inline Byte4 operator / (float rhs) const
{
Byte4 col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Byte4& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline Byte4 operator + (const Byte4& rhs) const
{
return Byte4(_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)
{
_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 Byte4 operator - (const Byte4& rhs) const
{
return Byte4(_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)
{
_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 Byte4
} // end of namespace osg
#endif

View File

@@ -161,19 +161,20 @@ class OSG_EXPORT Geometry : public Drawable
void setNormalBinding(AttributeBinding ab) { _normalData.binding = ab; dirtyDisplayList(); computeFastPathsUsed(); }
AttributeBinding getNormalBinding() const { return _normalData.binding; }
void setNormalArray(Vec3Array* array) { _normalData.array = array; if (!_normalData.array.valid()) _normalData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
Vec3Array* getNormalArray() { return _normalData.array.get(); }
const Vec3Array* getNormalArray() const { return _normalData.array.get(); }
void setNormalArray(Array* array) { _normalData.array = array; if (!_normalData.array.valid()) _normalData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
Array* getNormalArray() { return _normalData.array.get(); }
const Array* getNormalArray() const { return _normalData.array.get(); }
Array* getNormalArrayEx() { return _normalData.array.get(); }
const Array* getNormalArrayEx() const { return _normalData.array.get(); }
void setNormalIndices(IndexArray* array) { _normalData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); }
IndexArray* getNormalIndices() { return _normalData.indices.get(); }
const IndexArray* getNormalIndices() const { return _normalData.indices.get(); }
void setNormalData(const Vec3ArrayData& arrayData) { _normalData = arrayData; }
Vec3ArrayData& getNormalData() { return _normalData; }
const Vec3ArrayData& getNormalData() const { return _normalData; }
void setNormalData(const ArrayData& arrayData) { _normalData = arrayData; }
ArrayData& getNormalData() { return _normalData; }
const ArrayData& getNormalData() const { return _normalData; }
void setColorBinding(AttributeBinding ab) { _colorData.binding = ab; computeFastPathsUsed();}
AttributeBinding getColorBinding() const { return _colorData.binding; }
@@ -380,7 +381,7 @@ class OSG_EXPORT Geometry : public Drawable
PrimitiveSetList _primitives;
ArrayData _vertexData;
Vec3ArrayData _normalData;
ArrayData _normalData;
ArrayData _colorData;
ArrayData _secondaryColorData;
ArrayData _fogCoordData;

85
include/osg/Short2 Normal file
View File

@@ -0,0 +1,85 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_SHORT_2
#define OSG_SHORT_2 1
namespace osg {
class Short2
{
public:
typedef short value_type;
union
{
struct {value_type x,y;};
value_type _v[2];
};
Short2() {}
Short2(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
{
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
{
return Short2(_v[0]*rhs, _v[1]*rhs);
}
inline Short2 operator / (value_type rhs) const
{
return Short2(_v[0]/rhs, _v[1]/rhs);
}
inline Short2 operator + (value_type rhs) const
{
return Short2(_v[0]+rhs, _v[1]+rhs);
}
inline Short2 operator - (value_type rhs) const
{
return Short2(_v[0]-rhs, _v[1]-rhs);
}
inline Short2 operator + (const Short2& rhs) const
{
return Short2(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
inline Short2 operator - (const Short2& rhs) const
{
return Short2(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
inline Short2 operator * (const Short2& rhs) const
{
return Short2(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);
}
};
}
#endif

87
include/osg/Short3 Normal file
View File

@@ -0,0 +1,87 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_SHORT_3
#define OSG_SHORT_3 1
namespace osg {
class Short3
{
public:
typedef short value_type;
union
{
struct {value_type x,y,z;};
value_type _v[3];
};
Short3 (){}
Short3 (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
{
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 Short3 operator * (value_type rhs) const
{
return Short3(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
inline Short3 operator / (value_type rhs) const
{
return Short3(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
inline Short3 operator + (value_type rhs) const
{
return Short3(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs);
}
inline Short3 operator - (value_type rhs) const
{
return Short3(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs);
}
inline Short3 operator + (const Short3& rhs) const
{
return Short3(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
}
inline Short3 operator - (const Short3& rhs) const
{
return Short3(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
inline Short3 operator * (const Short3& rhs) const
{
return Short3(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
}
};
};
#endif

89
include/osg/Short4 Normal file
View File

@@ -0,0 +1,89 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_SHORT_4
#define OSG_SHORT_4 1
namespace osg {
class Short4
{
public:
typedef short value_type;
union
{
struct {value_type x,y,z,w;};
value_type _v[4];
};
Short4 (){}
Short4 (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
{
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 Short4 operator * (value_type rhs) const
{
return Short4(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
inline Short4 operator / (value_type rhs) const
{
return Short4(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
inline Short4 operator + (value_type rhs) const
{
return Short4(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs, _v[3]+rhs);
}
inline Short4 operator - (value_type rhs) const
{
return Short4(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs, _v[3]-rhs);
}
inline Short4 operator + (const Short4& rhs) const
{
return Short4(_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
{
return Short4(_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
{
return Short4(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
}
};
};
#endif

View File

@@ -19,6 +19,12 @@
#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/Matrixf>
#include <osg/Matrixd>
#include <osg/Plane>
@@ -124,6 +130,104 @@ inline std::istream& operator >> (std::istream& input, Vec4d& vec)
}
//////////////////////////////////////////////////////////////////////////
// Byte2 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Byte2& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Byte2& vec)
{
input >> vec._v[0] >> vec._v[1];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Byte3 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Byte3& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
<< (int)vec._v[2];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Byte3& 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)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
<< (int)vec._v[2] << " "
<< (int)vec._v[3];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Byte4& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2] >> vec._v[3];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Short2 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Short2& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Short2& vec)
{
input >> vec._v[0] >> vec._v[1];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Short3 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Short3& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
<< (int)vec._v[2];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Short3& 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)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
<< (int)vec._v[2] << " "
<< (int)vec._v[3];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Short4& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2] >> vec._v[3];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Matrxf steaming operators.
inline std::ostream& operator<< (std::ostream& os, const Matrixf& m )