o Updated Metrowerks files for MacOS. They aren't 100% there yet,
but getting there.
o First cut of osgcluster demo. Very simple beginings. Alas
I only one PC here so I can't test it in its current guise.
o New support for NodeCallbacks, via AppCallback attached to
osg::Node's, and a default osgUtil::AppVisitor which calls them on
each frame.
o Support for traversal masks in osg::NodeVisitor, osg::Node
which allows nodes to be switched on or off via a bit mask.
o Suppport for traversal number (frame number) and reference time
into osg::NodeVisitor to handle syncronization of app and cull
traversals. This also assist clustering as traversal number
master to slaves.
This commit is contained in:
224
include/osg/Matrix.new
Normal file
224
include/osg/Matrix.new
Normal file
@@ -0,0 +1,224 @@
|
||||
|
||||
#ifndef OSG_Matrix
|
||||
#define OSG_Matrix 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
//#include <osg/Quat>
|
||||
|
||||
#ifdef OSG_USE_IO_DOT_H
|
||||
#include <iostream.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
#define METAOBJ(name) \
|
||||
virtual Object* clone() const { return new name (); } \
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
|
||||
virtual const char* className() const { return #name; }
|
||||
|
||||
namespace osg {
|
||||
|
||||
class Quat;
|
||||
|
||||
class SG_EXPORT Matrix : public Object
|
||||
{
|
||||
// private:
|
||||
public:
|
||||
float _mat[4][4];
|
||||
bool fully_realized;
|
||||
|
||||
public:
|
||||
// const char* name() { return "My Matrix "; }
|
||||
METAOBJ(Matrix)
|
||||
|
||||
Matrix();
|
||||
Matrix( const Matrix& other );
|
||||
explicit Matrix( float const * const def );
|
||||
Matrix( float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23,
|
||||
float a30, float a31, float a32, float a33);
|
||||
|
||||
virtual ~Matrix() {}
|
||||
|
||||
Matrix& operator = (const Matrix& );
|
||||
|
||||
inline float& operator()(int col, int row) { return _mat[col][row]; }
|
||||
inline float operator()(int col, int row) const { return _mat[col][row]; }
|
||||
|
||||
void set( float const * const );
|
||||
void set( float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23,
|
||||
float a30, float a31, float a32, float a33);
|
||||
const float * values() { return (const float *)_mat; }
|
||||
|
||||
void makeIdent();
|
||||
void makeScale( const Vec3& );
|
||||
void makeScale( float, float, float );
|
||||
|
||||
void makeTrans( const Vec3& );
|
||||
void makeTrans( float, float, float );
|
||||
//TODO: original preTrans was optimized (M=Tr*M)
|
||||
// but also has the assumption that M (this) is an affine transformation Matrix
|
||||
// can I still do something to optimize the same case now?
|
||||
|
||||
void makeRot( const Vec3& from, const Vec3& to );
|
||||
void makeRot( float angle, const Vec3& orientation );
|
||||
void makeRot( float angle, float x, float y, float z );
|
||||
void makeRot( const Quat& );
|
||||
void makeRot( float, float, float ); //Euler angles
|
||||
|
||||
bool invert( const Matrix& );
|
||||
bool invertAffine( const Matrix& );
|
||||
|
||||
//basic utility functions to create new matrices or vectors
|
||||
static Matrix scale( const Vec3& );
|
||||
static Matrix scale( float, float, float );
|
||||
static Matrix trans( const Vec3& );
|
||||
static Matrix trans( float, float, float );
|
||||
static Matrix rotate( const Vec3&, const Vec3& );
|
||||
static Matrix rotate( float, float, float, float );
|
||||
static Matrix rotate( const Quat& );
|
||||
|
||||
inline Vec3 preMult( const Vec3& v ) const;
|
||||
inline Vec3 postMult( const Vec3& v ) const;
|
||||
inline Vec3 operator* ( const Vec3& v ) const;
|
||||
inline Vec4 preMult( const Vec4& v ) const;
|
||||
inline Vec4 postMult( const Vec4& v ) const;
|
||||
inline Vec4 operator* ( const Vec4& v ) const;
|
||||
|
||||
//start of Deprecated methods
|
||||
|
||||
void copy( const Matrix& );
|
||||
void preScale( float sx, float sy, float sz, const Matrix& m );
|
||||
void postScale( const Matrix& m, float sx, float sy, float sz );
|
||||
void preScale( float sx, float sy, float sz );
|
||||
void postScale( float sx, float sy, float sz );
|
||||
|
||||
void preTrans( float tx, float ty, float tz, const Matrix& m );
|
||||
void postTrans( const Matrix& m, float tx, float ty, float tz );
|
||||
void preTrans( float tx, float ty, float tz);
|
||||
void postTrans( float tx, float ty, float tz );
|
||||
|
||||
void preRot( float deg, float x, float y, float z, const Matrix& m );
|
||||
void postRot( const Matrix& m, float deg, float x, float y, float z );
|
||||
void preRot( float deg, float x, float y, float z );
|
||||
void postRot( float deg, float x, float y, float z );
|
||||
|
||||
/** apply apply an 3x3 transform of v*M[0..2,0..2] */
|
||||
inline static Vec3 transform3x3(const Vec3& v,const Matrix& m);
|
||||
/** apply apply an 3x3 transform of M[0..2,0..2]*v */
|
||||
inline static Vec3 transform3x3(const Matrix& m,const Vec3& v);
|
||||
|
||||
//end of Deprecated methods
|
||||
|
||||
|
||||
// basic matrix multiplication, our workhorse methods.
|
||||
void mult( const Matrix&, const Matrix& );
|
||||
void preMult( const Matrix& );
|
||||
void postMult( const Matrix& );
|
||||
|
||||
// Helper class to optimize product expressions somewhat
|
||||
class MatrixProduct {
|
||||
public:
|
||||
const Matrix& A;
|
||||
const Matrix& B;
|
||||
|
||||
MatrixProduct( const Matrix& lhs, const Matrix& rhs ) : A(lhs), B(rhs) {}
|
||||
};
|
||||
|
||||
inline MatrixProduct operator * ( const Matrix& other ) const
|
||||
{ return MatrixProduct(*this, other); }
|
||||
|
||||
inline void operator *= ( const Matrix& other )
|
||||
{ if( this == &other ) {
|
||||
Matrix temp(other);
|
||||
postMult( temp );
|
||||
}
|
||||
else postMult( other );
|
||||
}
|
||||
inline void operator = ( const MatrixProduct& p )
|
||||
{
|
||||
if( this == &(p.A)) postMult(p.B);
|
||||
else if( this == &(p.B)) preMult(p.A);
|
||||
else mult( p.A, p.B );
|
||||
}
|
||||
|
||||
Matrix( const MatrixProduct& p ) //allows implicit evaluation of the product
|
||||
{ mult( p.A, p.B ); }
|
||||
};
|
||||
|
||||
inline Vec3 Matrix::postMult ( const Vec3& v ) const {
|
||||
float d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
|
||||
return Vec3( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
|
||||
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
|
||||
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
|
||||
}
|
||||
|
||||
inline Vec3 Matrix::preMult (const Vec3& v ) const {
|
||||
float d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
|
||||
return Vec3( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
|
||||
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
|
||||
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
|
||||
}
|
||||
inline Vec3 Matrix::operator* (const Vec3& v) const {
|
||||
return postMult(v);
|
||||
}
|
||||
inline Vec3 operator* (const Vec3& v, const Matrix& m ) {
|
||||
return m.preMult(v);
|
||||
}
|
||||
inline Vec4 Matrix::postMult(const Vec4& v) const {
|
||||
return Vec4( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
|
||||
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
|
||||
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
|
||||
(_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
|
||||
}
|
||||
/*
|
||||
inline Vec4 Matrix::preMult(const Vec4& v,const Matrix& m) {
|
||||
return Vec4( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z() + m._mat[3][0]*v.w()),
|
||||
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z() + m._mat[3][1]*v.w()),
|
||||
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z() + m._mat[3][2]*v.w()),
|
||||
(m._mat[0][3]*v.x() + m._mat[1][3]*v.y() + m._mat[2][3]*v.z() + m._mat[3][3]*v.w()));
|
||||
}
|
||||
*/
|
||||
inline Vec4 Matrix::operator* (const Vec4& v) const {
|
||||
return postMult(v);
|
||||
}
|
||||
inline Vec4 operator* (const Vec4& v, const Matrix& m ) {
|
||||
return m.preMult(v);
|
||||
}
|
||||
|
||||
inline Vec3 Matrix::transform3x3(const Vec3& v,const Matrix& m)
|
||||
{
|
||||
return Vec3( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
|
||||
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
|
||||
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
|
||||
}
|
||||
|
||||
inline Vec3 Matrix::transform3x3(const Matrix& m,const Vec3& v)
|
||||
{
|
||||
return Vec3( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
|
||||
(m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
|
||||
(m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
|
||||
}
|
||||
|
||||
inline ostream& operator<< (ostream& os, const Matrix& m ) {
|
||||
os << "{";
|
||||
for(int row=0; row<4; ++row) {
|
||||
os << "\t";
|
||||
for(int col=0; col<4; ++col)
|
||||
os << m(col,row) << " ";
|
||||
os << endl;
|
||||
}
|
||||
os << "}" << endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
}; //namespace osg
|
||||
|
||||
|
||||
#endif
|
||||
184
include/osg/Matrix.old
Normal file
184
include/osg/Matrix.old
Normal file
@@ -0,0 +1,184 @@
|
||||
#ifndef OSG_MATRIX
|
||||
#define OSG_MATRIX 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
|
||||
#ifdef OSG_USE_IO_DOT_H
|
||||
#include <iostream.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** 4x4 Matrix for storage & manipulation of transformations in scene graph.
|
||||
Provides basic maths operations, IO and via osg::Object reference counting.
|
||||
You can directly load the matrix with OpenGL's LoadMatrixf() function via
|
||||
the public member _mat as the matrix is stored in the OpenGL format.
|
||||
Caution: The disadvantage of this feature is, that the matrix access is
|
||||
'transposed' if you compare it with the standard C/C++ 2d-array-access
|
||||
convention . I.e. _mat[i][j] accesses the ith column of the jth row in the
|
||||
4x4 matrix.
|
||||
*/
|
||||
|
||||
class SG_EXPORT Matrix : public Object
|
||||
{
|
||||
public:
|
||||
Matrix();
|
||||
Matrix(const Matrix& matrix);
|
||||
Matrix( float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23,
|
||||
float a30, float a31, float a32, float a33);
|
||||
|
||||
Matrix& operator = (const Matrix& matrix);
|
||||
|
||||
virtual ~Matrix();
|
||||
|
||||
virtual Object* clone() const { return new Matrix(); }
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Matrix*>(obj)!=NULL; }
|
||||
virtual const char* className() const { return "Matrix"; }
|
||||
|
||||
void makeIdent();
|
||||
|
||||
void set(const float* m);
|
||||
|
||||
void set( float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23,
|
||||
float a30, float a31, float a32, float a33);
|
||||
|
||||
void copy(const Matrix& matrix);
|
||||
|
||||
void makeScale(float sx, float sy, float sz);
|
||||
void preScale( float sx, float sy, float sz, const Matrix& m );
|
||||
void postScale( const Matrix& m, float sx, float sy, float sz );
|
||||
|
||||
void preScale( float sx, float sy, float sz );
|
||||
void postScale( float sx, float sy, float sz );
|
||||
|
||||
|
||||
void makeTrans( float tx, float ty, float tz );
|
||||
void preTrans( float tx, float ty, float tz, const Matrix& m );
|
||||
void postTrans( const Matrix& m, float tx, float ty, float tz );
|
||||
|
||||
void preTrans( float tx, float ty, float tz );
|
||||
void postTrans( float tx, float ty, float tz );
|
||||
|
||||
|
||||
/**
|
||||
* Calc the rotation matrix which aligns vector \a old_vec with
|
||||
* vector \a new_vec. Both \a old_vec and \a new_vec must have
|
||||
* length 1.0.
|
||||
*/
|
||||
void makeRot( const Vec3& old_vec, const Vec3& new_vec );
|
||||
|
||||
void makeRot( float deg, float x, float y, float z );
|
||||
void preRot( float deg, float x, float y, float z, const Matrix& m );
|
||||
void postRot( const Matrix& m, float deg, float x, float y, float z );
|
||||
|
||||
void preRot( float deg, float x, float y, float z );
|
||||
void postRot( float deg, float x, float y, float z );
|
||||
|
||||
void setTrans( float tx, float ty, float tz );
|
||||
void setTrans( const Vec3& v );
|
||||
Vec3 getTrans() const { return Vec3(_mat[3][0],_mat[3][1],_mat[3][2]); }
|
||||
|
||||
void preMult(const Matrix& m);
|
||||
void postMult(const Matrix& m);
|
||||
void mult(const Matrix& lhs,const Matrix& rhs);
|
||||
|
||||
Matrix operator * (const Matrix& m) const;
|
||||
|
||||
/** apply apply an 3x3 transform of v*M[0..2,0..2] */
|
||||
inline static Vec3 transform3x3(const Vec3& v,const Matrix& m);
|
||||
/** apply apply an 3x3 transform of M[0..2,0..2]*v */
|
||||
inline static Vec3 transform3x3(const Matrix& m,const Vec3& v);
|
||||
|
||||
/** post multipy v. ie. (m*v) */
|
||||
inline Vec3 operator * (const Vec3& v) const;
|
||||
|
||||
/** pre multipy v. ie. (v*m) */
|
||||
friend inline Vec3 operator * (const Vec3& v,const Matrix& m);
|
||||
|
||||
/** post multipy v. ie. (m*v) */
|
||||
inline Vec4 operator * (const Vec4& v) const;
|
||||
|
||||
/** pre multipy v. ie. (v*m) */
|
||||
friend inline Vec4 operator * (const Vec4& v,const Matrix& m);
|
||||
|
||||
friend inline ostream& operator << (ostream& output, const Matrix& matrix);
|
||||
|
||||
bool invert(const Matrix& m);
|
||||
|
||||
public :
|
||||
float _mat[4][4];
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
inline Vec3 Matrix::operator * (const Vec3& v) const
|
||||
{
|
||||
float d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
|
||||
return Vec3( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
|
||||
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
|
||||
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
|
||||
}
|
||||
|
||||
|
||||
inline Vec3 operator * (const Vec3& v,const Matrix& m)
|
||||
{
|
||||
float d = 1.0f/(m._mat[0][3]*v.x()+m._mat[1][3]*v.y()+m._mat[2][3]*v.z()+m._mat[3][3]) ;
|
||||
return Vec3( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z() + m._mat[3][0])*d,
|
||||
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z() + m._mat[3][1])*d,
|
||||
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z() + m._mat[3][2])*d);
|
||||
}
|
||||
|
||||
inline Vec4 Matrix::operator * (const Vec4& v) const
|
||||
{
|
||||
return Vec4( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
|
||||
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
|
||||
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
|
||||
(_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
|
||||
}
|
||||
|
||||
|
||||
inline Vec4 operator * (const Vec4& v,const Matrix& m)
|
||||
{
|
||||
return Vec4( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z() + m._mat[3][0]*v.w()),
|
||||
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z() + m._mat[3][1]*v.w()),
|
||||
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z() + m._mat[3][2]*v.w()),
|
||||
(m._mat[0][3]*v.x() + m._mat[1][3]*v.y() + m._mat[2][3]*v.z() + m._mat[3][3]*v.w()));
|
||||
}
|
||||
|
||||
inline Vec3 Matrix::transform3x3(const Vec3& v,const Matrix& m)
|
||||
{
|
||||
return Vec3( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
|
||||
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
|
||||
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
|
||||
}
|
||||
|
||||
inline Vec3 Matrix::transform3x3(const Matrix& m,const Vec3& v)
|
||||
{
|
||||
return Vec3( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
|
||||
(m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
|
||||
(m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
|
||||
}
|
||||
|
||||
inline ostream& operator << (ostream& output, const Matrix& matrix)
|
||||
{
|
||||
output << "{"<<endl
|
||||
<< " " << matrix._mat[0][0] << " " << matrix._mat[0][1] << " " << matrix._mat[0][2] << " " << matrix._mat[0][3] << endl
|
||||
<< " " << matrix._mat[1][0] << " " << matrix._mat[1][1] << " " << matrix._mat[1][2] << " " << matrix._mat[1][3] << endl
|
||||
<< " " << matrix._mat[2][0] << " " << matrix._mat[2][1] << " " << matrix._mat[2][2] << " " << matrix._mat[2][3] << endl
|
||||
<< " " << matrix._mat[3][0] << " " << matrix._mat[3][1] << " " << matrix._mat[3][2] << " " << matrix._mat[3][3] << endl
|
||||
<< "}" << endl;
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
46
include/osg/NodeCallback
Normal file
46
include/osg/NodeCallback
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef OSG_NODECALLBACK
|
||||
#define OSG_NODECALLBACK 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
|
||||
namespace osg {
|
||||
|
||||
class Node;
|
||||
class NodeVisitor;
|
||||
|
||||
class SG_EXPORT NodeCallback : public Referenced {
|
||||
|
||||
public :
|
||||
|
||||
/** The range of values which can be accumulated by the NodeVisitor. */
|
||||
enum Requirements
|
||||
{
|
||||
NO_REQUIREMENTS = 0x0,
|
||||
REQUIRES_TRAVERSAL = 0x1,
|
||||
REQUIRES_PARENT_PATH = 0x2,
|
||||
REQUIRES_ACCUMULATED_MATRIX = 0x4,
|
||||
REQUIRES_ACCUMULATED_INVERSE = 0x8,
|
||||
};
|
||||
|
||||
NodeCallback(const Requirements ncr=NO_REQUIREMENTS):_requirements(ncr) {}
|
||||
virtual ~NodeCallback() {}
|
||||
|
||||
|
||||
/** Set what values from traversal are required by this NodeCallback.*/
|
||||
inline void setRequirements(const Requirements ncr) { _requirements=ncr; }
|
||||
|
||||
/** Get what values from traversal are required by this NodeCallback.*/
|
||||
inline const Requirements getRequirements() const { return _requirements; }
|
||||
|
||||
/** Callback method call by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator()(Node*, NodeVisitor*) {}
|
||||
|
||||
public:
|
||||
|
||||
Requirements _requirements;
|
||||
};
|
||||
|
||||
}; // namespace
|
||||
|
||||
#endif
|
||||
|
||||
63
include/osg/Viewport
Normal file
63
include/osg/Viewport
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef OSG_VIEWPORT
|
||||
#define OSG_VIEWPORT 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Types>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Encapsulte OpenGL glViewport.
|
||||
*/
|
||||
class SG_EXPORT Viewport : public StateAttribute
|
||||
{
|
||||
public :
|
||||
|
||||
|
||||
Viewport();
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Viewport*>(obj)!=0L; }
|
||||
virtual Object* clone() const { return new Viewport(); }
|
||||
virtual const char* className() const { return "Viewport"; }
|
||||
|
||||
virtual const Type getType() const { return VIEWPORT; }
|
||||
|
||||
inline void setViewport(const int x,const int y,const int width,const int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
void getViewport(int& x,int& y,int& width,int& height)
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
width = _width;
|
||||
height = _height;
|
||||
}
|
||||
|
||||
inline const int x() const { return _x; }
|
||||
inline const int y() const { return _y; }
|
||||
inline const int width() const { return _width; }
|
||||
inline const int height() const { return _height; }
|
||||
|
||||
/** return the aspcetRatio of the viewport, which is equal to width/height.*/
|
||||
inline const float aspectRatio() const { return (float)_width/(float)_height; }
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Viewport();
|
||||
|
||||
int _x;
|
||||
int _y;
|
||||
int _width;
|
||||
int _height;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
67
include/osgUtil/AppVisitor
Normal file
67
include/osgUtil/AppVisitor
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef OSGUTIL_APPVISITOR
|
||||
#define OSGUTIL_APPVISITOR 1
|
||||
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/Node>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/LOD>
|
||||
#include <osg/Switch>
|
||||
#include <osg/LightSource>
|
||||
#include <osg/Transform>
|
||||
#include <osg/Impostor>
|
||||
|
||||
#include <osgUtil/Export>
|
||||
|
||||
namespace osgUtil {
|
||||
|
||||
/**
|
||||
* Basic AppVisitor implementation for animating a scene.
|
||||
* This visitor traverses the scene graph, call each nodes appCallback if
|
||||
* it exists.
|
||||
*/
|
||||
class OSGUTIL_EXPORT AppVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
AppVisitor();
|
||||
virtual ~AppVisitor();
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual void apply(osg::Node& node) { handle_callbacks(node); }
|
||||
|
||||
virtual void apply(osg::Geode& node) { handle_callbacks(node); }
|
||||
virtual void apply(osg::Billboard& node) { handle_callbacks(node); }
|
||||
virtual void apply(osg::LightSource& node){ handle_callbacks(node); }
|
||||
|
||||
virtual void apply(osg::Group& node) { handle_callbacks(node); }
|
||||
virtual void apply(osg::Transform& node) { handle_callbacks(node); }
|
||||
virtual void apply(osg::Switch& node) { handle_callbacks(node); }
|
||||
virtual void apply(osg::LOD& node) { handle_callbacks(node); }
|
||||
virtual void apply(osg::Impostor& node) { handle_callbacks(node); }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** prevent unwanted copy construction.*/
|
||||
AppVisitor(const AppVisitor&):osg::NodeVisitor() {}
|
||||
|
||||
/** prevent unwanted copy operator.*/
|
||||
AppVisitor& operator = (const AppVisitor&) { return *this; }
|
||||
|
||||
inline void handle_callbacks(osg::Node& node)
|
||||
{
|
||||
osg::NodeCallback* callback = node.getAppCallback();
|
||||
if (callback) (*callback)(&node,this);
|
||||
else if (node.getNumChildrenRequiringAppTraversal()>0) traverse(node);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user