From David Callu, "Added Vec3ub, Vec3us, Vec4us, Vec2ub and Vec2us classes"

This commit is contained in:
Robert Osfield 2013-06-27 17:37:03 +00:00
parent 9f13e2fcb9
commit 775c1443eb
7 changed files with 1000 additions and 59 deletions

View File

@ -16,20 +16,32 @@
#include <osg/MixinVector>
#include <osg/Vec2b>
#include <osg/Vec3b>
#include <osg/Vec4b>
#include <osg/Vec2s>
#include <osg/Vec3s>
#include <osg/Vec4s>
#include <osg/Vec2i>
#include <osg/Vec3i>
#include <osg/Vec4i>
#include <osg/Vec2ub>
#include <osg/Vec3ub>
#include <osg/Vec4ub>
#include <osg/Vec2us>
#include <osg/Vec3us>
#include <osg/Vec4us>
#include <osg/Vec2ui>
#include <osg/Vec3ui>
#include <osg/Vec4ui>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Vec2d>
#include <osg/Vec3d>
#include <osg/Vec4d>
#include <osg/Vec4ub>
#include <osg/Vec2s>
#include <osg/Vec3s>
#include <osg/Vec4s>
#include <osg/Vec2b>
#include <osg/Vec3b>
#include <osg/Vec4b>
#include <osg/Matrix>
#include <osg/Matrixd>
#include <osg/BufferObject>
@ -52,28 +64,52 @@ class OSG_EXPORT Array : public BufferData
enum Type
{
ArrayType = 0,
ByteArrayType = 1,
ShortArrayType = 2,
IntArrayType = 3,
UByteArrayType = 4,
UShortArrayType = 5,
UIntArrayType = 6,
Vec4ubArrayType = 7,
FloatArrayType = 8,
Vec2ArrayType = 9,
Vec3ArrayType = 10,
Vec4ArrayType = 11,
FloatArrayType = 7,
DoubleArrayType = 8,
Vec2bArrayType = 9,
Vec3bArrayType = 10,
Vec4bArrayType = 11,
Vec2sArrayType = 12,
Vec3sArrayType = 13,
Vec4sArrayType = 14,
Vec2bArrayType = 15,
Vec3bArrayType = 16,
Vec4bArrayType = 17,
DoubleArrayType = 18,
Vec2dArrayType = 19,
Vec3dArrayType = 20,
Vec4dArrayType = 21,
MatrixArrayType = 22
Vec2iArrayType = 15,
Vec3iArrayType = 16,
Vec4iArrayType = 17,
Vec2ubArrayType = 18,
Vec3ubArrayType = 19,
Vec4ubArrayType = 20,
Vec2usArrayType = 21,
Vec3usArrayType = 22,
Vec4usArrayType = 23,
Vec2uiArrayType = 24,
Vec3uiArrayType = 25,
Vec4uiArrayType = 26,
Vec2ArrayType = 27,
Vec3ArrayType = 28,
Vec4ArrayType = 29,
Vec2dArrayType = 30,
Vec3dArrayType = 31,
Vec4dArrayType = 32,
MatrixArrayType = 33,
MatrixdArrayType = 34
};
enum Binding
@ -362,32 +398,49 @@ class TemplateIndexArray : public IndexArray, public MixinVector<T>
typedef TemplateIndexArray<GLbyte,Array::ByteArrayType,1,GL_BYTE> ByteArray;
typedef TemplateIndexArray<GLshort,Array::ShortArrayType,1,GL_SHORT> ShortArray;
typedef TemplateIndexArray<GLint,Array::IntArrayType,1,GL_INT> IntArray;
typedef TemplateIndexArray<GLubyte,Array::UByteArrayType,1,GL_UNSIGNED_BYTE> UByteArray;
typedef TemplateIndexArray<GLushort,Array::UShortArrayType,1,GL_UNSIGNED_SHORT> UShortArray;
typedef TemplateIndexArray<GLuint,Array::UIntArrayType,1,GL_UNSIGNED_INT> UIntArray;
typedef TemplateArray<GLfloat,Array::FloatArrayType,1,GL_FLOAT> FloatArray;
typedef TemplateArray<GLdouble,Array::DoubleArrayType,1,GL_DOUBLE> DoubleArray;
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<Vec4ub,Array::Vec4ubArrayType,4,GL_UNSIGNED_BYTE> Vec4ubArray;
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;
typedef TemplateArray<GLdouble,Array::DoubleArrayType,1,GL_DOUBLE> DoubleArray;
typedef TemplateArray<Vec2d,Array::Vec2dArrayType,2,GL_DOUBLE> Vec2dArray;
typedef TemplateArray<Vec3d,Array::Vec3dArrayType,3,GL_DOUBLE> Vec3dArray;
typedef TemplateArray<Vec4d,Array::Vec4dArrayType,4,GL_DOUBLE> Vec4dArray;
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<Matrixf,Array::MatrixArrayType,16,GL_FLOAT> MatrixfArray;
typedef TemplateArray<Vec2i,Array::Vec2iArrayType,2,GL_INT> Vec2iArray;
typedef TemplateArray<Vec3i,Array::Vec3iArrayType,3,GL_INT> Vec3iArray;
typedef TemplateArray<Vec4i,Array::Vec4iArrayType,4,GL_INT> Vec4iArray;
typedef TemplateArray<Vec2ub,Array::Vec2ubArrayType,2,GL_UNSIGNED_BYTE> Vec2ubArray;
typedef TemplateArray<Vec3ub,Array::Vec3ubArrayType,3,GL_UNSIGNED_BYTE> Vec3ubArray;
typedef TemplateArray<Vec4ub,Array::Vec4ubArrayType,4,GL_UNSIGNED_BYTE> Vec4ubArray;
typedef TemplateArray<Vec2us,Array::Vec2usArrayType,2,GL_UNSIGNED_SHORT> Vec2usArray;
typedef TemplateArray<Vec3us,Array::Vec3usArrayType,3,GL_UNSIGNED_SHORT> Vec3usArray;
typedef TemplateArray<Vec4us,Array::Vec4usArrayType,4,GL_UNSIGNED_SHORT> Vec4usArray;
typedef TemplateArray<Vec2ui,Array::Vec2uiArrayType,2,GL_UNSIGNED_INT> Vec2uiArray;
typedef TemplateArray<Vec3ui,Array::Vec3uiArrayType,3,GL_UNSIGNED_INT> Vec3uiArray;
typedef TemplateArray<Vec4ui,Array::Vec4uiArrayType,4,GL_UNSIGNED_INT> Vec4uiArray;
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<Vec2d,Array::Vec2dArrayType,2,GL_DOUBLE> Vec2dArray;
typedef TemplateArray<Vec3d,Array::Vec3dArrayType,3,GL_DOUBLE> Vec3dArray;
typedef TemplateArray<Vec4d,Array::Vec4dArrayType,4,GL_DOUBLE> Vec4dArray;
typedef TemplateArray<Matrixf,Array::MatrixArrayType,16,GL_FLOAT> MatrixfArray;
typedef TemplateArray<Matrixd,Array::MatrixdArrayType,16,GL_DOUBLE> MatrixdArray;
class ArrayVisitor
@ -397,20 +450,18 @@ class ArrayVisitor
virtual ~ArrayVisitor() {}
virtual void apply(Array&) {}
virtual void apply(ByteArray&) {}
virtual void apply(ShortArray&) {}
virtual void apply(IntArray&) {}
virtual void apply(UByteArray&) {}
virtual void apply(UShortArray&) {}
virtual void apply(UIntArray&) {}
virtual void apply(FloatArray&) {}
virtual void apply(DoubleArray&) {}
virtual void apply(Vec2Array&) {}
virtual void apply(Vec3Array&) {}
virtual void apply(Vec4Array&) {}
virtual void apply(Vec4ubArray&) {}
virtual void apply(Vec2bArray&) {}
virtual void apply(Vec3bArray&) {}
@ -420,11 +471,32 @@ class ArrayVisitor
virtual void apply(Vec3sArray&) {}
virtual void apply(Vec4sArray&) {}
virtual void apply(Vec2iArray&) {}
virtual void apply(Vec3iArray&) {}
virtual void apply(Vec4iArray&) {}
virtual void apply(Vec2ubArray&) {}
virtual void apply(Vec3ubArray&) {}
virtual void apply(Vec4ubArray&) {}
virtual void apply(Vec2usArray&) {}
virtual void apply(Vec3usArray&) {}
virtual void apply(Vec4usArray&) {}
virtual void apply(Vec2uiArray&) {}
virtual void apply(Vec3uiArray&) {}
virtual void apply(Vec4uiArray&) {}
virtual void apply(Vec2Array&) {}
virtual void apply(Vec3Array&) {}
virtual void apply(Vec4Array&) {}
virtual void apply(Vec2dArray&) {}
virtual void apply(Vec3dArray&) {}
virtual void apply(Vec4dArray&) {}
virtual void apply(MatrixfArray&) {}
virtual void apply(MatrixdArray&) {}
};
class ConstArrayVisitor
@ -434,20 +506,18 @@ class ConstArrayVisitor
virtual ~ConstArrayVisitor() {}
virtual void apply(const Array&) {}
virtual void apply(const ByteArray&) {}
virtual void apply(const ShortArray&) {}
virtual void apply(const IntArray&) {}
virtual void apply(const UByteArray&) {}
virtual void apply(const UShortArray&) {}
virtual void apply(const UIntArray&) {}
virtual void apply(const FloatArray&) {}
virtual void apply(const DoubleArray&) {}
virtual void apply(const Vec2Array&) {}
virtual void apply(const Vec3Array&) {}
virtual void apply(const Vec4Array&) {}
virtual void apply(const Vec4ubArray&) {}
virtual void apply(const Vec2bArray&) {}
virtual void apply(const Vec3bArray&) {}
@ -457,11 +527,32 @@ class ConstArrayVisitor
virtual void apply(const Vec3sArray&) {}
virtual void apply(const Vec4sArray&) {}
virtual void apply(const Vec2iArray&) {}
virtual void apply(const Vec3iArray&) {}
virtual void apply(const Vec4iArray&) {}
virtual void apply(const Vec2ubArray&) {}
virtual void apply(const Vec3ubArray&) {}
virtual void apply(const Vec4ubArray&) {}
virtual void apply(const Vec2usArray&) {}
virtual void apply(const Vec3usArray&) {}
virtual void apply(const Vec4usArray&) {}
virtual void apply(const Vec2uiArray&) {}
virtual void apply(const Vec3uiArray&) {}
virtual void apply(const Vec4uiArray&) {}
virtual void apply(const Vec2Array&) {}
virtual void apply(const Vec3Array&) {}
virtual void apply(const Vec4Array&) {}
virtual void apply(const Vec2dArray&) {}
virtual void apply(const Vec3dArray&) {}
virtual void apply(const Vec4dArray&) {}
virtual void apply(const MatrixfArray&) {}
virtual void apply(const MatrixdArray&) {}
};
@ -474,19 +565,15 @@ class ValueVisitor
virtual void apply(GLbyte&) {}
virtual void apply(GLshort&) {}
virtual void apply(GLint&) {}
virtual void apply(GLushort&) {}
virtual void apply(GLubyte&) {}
virtual void apply(GLuint&) {}
virtual void apply(GLfloat&) {}
virtual void apply(GLdouble&) {}
virtual void apply(Vec2&) {}
virtual void apply(Vec3&) {}
virtual void apply(Vec4&) {}
virtual void apply(Vec4ub&) {}
virtual void apply(Vec2b&) {}
virtual void apply(Vec3b&) {}
virtual void apply(Vec4b&) {}
@ -495,11 +582,32 @@ class ValueVisitor
virtual void apply(Vec3s&) {}
virtual void apply(Vec4s&) {}
virtual void apply(Vec2i&) {}
virtual void apply(Vec3i&) {}
virtual void apply(Vec4i&) {}
virtual void apply(Vec2ub&) {}
virtual void apply(Vec3ub&) {}
virtual void apply(Vec4ub&) {}
virtual void apply(Vec2us&) {}
virtual void apply(Vec3us&) {}
virtual void apply(Vec4us&) {}
virtual void apply(Vec2ui&) {}
virtual void apply(Vec3ui&) {}
virtual void apply(Vec4ui&) {}
virtual void apply(Vec2&) {}
virtual void apply(Vec3&) {}
virtual void apply(Vec4&) {}
virtual void apply(Vec2d&) {}
virtual void apply(Vec3d&) {}
virtual void apply(Vec4d&) {}
virtual void apply(Matrixf&) {}
virtual void apply(Matrixd&) {}
};
class ConstValueVisitor
@ -511,17 +619,14 @@ class ConstValueVisitor
virtual void apply(const GLbyte&) {}
virtual void apply(const GLshort&) {}
virtual void apply(const GLint&) {}
virtual void apply(const GLushort&) {}
virtual void apply(const GLubyte&) {}
virtual void apply(const GLuint&) {}
virtual void apply(const GLfloat&) {}
virtual void apply(const GLdouble&) {}
virtual void apply(const Vec4ub&) {}
virtual void apply(const Vec2&) {}
virtual void apply(const Vec3&) {}
virtual void apply(const Vec4&) {}
virtual void apply(const Vec2b&) {}
virtual void apply(const Vec3b&) {}
@ -531,11 +636,32 @@ class ConstValueVisitor
virtual void apply(const Vec3s&) {}
virtual void apply(const Vec4s&) {}
virtual void apply(const Vec2i&) {}
virtual void apply(const Vec3i&) {}
virtual void apply(const Vec4i&) {}
virtual void apply(const Vec2ub&) {}
virtual void apply(const Vec3ub&) {}
virtual void apply(const Vec4ub&) {}
virtual void apply(const Vec2us&) {}
virtual void apply(const Vec3us&) {}
virtual void apply(const Vec4us&) {}
virtual void apply(const Vec2ui&) {}
virtual void apply(const Vec3ui&) {}
virtual void apply(const Vec4ui&) {}
virtual void apply(const Vec2&) {}
virtual void apply(const Vec3&) {}
virtual void apply(const Vec4&) {}
virtual void apply(const Vec2d&) {}
virtual void apply(const Vec3d&) {}
virtual void apply(const Vec4d&) {}
virtual void apply(const Matrixf&) {}
virtual void apply(const Matrixd&) {}
};
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>

154
include/osg/Vec2ub Normal file
View File

@ -0,0 +1,154 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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_VEC2UB
#define OSG_VEC2UB 1
namespace osg {
/** General purpose unsigned byte pair.
*/
class Vec2ub
{
public:
/** Data type of vector components.*/
typedef unsigned char value_type;
/** Number of vector components. */
enum { num_components = 2 };
/** Vec member variable. */
value_type _v[2];
/** Constructor that sets all components of the vector to zero */
Vec2ub() { _v[0]=0; _v[1]=0; }
Vec2ub(value_type r, value_type g) { _v[0]=r; _v[1]=g; }
inline bool operator == (const Vec2ub& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Vec2ub& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Vec2ub& 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 Vec2ub& 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]; }
/** Multiply by scalar. */
inline Vec2ub operator * (float rhs) const
{
Vec2ub col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Vec2ub& operator *= (float rhs)
{
_v[0]=(value_type)((float)_v[0]*rhs);
_v[1]=(value_type)((float)_v[1]*rhs);
return *this;
}
/** Divide by scalar. */
inline Vec2ub operator / (float rhs) const
{
Vec2ub col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Vec2ub& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline Vec2ub operator + (const Vec2ub& rhs) const
{
return Vec2ub(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
/** Unary vector add. Slightly more efficient because no temporary
* intermediate object.
*/
inline Vec2ub& operator += (const Vec2ub& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
return *this;
}
/** Binary vector subtract. */
inline Vec2ub operator - (const Vec2ub& rhs) const
{
return Vec2ub(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
/** Unary vector subtract. */
inline Vec2ub& operator -= (const Vec2ub& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
return *this;
}
}; // end of class Vec2ub
/** multiply by vector components. */
inline Vec2ub componentMultiply(const Vec2ub& lhs, const Vec2ub& rhs)
{
return Vec2ub(lhs[0]*rhs[0], lhs[1]*rhs[1]);
}
/** divide rhs components by rhs vector components. */
inline Vec2ub componentDivide(const Vec2ub& lhs, const Vec2ub& rhs)
{
return Vec2ub(lhs[0]/rhs[0], lhs[1]/rhs[1]);
}
} // end of namespace osg
#endif

136
include/osg/Vec2us Normal file
View File

@ -0,0 +1,136 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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_VEC2US
#define OSG_VEC2US 1
namespace osg {
class Vec2us
{
public:
/** Data type of vector components.*/
typedef unsigned short value_type;
/** Number of vector components. */
enum { num_components = 2 };
value_type _v[2];
/** Constructor that sets all components of the vector to zero */
Vec2us() { _v[0]=0; _v[1]=0; }
Vec2us(value_type x, value_type y) { _v[0] = x; _v[1] = y; }
inline bool operator == (const Vec2us& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Vec2us& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Vec2us& 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 Vec2us& 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 Vec2us operator * (value_type rhs) const
{
return Vec2us(_v[0]*rhs, _v[1]*rhs);
}
inline Vec2us& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
return *this;
}
inline Vec2us operator / (value_type rhs) const
{
return Vec2us(_v[0]/rhs, _v[1]/rhs);
}
inline Vec2us& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
return *this;
}
inline Vec2us operator + (const Vec2us& rhs) const
{
return Vec2us(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
inline Vec2us& operator += (const Vec2us& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
return *this;
}
inline Vec2us operator - (const Vec2us& rhs) const
{
return Vec2us(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
inline Vec2us& operator -= (const Vec2us& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
return *this;
}
}; // end of class Vec2us
/** multiply by vector components. */
inline Vec2us componentMultiply(const Vec2us& lhs, const Vec2us& rhs)
{
return Vec2us(lhs[0]*rhs[0], lhs[1]*rhs[1]);
}
/** divide rhs components by rhs vector components. */
inline Vec2us componentDivide(const Vec2us& lhs, const Vec2us& rhs)
{
return Vec2us(lhs[0]/rhs[0], lhs[1]/rhs[1]);
}
} // end of namespace osg
#endif

170
include/osg/Vec3ub Normal file
View File

@ -0,0 +1,170 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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_VEC3UB
#define OSG_VEC3UB 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Vec3ub - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Vec3ub * float is okay
*/
class Vec3ub
{
public:
/** Data type of vector components.*/
typedef unsigned char value_type;
/** Number of vector components. */
enum { num_components = 3 };
value_type _v[3];
/** Constructor that sets all components of the vector to zero */
Vec3ub() { _v[0]=0; _v[1]=0; _v[2]=0; }
Vec3ub(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
inline bool operator == (const Vec3ub& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Vec3ub& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Vec3ub& 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 Vec3ub& 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 Vec3ub operator * (float rhs) const
{
Vec3ub col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Vec3ub& operator *= (float rhs)
{
_v[0]=(value_type)((float)_v[0]*rhs);
_v[1]=(value_type)((float)_v[1]*rhs);
_v[2]=(value_type)((float)_v[2]*rhs);
return *this;
}
/** Divide by scalar. */
inline Vec3ub operator / (float rhs) const
{
Vec3ub col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Vec3ub& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline Vec3ub operator + (const Vec3ub& rhs) const
{
return Vec3ub(_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 Vec3ub& operator += (const Vec3ub& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
return *this;
}
/** Binary vector subtract. */
inline Vec3ub operator - (const Vec3ub& rhs) const
{
return Vec3ub(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2]);
}
/** Unary vector subtract. */
inline Vec3ub& operator -= (const Vec3ub& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
return *this;
}
}; // end of class Vec3ub
/** multiply by vector components. */
inline Vec3ub componentMultiply(const Vec3ub& lhs, const Vec3ub& rhs)
{
return Vec3ub(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
}
/** divide rhs components by rhs vector components. */
inline Vec3ub componentDivide(const Vec3ub& lhs, const Vec3ub& rhs)
{
return Vec3ub(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
}
} // end of namespace osg
#endif

164
include/osg/Vec3us Normal file
View File

@ -0,0 +1,164 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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_VEC3US
#define OSG_VEC3US 1
namespace osg {
class Vec3us
{
public:
/** Data type of vector components.*/
typedef unsigned short value_type;
/** Number of vector components. */
enum { num_components = 3 };
value_type _v[3];
/** Constructor that sets all components of the vector to zero */
Vec3us() { _v[0]=0; _v[1]=0; _v[2]=0; }
Vec3us(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
inline bool operator == (const Vec3us& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Vec3us& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Vec3us& 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 Vec3us& 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 Vec3us operator * (value_type rhs) const
{
return Vec3us(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
/** Unary multiply by scalar. */
inline Vec3us& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
return *this;
}
/** Divide by scalar. */
inline Vec3us operator / (value_type rhs) const
{
return Vec3us(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
/** Unary divide by scalar. */
inline Vec3us& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
return *this;
}
/** Binary vector multiply. */
inline Vec3us operator * (const Vec3us& rhs) const
{
return Vec3us(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
}
/** Binary vector add. */
inline Vec3us operator + (const Vec3us& rhs) const
{
return Vec3us(_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 Vec3us& operator += (const Vec3us& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
return *this;
}
/** Binary vector subtract. */
inline Vec3us operator - (const Vec3us& rhs) const
{
return Vec3us(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
/** Unary vector subtract. */
inline Vec3us& operator -= (const Vec3us& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
return *this;
}
}; // end of class Vec3us
/** multiply by vector components. */
inline Vec3us componentMultiply(const Vec3us& lhs, const Vec3us& rhs)
{
return Vec3us(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
}
/** divide rhs components by rhs vector components. */
inline Vec3us componentDivide(const Vec3us& lhs, const Vec3us& rhs)
{
return Vec3us(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
}
} // end of namespace osg
#endif

186
include/osg/Vec4us Normal file
View File

@ -0,0 +1,186 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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_VEC4US
#define OSG_VEC4US 1
namespace osg {
/** General purpose float quad. Uses include representation
* of color coordinates.
* No support yet added for float * Vec4us - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Vec4us * float is okay
*/
class Vec4us
{
public:
/** Data type of vector components.*/
typedef unsigned short value_type;
/** Number of vector components. */
enum { num_components = 4 };
/** Vec member variable. */
value_type _v[4];
/** Constructor that sets all components of the vector to zero */
Vec4us() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
Vec4us(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 Vec4us& 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 Vec4us& 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 Vec4us& 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 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]; }
/** Multiply by scalar. */
inline Vec4us operator * (value_type rhs) const
{
return Vec4us(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
/** Unary multiply by scalar. */
inline Vec4us& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
_v[3]*=rhs;
return *this;
}
/** Divide by scalar. */
inline Vec4us operator / (value_type rhs) const
{
return Vec4us(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
/** Unary divide by scalar. */
inline Vec4us& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
_v[3]/=rhs;
return *this;
}
/** Binary vector multiply. */
inline Vec4us operator * (const Vec4us& rhs) const
{
return Vec4us(_v[0]*rhs._v[0], _v[1]*rhs._v[1],
_v[2]*rhs._v[2], _v[3]*rhs._v[3]);
}
/** Binary vector add. */
inline Vec4us operator + (const Vec4us& rhs) const
{
return Vec4us(_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 Vec4us& operator += (const Vec4us& 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 Vec4us operator - (const Vec4us& rhs) const
{
return Vec4us(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2], _v[3]-rhs._v[3] );
}
/** Unary vector subtract. */
inline Vec4us& operator -= (const Vec4us& 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 Vec4us
/** multiply by vector components. */
inline Vec4us componentMultiply(const Vec4us& lhs, const Vec4us& rhs)
{
return Vec4us(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2], lhs[3]*rhs[3]);
}
/** divide rhs components by rhs vector components. */
inline Vec4us componentDivide(const Vec4us& lhs, const Vec4us& rhs)
{
return Vec4us(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2], lhs[3]/rhs[3]);
}
} // end of namespace osg
#endif

View File

@ -181,24 +181,29 @@ SET(TARGET_H
${HEADER_PATH}/Vec2b
${HEADER_PATH}/Vec2d
${HEADER_PATH}/Vec2f
${HEADER_PATH}/Vec2s
${HEADER_PATH}/Vec2i
${HEADER_PATH}/Vec2s
${HEADER_PATH}/Vec2ub
${HEADER_PATH}/Vec2ui
${HEADER_PATH}/Vec2us
${HEADER_PATH}/Vec3
${HEADER_PATH}/Vec3b
${HEADER_PATH}/Vec3d
${HEADER_PATH}/Vec3f
${HEADER_PATH}/Vec3s
${HEADER_PATH}/Vec3i
${HEADER_PATH}/Vec3s
${HEADER_PATH}/Vec3ub
${HEADER_PATH}/Vec3ui
${HEADER_PATH}/Vec3us
${HEADER_PATH}/Vec4
${HEADER_PATH}/Vec4b
${HEADER_PATH}/Vec4d
${HEADER_PATH}/Vec4f
${HEADER_PATH}/Vec4s
${HEADER_PATH}/Vec4i
${HEADER_PATH}/Vec4ui
${HEADER_PATH}/Vec4s
${HEADER_PATH}/Vec4ub
${HEADER_PATH}/Vec4ui
${HEADER_PATH}/Vec4us
${HEADER_PATH}/Version
${HEADER_PATH}/VertexProgram
${HEADER_PATH}/View