Added a Matrix::value_type typedef'd trait into osg::Matrix, defaulting its
value to float, and converted the internal code across to use value_type. This allows Matrix to be converted to use double's simply by change the definition of value_type. Added Matrix::glLoadlMatrix and Matrix::glMultMatrix() to help encapsulate the changes between float and double matrix usage. Updated code that uses Matrix so it doesn't assume float or double matrices.
This commit is contained in:
@@ -72,7 +72,7 @@ class CreateShadowTextureCullCallback : public osg::NodeCallback
|
||||
virtual void apply(osg::State& state) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glLoadMatrixf(_matrix.ptr());
|
||||
_matrix.glLoadMatrix();
|
||||
TexGen::apply(state);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -27,38 +27,33 @@ namespace osg {
|
||||
|
||||
class Quat;
|
||||
|
||||
class SG_EXPORT Matrixf
|
||||
class SG_EXPORT Matrix
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef float value_type;
|
||||
|
||||
Matrixf();
|
||||
|
||||
Matrixf( const Matrixf& other);
|
||||
|
||||
explicit Matrixf( float const * const def );
|
||||
|
||||
explicit Matrixf(double const * const ptr )
|
||||
{
|
||||
for(int i=0;i<16;++i)
|
||||
((float*)_mat)[i] = ptr[i];
|
||||
}
|
||||
inline Matrix() { makeIdentity(); }
|
||||
inline Matrix( const Matrix& other) { set(other.ptr()); }
|
||||
inline explicit Matrix( float const * const ptr ) { set(ptr); }
|
||||
inline explicit Matrix( double const * const ptr ) { set(ptr); }
|
||||
|
||||
Matrixf( 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( value_type a00, value_type a01, value_type a02, value_type a03,
|
||||
value_type a10, value_type a11, value_type a12, value_type a13,
|
||||
value_type a20, value_type a21, value_type a22, value_type a23,
|
||||
value_type a30, value_type a31, value_type a32, value_type a33);
|
||||
|
||||
~Matrixf() {}
|
||||
~Matrix() {}
|
||||
|
||||
int compare(const Matrixf& m) const { return memcmp(_mat,m._mat,sizeof(_mat)); }
|
||||
int compare(const Matrix& m) const { return memcmp(_mat,m._mat,sizeof(_mat)); }
|
||||
|
||||
bool operator < (const Matrixf& m) const { return compare(m)<0; }
|
||||
bool operator == (const Matrixf& m) const { return compare(m)==0; }
|
||||
bool operator != (const Matrixf& m) const { return compare(m)!=0; }
|
||||
bool operator < (const Matrix& m) const { return compare(m)<0; }
|
||||
bool operator == (const Matrix& m) const { return compare(m)==0; }
|
||||
bool operator != (const Matrix& m) const { return compare(m)!=0; }
|
||||
|
||||
inline float& operator()(int row, int col) { return _mat[row][col]; }
|
||||
inline float operator()(int row, int col) const { return _mat[row][col]; }
|
||||
inline value_type& operator()(int row, int col) { return _mat[row][col]; }
|
||||
inline value_type operator()(int row, int col) const { return _mat[row][col]; }
|
||||
|
||||
inline bool valid() const { return !isNaN(); }
|
||||
inline bool isNaN() const { return osg::isNaN(_mat[0][0]) || osg::isNaN(_mat[0][1]) || osg::isNaN(_mat[0][2]) || osg::isNaN(_mat[0][3]) ||
|
||||
@@ -66,40 +61,43 @@ class SG_EXPORT Matrixf
|
||||
osg::isNaN(_mat[2][0]) || osg::isNaN(_mat[2][1]) || osg::isNaN(_mat[2][2]) || osg::isNaN(_mat[2][3]) ||
|
||||
osg::isNaN(_mat[3][0]) || osg::isNaN(_mat[3][1]) || osg::isNaN(_mat[3][2]) || osg::isNaN(_mat[3][3]); }
|
||||
|
||||
|
||||
|
||||
inline Matrixf& operator = (const Matrixf& other)
|
||||
inline Matrix& operator = (const Matrix& other)
|
||||
{
|
||||
if( &other == this ) return *this;
|
||||
std::copy((float*)other._mat,(float*)other._mat+16,(float*)(_mat));
|
||||
set(other.ptr());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void set(const Matrixf& other)
|
||||
inline void set(const Matrix& other)
|
||||
{
|
||||
std::copy((float*)other._mat,(float*)other._mat+16,(float*)(_mat));
|
||||
set(other.ptr());
|
||||
}
|
||||
|
||||
inline void set(float const * const ptr)
|
||||
{
|
||||
std::copy(ptr,ptr+16,(float*)(_mat));
|
||||
std::copy(ptr,ptr+16,(value_type*)_mat);
|
||||
}
|
||||
|
||||
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);
|
||||
inline void set(double const * const ptr)
|
||||
{
|
||||
std::copy(ptr,ptr+16,(value_type*)_mat);
|
||||
}
|
||||
|
||||
void set( value_type a00, value_type a01, value_type a02, value_type a03,
|
||||
value_type a10, value_type a11, value_type a12, value_type a13,
|
||||
value_type a20, value_type a21, value_type a22, value_type a23,
|
||||
value_type a30, value_type a31, value_type a32, value_type a33);
|
||||
|
||||
float * ptr() { return (float *)_mat; }
|
||||
const float * ptr() const { return (const float *)_mat; }
|
||||
value_type * ptr() { return (value_type*)_mat; }
|
||||
const value_type * ptr() const { return (const value_type *)_mat; }
|
||||
|
||||
void makeIdentity();
|
||||
|
||||
void makeScale( const Vec3& );
|
||||
void makeScale( float, float, float );
|
||||
void makeScale( value_type, value_type, value_type );
|
||||
|
||||
void makeTranslate( const Vec3& );
|
||||
void makeTranslate( float, float, float );
|
||||
void makeTranslate( value_type, value_type, value_type );
|
||||
|
||||
void makeRotate( const Vec3& from, const Vec3& to );
|
||||
void makeRotate( float angle, const Vec3& axis );
|
||||
@@ -152,44 +150,44 @@ class SG_EXPORT Matrixf
|
||||
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
|
||||
void getLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance=1.0f);
|
||||
|
||||
bool invert( const Matrixf& );
|
||||
bool invert( const Matrix& );
|
||||
|
||||
//basic utility functions to create new matrices
|
||||
inline static Matrixf identity( void );
|
||||
inline static Matrixf scale( const Vec3& sv);
|
||||
inline static Matrixf scale( float sx, float sy, float sz);
|
||||
inline static Matrixf translate( const Vec3& dv);
|
||||
inline static Matrixf translate( float x, float y, float z);
|
||||
inline static Matrixf rotate( const Vec3& from, const Vec3& to);
|
||||
inline static Matrixf rotate( float angle, float x, float y, float z);
|
||||
inline static Matrixf rotate( float angle, const Vec3& axis);
|
||||
inline static Matrixf rotate( float angle1, const Vec3& axis1,
|
||||
inline static Matrix identity( void );
|
||||
inline static Matrix scale( const Vec3& sv);
|
||||
inline static Matrix scale( value_type sx, value_type sy, value_type sz);
|
||||
inline static Matrix translate( const Vec3& dv);
|
||||
inline static Matrix translate( value_type x, value_type y, value_type z);
|
||||
inline static Matrix rotate( const Vec3& from, const Vec3& to);
|
||||
inline static Matrix rotate( float angle, float x, float y, float z);
|
||||
inline static Matrix rotate( float angle, const Vec3& axis);
|
||||
inline static Matrix rotate( float angle1, const Vec3& axis1,
|
||||
float angle2, const Vec3& axis2,
|
||||
float angle3, const Vec3& axis3);
|
||||
inline static Matrixf rotate( const Quat& quat);
|
||||
inline static Matrixf inverse( const Matrixf& matrix);
|
||||
inline static Matrix rotate( const Quat& quat);
|
||||
inline static Matrix inverse( const Matrix& matrix);
|
||||
|
||||
/** Create a orthographic projection. See glOrtho for further details.*/
|
||||
inline static Matrixf ortho(double left, double right,
|
||||
inline static Matrix ortho(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar);
|
||||
|
||||
/** Create a 2D orthographic projection. See glOrtho for further details.*/
|
||||
inline static Matrixf ortho2D(double left, double right,
|
||||
inline static Matrix ortho2D(double left, double right,
|
||||
double bottom, double top);
|
||||
|
||||
/** Create a perspective projection. See glFrustum for further details.*/
|
||||
inline static Matrixf frustum(double left, double right,
|
||||
inline static Matrix frustum(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar);
|
||||
|
||||
/** Create a symmetrical perspective projection, See gluPerspective for further details.
|
||||
* Aspect ratio is defined as width/height.*/
|
||||
inline static Matrixf perspective(double fovy,double aspectRatio,
|
||||
inline static Matrix perspective(double fovy,double aspectRatio,
|
||||
double zNear, double zFar);
|
||||
|
||||
/** Create the position and orientation as per a camera, using the same convention as gluLookAt. */
|
||||
inline static Matrixf lookAt(const Vec3& eye,const Vec3& center,const Vec3& up);
|
||||
inline static Matrix lookAt(const Vec3& eye,const Vec3& center,const Vec3& up);
|
||||
|
||||
|
||||
|
||||
@@ -201,34 +199,34 @@ class SG_EXPORT Matrixf
|
||||
inline Vec4 postMult( const Vec4& v ) const;
|
||||
inline Vec4 operator* ( const Vec4& v ) const;
|
||||
|
||||
void setTrans( float tx, float ty, float tz );
|
||||
void setTrans( value_type tx, value_type ty, value_type tz );
|
||||
void setTrans( const Vec3& v );
|
||||
inline Vec3 getTrans() const { return Vec3(_mat[3][0],_mat[3][1],_mat[3][2]); }
|
||||
|
||||
inline Vec3 getScale() const { return Vec3(_mat[0][0],_mat[1][1],_mat[2][2]); }
|
||||
|
||||
/** apply apply an 3x3 transform of v*M[0..2,0..2] */
|
||||
inline static Vec3 transform3x3(const Vec3& v,const Matrixf& m);
|
||||
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 Matrixf& m,const Vec3& v);
|
||||
inline static Vec3 transform3x3(const Matrix& m,const Vec3& v);
|
||||
|
||||
|
||||
// basic Matrix multiplication, our workhorse methods.
|
||||
void mult( const Matrixf&, const Matrixf& );
|
||||
void preMult( const Matrixf& );
|
||||
void postMult( const Matrixf& );
|
||||
void mult( const Matrix&, const Matrix& );
|
||||
void preMult( const Matrix& );
|
||||
void postMult( const Matrix& );
|
||||
|
||||
inline void operator *= ( const Matrixf& other )
|
||||
inline void operator *= ( const Matrix& other )
|
||||
{ if( this == &other ) {
|
||||
Matrixf temp(other);
|
||||
Matrix temp(other);
|
||||
postMult( temp );
|
||||
}
|
||||
else postMult( other );
|
||||
}
|
||||
|
||||
inline Matrixf operator * ( const Matrixf &m ) const
|
||||
inline Matrix operator * ( const Matrix &m ) const
|
||||
{
|
||||
osg::Matrixf r;
|
||||
osg::Matrix r;
|
||||
r.mult(*this,m);
|
||||
return r;
|
||||
}
|
||||
@@ -240,12 +238,10 @@ class SG_EXPORT Matrixf
|
||||
void glMultMatrix() const;
|
||||
|
||||
protected:
|
||||
float _mat[4][4];
|
||||
value_type _mat[4][4];
|
||||
|
||||
};
|
||||
|
||||
typedef Matrixf Matrix;
|
||||
|
||||
class RefMatrix : public Object, public Matrix
|
||||
{
|
||||
public:
|
||||
@@ -284,7 +280,7 @@ inline Matrix Matrix::identity(void)
|
||||
return m;
|
||||
}
|
||||
|
||||
inline Matrix Matrix::scale(float sx, float sy, float sz)
|
||||
inline Matrix Matrix::scale(value_type sx, value_type sy, value_type sz)
|
||||
{
|
||||
Matrix m;
|
||||
m.makeScale(sx,sy,sz);
|
||||
@@ -296,7 +292,7 @@ inline Matrix Matrix::scale(const Vec3& v )
|
||||
return scale(v.x(), v.y(), v.z() );
|
||||
}
|
||||
|
||||
inline Matrix Matrix::translate(float tx, float ty, float tz)
|
||||
inline Matrix Matrix::translate(value_type tx, value_type ty, value_type tz)
|
||||
{
|
||||
Matrix m;
|
||||
m.makeTranslate(tx,ty,tz);
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace osgUtil {
|
||||
class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStack
|
||||
{
|
||||
public:
|
||||
|
||||
typedef osg::Matrix::value_type value_type;
|
||||
|
||||
|
||||
CullVisitor();
|
||||
virtual ~CullVisitor();
|
||||
@@ -215,9 +218,6 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
osg::State* getState() { return _state.get(); }
|
||||
const osg::State* getState() const { return _state.get(); }
|
||||
|
||||
typedef double NearFarReal;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// /** prevent unwanted copy construction.*/
|
||||
@@ -253,9 +253,9 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
|
||||
ComputeNearFarMode _computeNearFar;
|
||||
|
||||
NearFarReal _nearFarRatio;
|
||||
NearFarReal _computed_znear;
|
||||
NearFarReal _computed_zfar;
|
||||
value_type _nearFarRatio;
|
||||
value_type _computed_znear;
|
||||
value_type _computed_zfar;
|
||||
|
||||
osg::ref_ptr<const osg::ClearNode> _clearNode;
|
||||
|
||||
|
||||
@@ -34,28 +34,10 @@ using namespace osg;
|
||||
+((a)._mat[r][3] * (b)._mat[3][c])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Matrixf::Matrixf()
|
||||
{
|
||||
makeIdentity();
|
||||
}
|
||||
|
||||
Matrixf::Matrixf( const Matrixf& other)
|
||||
{
|
||||
set( (const float *) other._mat );
|
||||
}
|
||||
|
||||
Matrixf::Matrixf( const float * const def )
|
||||
{
|
||||
set( def );
|
||||
}
|
||||
|
||||
Matrixf::Matrixf( 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::Matrix( value_type a00, value_type a01, value_type a02, value_type a03,
|
||||
value_type a10, value_type a11, value_type a12, value_type a13,
|
||||
value_type a20, value_type a21, value_type a22, value_type a23,
|
||||
value_type a30, value_type a31, value_type a32, value_type a33)
|
||||
{
|
||||
SET_ROW(0, a00, a01, a02, a03 )
|
||||
SET_ROW(1, a10, a11, a12, a13 )
|
||||
@@ -63,10 +45,10 @@ Matrixf::Matrixf( float a00, float a01, float a02, float a03,
|
||||
SET_ROW(3, a30, a31, a32, a33 )
|
||||
}
|
||||
|
||||
void Matrixf::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 Matrix::set( value_type a00, value_type a01, value_type a02, value_type a03,
|
||||
value_type a10, value_type a11, value_type a12, value_type a13,
|
||||
value_type a20, value_type a21, value_type a22, value_type a23,
|
||||
value_type a30, value_type a31, value_type a32, value_type a33)
|
||||
{
|
||||
SET_ROW(0, a00, a01, a02, a03 )
|
||||
SET_ROW(1, a10, a11, a12, a13 )
|
||||
@@ -74,7 +56,7 @@ void Matrixf::set( float a00, float a01, float a02, float a03,
|
||||
SET_ROW(3, a30, a31, a32, a33 )
|
||||
}
|
||||
|
||||
void Matrixf::setTrans( float tx, float ty, float tz )
|
||||
void Matrix::setTrans( value_type tx, value_type ty, value_type tz )
|
||||
{
|
||||
_mat[3][0] = tx;
|
||||
_mat[3][1] = ty;
|
||||
@@ -82,14 +64,14 @@ void Matrixf::setTrans( float tx, float ty, float tz )
|
||||
}
|
||||
|
||||
|
||||
void Matrixf::setTrans( const Vec3& v )
|
||||
void Matrix::setTrans( const Vec3& v )
|
||||
{
|
||||
_mat[3][0] = v[0];
|
||||
_mat[3][1] = v[1];
|
||||
_mat[3][2] = v[2];
|
||||
}
|
||||
|
||||
void Matrixf::makeIdentity()
|
||||
void Matrix::makeIdentity()
|
||||
{
|
||||
SET_ROW(0, 1, 0, 0, 0 )
|
||||
SET_ROW(1, 0, 1, 0, 0 )
|
||||
@@ -97,12 +79,12 @@ void Matrixf::makeIdentity()
|
||||
SET_ROW(3, 0, 0, 0, 1 )
|
||||
}
|
||||
|
||||
void Matrixf::makeScale( const Vec3& v )
|
||||
void Matrix::makeScale( const Vec3& v )
|
||||
{
|
||||
makeScale(v[0], v[1], v[2] );
|
||||
}
|
||||
|
||||
void Matrixf::makeScale( float x, float y, float z )
|
||||
void Matrix::makeScale( value_type x, value_type y, value_type z )
|
||||
{
|
||||
SET_ROW(0, x, 0, 0, 0 )
|
||||
SET_ROW(1, 0, y, 0, 0 )
|
||||
@@ -110,12 +92,12 @@ void Matrixf::makeScale( float x, float y, float z )
|
||||
SET_ROW(3, 0, 0, 0, 1 )
|
||||
}
|
||||
|
||||
void Matrixf::makeTranslate( const Vec3& v )
|
||||
void Matrix::makeTranslate( const Vec3& v )
|
||||
{
|
||||
makeTranslate( v[0], v[1], v[2] );
|
||||
}
|
||||
|
||||
void Matrixf::makeTranslate( float x, float y, float z )
|
||||
void Matrix::makeTranslate( value_type x, value_type y, value_type z )
|
||||
{
|
||||
SET_ROW(0, 1, 0, 0, 0 )
|
||||
SET_ROW(1, 0, 1, 0, 0 )
|
||||
@@ -123,33 +105,33 @@ void Matrixf::makeTranslate( float x, float y, float z )
|
||||
SET_ROW(3, x, y, z, 1 )
|
||||
}
|
||||
|
||||
void Matrixf::makeRotate( const Vec3& from, const Vec3& to )
|
||||
void Matrix::makeRotate( const Vec3& from, const Vec3& to )
|
||||
{
|
||||
Quat quat;
|
||||
quat.makeRotate(from,to);
|
||||
quat.get(*this);
|
||||
}
|
||||
|
||||
void Matrixf::makeRotate( float angle, const Vec3& axis )
|
||||
void Matrix::makeRotate( float angle, const Vec3& axis )
|
||||
{
|
||||
Quat quat;
|
||||
quat.makeRotate( angle, axis);
|
||||
quat.get(*this);
|
||||
}
|
||||
|
||||
void Matrixf::makeRotate( float angle, float x, float y, float z )
|
||||
void Matrix::makeRotate( float angle, float x, float y, float z )
|
||||
{
|
||||
Quat quat;
|
||||
quat.makeRotate( angle, x, y, z);
|
||||
quat.get(*this);
|
||||
}
|
||||
|
||||
void Matrixf::makeRotate( const Quat& q )
|
||||
void Matrix::makeRotate( const Quat& q )
|
||||
{
|
||||
q.get(*this);
|
||||
}
|
||||
|
||||
void Matrixf::makeRotate( float angle1, const Vec3& axis1,
|
||||
void Matrix::makeRotate( float angle1, const Vec3& axis1,
|
||||
float angle2, const Vec3& axis2,
|
||||
float angle3, const Vec3& axis3)
|
||||
{
|
||||
@@ -160,7 +142,7 @@ void Matrixf::makeRotate( float angle1, const Vec3& axis1,
|
||||
quat.get(*this);
|
||||
}
|
||||
|
||||
void Matrixf::mult( const Matrix& lhs, const Matrix& rhs )
|
||||
void Matrix::mult( const Matrix& lhs, const Matrix& rhs )
|
||||
{
|
||||
if (&lhs==this)
|
||||
{
|
||||
@@ -193,7 +175,7 @@ void Matrixf::mult( const Matrix& lhs, const Matrix& rhs )
|
||||
_mat[3][3] = INNER_PRODUCT(lhs, rhs, 3, 3);
|
||||
}
|
||||
|
||||
void Matrixf::preMult( const Matrix& other )
|
||||
void Matrix::preMult( const Matrix& other )
|
||||
{
|
||||
// brute force method requiring a copy
|
||||
//Matrix tmp(other* *this);
|
||||
@@ -214,7 +196,7 @@ void Matrixf::preMult( const Matrix& other )
|
||||
|
||||
}
|
||||
|
||||
void Matrixf::postMult( const Matrix& other )
|
||||
void Matrix::postMult( const Matrix& other )
|
||||
{
|
||||
// brute force method requiring a copy
|
||||
//Matrix tmp(*this * other);
|
||||
@@ -245,7 +227,7 @@ inline T SGL_ABS(T a)
|
||||
#define SGL_SWAP(a,b,temp) ((temp)=(a),(a)=(b),(b)=(temp))
|
||||
#endif
|
||||
|
||||
bool Matrixf::invert( const Matrix& mat )
|
||||
bool Matrix::invert( const Matrix& mat )
|
||||
{
|
||||
if (&mat==this) {
|
||||
Matrix tm(mat);
|
||||
@@ -314,7 +296,7 @@ bool Matrixf::invert( const Matrix& mat )
|
||||
return true;
|
||||
}
|
||||
|
||||
void Matrixf::makeOrtho(double left, double right,
|
||||
void Matrix::makeOrtho(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
@@ -328,7 +310,7 @@ void Matrixf::makeOrtho(double left, double right,
|
||||
SET_ROW(3, tx, ty, tz, 1.0f )
|
||||
}
|
||||
|
||||
void Matrixf::getOrtho(double& left, double& right,
|
||||
void Matrix::getOrtho(double& left, double& right,
|
||||
double& bottom, double& top,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
@@ -343,7 +325,7 @@ void Matrixf::getOrtho(double& left, double& right,
|
||||
}
|
||||
|
||||
|
||||
void Matrixf::makeFrustum(double left, double right,
|
||||
void Matrix::makeFrustum(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
@@ -358,7 +340,7 @@ void Matrixf::makeFrustum(double left, double right,
|
||||
SET_ROW(3, 0.0f, 0.0f, D, 0.0f )
|
||||
}
|
||||
|
||||
void Matrixf::getFrustum(double& left, double& right,
|
||||
void Matrix::getFrustum(double& left, double& right,
|
||||
double& bottom, double& top,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
@@ -373,7 +355,7 @@ void Matrixf::getFrustum(double& left, double& right,
|
||||
}
|
||||
|
||||
|
||||
void Matrixf::makePerspective(double fovy,double aspectRatio,
|
||||
void Matrix::makePerspective(double fovy,double aspectRatio,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
// calculate the appropriate left, right etc.
|
||||
@@ -386,7 +368,7 @@ void Matrixf::makePerspective(double fovy,double aspectRatio,
|
||||
}
|
||||
|
||||
|
||||
void Matrixf::makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
|
||||
void Matrix::makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
|
||||
{
|
||||
Vec3 f(center-eye);
|
||||
f.normalize();
|
||||
@@ -401,10 +383,10 @@ void Matrixf::makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
|
||||
s[2], u[2], -f[2], 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
preMult(Matrixf::translate(-eye));
|
||||
preMult(Matrix::translate(-eye));
|
||||
}
|
||||
|
||||
void Matrixf::getLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance)
|
||||
void Matrix::getLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance)
|
||||
{
|
||||
Matrix inv;
|
||||
inv.invert(*this);
|
||||
@@ -415,13 +397,18 @@ void Matrixf::getLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance)
|
||||
center = eye + center*lookDistance;
|
||||
}
|
||||
|
||||
void Matrixf::glLoadMatrix() const
|
||||
void my_glLoadMatrix(float* mat) { glLoadMatrixf((GLfloat*)mat); }
|
||||
void my_glLoadMatrix(double* mat) { glLoadMatrixd((GLdouble*)mat); }
|
||||
void my_glMultMatrix(float* mat) { glMultMatrixf((GLfloat*)mat); }
|
||||
void my_glMultMatrix(double* mat) { glMultMatrixd((GLdouble*)mat); }
|
||||
|
||||
void Matrix::glLoadMatrix() const
|
||||
{
|
||||
glLoadMatrixf((GLfloat*)_mat);
|
||||
my_glLoadMatrix((value_type*)_mat);
|
||||
}
|
||||
|
||||
void Matrixf::glMultMatrix() const
|
||||
void Matrix::glMultMatrix() const
|
||||
{
|
||||
glMultMatrixf((GLfloat*)_mat);
|
||||
my_glMultMatrix((value_type*)_mat);
|
||||
}
|
||||
#undef SET_ROW
|
||||
|
||||
@@ -41,12 +41,12 @@ void osgParticle::FluidFrictionOperator::operate(Particle *P, double dt)
|
||||
Fr = current_program_->rotateLocalToWorld(Fr);
|
||||
}
|
||||
|
||||
// correct unwanted velocity increments
|
||||
osg::Vec3 dv = Fr * P->getMassInv() * dt;
|
||||
float dvl = dv.length();
|
||||
if (dvl > vm) {
|
||||
dv *= vm / dvl;
|
||||
}
|
||||
// correct unwanted velocity increments
|
||||
osg::Vec3 dv = Fr * P->getMassInv() * dt;
|
||||
float dvl = dv.length();
|
||||
if (dvl > vm) {
|
||||
dv *= vm / dvl;
|
||||
}
|
||||
|
||||
P->addVelocity(dv);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ osgParticle::Particle::Particle()
|
||||
prev_pos_(0, 0, 0),
|
||||
position_(0, 0, 0),
|
||||
velocity_(0, 0, 0),
|
||||
prev_angle_(0, 0, 0),
|
||||
angle_(0, 0, 0),
|
||||
angular_vel_(0, 0, 0),
|
||||
prev_angle_(0, 0, 0),
|
||||
angle_(0, 0, 0),
|
||||
angular_vel_(0, 0, 0),
|
||||
t0_(0),
|
||||
current_size_(0),
|
||||
current_alpha_(0)
|
||||
@@ -78,16 +78,16 @@ bool osgParticle::Particle::update(double dt)
|
||||
prev_pos_ = position_;
|
||||
position_ += velocity_ * dt;
|
||||
|
||||
// update angle
|
||||
prev_angle_ = angle_;
|
||||
angle_ += angular_vel_ * dt;
|
||||
// update angle
|
||||
prev_angle_ = angle_;
|
||||
angle_ += angular_vel_ * dt;
|
||||
|
||||
if (angle_.x() > osg::PI*2) angle_.x() -= osg::PI*2;
|
||||
if (angle_.x() < -osg::PI*2) angle_.x() += osg::PI*2;
|
||||
if (angle_.y() > osg::PI*2) angle_.y() -= osg::PI*2;
|
||||
if (angle_.y() < -osg::PI*2) angle_.y() += osg::PI*2;
|
||||
if (angle_.z() > osg::PI*2) angle_.z() -= osg::PI*2;
|
||||
if (angle_.z() < -osg::PI*2) angle_.z() += osg::PI*2;
|
||||
if (angle_.x() > osg::PI*2) angle_.x() -= osg::PI*2;
|
||||
if (angle_.x() < -osg::PI*2) angle_.x() += osg::PI*2;
|
||||
if (angle_.y() > osg::PI*2) angle_.y() -= osg::PI*2;
|
||||
if (angle_.y() < -osg::PI*2) angle_.y() += osg::PI*2;
|
||||
if (angle_.z() > osg::PI*2) angle_.z() -= osg::PI*2;
|
||||
if (angle_.z() < -osg::PI*2) angle_.z() += osg::PI*2;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -99,11 +99,11 @@ void osgParticle::Particle::render(const osg::Vec3 &xpos, const osg::Vec3 &px, c
|
||||
current_color_.z(),
|
||||
current_color_.w() * current_alpha_);
|
||||
|
||||
osg::Matrix R;
|
||||
R.makeRotate(
|
||||
angle_.x(), osg::Vec3(1, 0, 0),
|
||||
angle_.y(), osg::Vec3(0, 1, 0),
|
||||
angle_.z(), osg::Vec3(0, 0, 1));
|
||||
osg::Matrix R;
|
||||
R.makeRotate(
|
||||
angle_.x(), osg::Vec3(1, 0, 0),
|
||||
angle_.y(), osg::Vec3(0, 1, 0),
|
||||
angle_.z(), osg::Vec3(0, 0, 1));
|
||||
|
||||
osg::Vec3 p1(px * current_size_ * scale);
|
||||
osg::Vec3 p2(py * current_size_ * scale);
|
||||
@@ -126,10 +126,10 @@ void osgParticle::Particle::render(const osg::Vec3 &xpos, const osg::Vec3 &px, c
|
||||
break;
|
||||
|
||||
case QUAD_TRIANGLESTRIP:
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
glMultMatrixf(R.ptr());
|
||||
// we must glBegin() and glEnd() here, because each particle is a single strip
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
R.glMultMatrix();
|
||||
// we must glBegin() and glEnd() here, because each particle is a single strip
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3fv((p1+p2).ptr());
|
||||
@@ -140,13 +140,13 @@ void osgParticle::Particle::render(const osg::Vec3 &xpos, const osg::Vec3 &px, c
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3fv((-p1-p2).ptr());
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
break;
|
||||
|
||||
case HEXAGON:
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
glMultMatrixf(R.ptr());
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
R.glMultMatrix();
|
||||
// we must glBegin() and glEnd() here, because each particle is a single fan
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glTexCoord2f(0.5f, 0.5f);
|
||||
@@ -166,22 +166,22 @@ void osgParticle::Particle::render(const osg::Vec3 &xpos, const osg::Vec3 &px, c
|
||||
glTexCoord2f(hex_texcoord_x1, hex_texcoord_y1);
|
||||
glVertex3fv((p1*cosPI3+p2*sinPI3).ptr());
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
break;
|
||||
|
||||
case LINE:
|
||||
case LINE:
|
||||
{
|
||||
// Get the normalized direction of the particle, to be used in the
|
||||
// calculation of one of the linesegment endpoints.
|
||||
float vl = velocity_.length();
|
||||
if (vl != 0) {
|
||||
osg::Vec3 v = velocity_ * current_size_ * scale / vl;
|
||||
float vl = velocity_.length();
|
||||
if (vl != 0) {
|
||||
osg::Vec3 v = velocity_ * current_size_ * scale / vl;
|
||||
|
||||
glTexCoord1f(0);
|
||||
glVertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
glTexCoord1f(1);
|
||||
glVertex3f(xpos.x() + v.x(), xpos.y() + v.y(), xpos.z() + v.z());
|
||||
}
|
||||
glTexCoord1f(0);
|
||||
glVertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
glTexCoord1f(1);
|
||||
glVertex3f(xpos.x() + v.x(), xpos.y() + v.y(), xpos.z() + v.z());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ osgParticle::ParticleProcessor::ParticleProcessor()
|
||||
need_ltw_matrix_(false),
|
||||
need_wtl_matrix_(false),
|
||||
current_nodevisitor_(0),
|
||||
endless_(true),
|
||||
lifeTime_(0.0),
|
||||
startTime_(0.0),
|
||||
currentTime_(0.0),
|
||||
resetTime_(0.0)
|
||||
endless_(true),
|
||||
lifeTime_(0.0),
|
||||
startTime_(0.0),
|
||||
currentTime_(0.0),
|
||||
resetTime_(0.0)
|
||||
{
|
||||
setCullingActive(false);
|
||||
}
|
||||
@@ -38,11 +38,11 @@ osgParticle::ParticleProcessor::ParticleProcessor(const ParticleProcessor ©,
|
||||
need_ltw_matrix_(copy.need_ltw_matrix_),
|
||||
need_wtl_matrix_(copy.need_wtl_matrix_),
|
||||
current_nodevisitor_(0),
|
||||
endless_(copy.endless_),
|
||||
lifeTime_(copy.lifeTime_),
|
||||
startTime_(copy.startTime_),
|
||||
currentTime_(copy.currentTime_),
|
||||
resetTime_(copy.resetTime_)
|
||||
endless_(copy.endless_),
|
||||
lifeTime_(copy.lifeTime_),
|
||||
startTime_(copy.startTime_),
|
||||
currentTime_(copy.currentTime_),
|
||||
resetTime_(copy.resetTime_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -64,30 +64,30 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor &nv)
|
||||
// retrieve the current time
|
||||
double t = nv.getFrameStamp()->getReferenceTime();
|
||||
|
||||
// reset this processor if we've reached the reset point
|
||||
if ((currentTime_ >= resetTime_) && (resetTime_ > 0)) {
|
||||
currentTime_ = 0;
|
||||
t0_ = -1;
|
||||
}
|
||||
// reset this processor if we've reached the reset point
|
||||
if ((currentTime_ >= resetTime_) && (resetTime_ > 0)) {
|
||||
currentTime_ = 0;
|
||||
t0_ = -1;
|
||||
}
|
||||
|
||||
// skip if we haven't initialized t0_ yet
|
||||
// skip if we haven't initialized t0_ yet
|
||||
if (t0_ != -1) {
|
||||
|
||||
// check whether the processor is alive
|
||||
bool alive = false;
|
||||
if (currentTime_ >= startTime_) {
|
||||
if (endless_ || (currentTime_ < (startTime_ + lifeTime_)))
|
||||
alive = true;
|
||||
}
|
||||
// check whether the processor is alive
|
||||
bool alive = false;
|
||||
if (currentTime_ >= startTime_) {
|
||||
if (endless_ || (currentTime_ < (startTime_ + lifeTime_)))
|
||||
alive = true;
|
||||
}
|
||||
|
||||
// update current time
|
||||
currentTime_ += t - t0_;
|
||||
// update current time
|
||||
currentTime_ += t - t0_;
|
||||
|
||||
// process only if the particle system is not frozen/culled
|
||||
if (alive &&
|
||||
enabled_ &&
|
||||
!ps_->isFrozen() &&
|
||||
(ps_->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps_->getFreezeOnCull())) {
|
||||
enabled_ &&
|
||||
!ps_->isFrozen() &&
|
||||
(ps_->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps_->getFreezeOnCull())) {
|
||||
|
||||
// initialize matrix flags
|
||||
need_ltw_matrix_ = true;
|
||||
|
||||
@@ -370,15 +370,20 @@ osg::Vec4Array* DataInputStream::readVec4Array(){
|
||||
return a;
|
||||
}
|
||||
|
||||
osg::Matrix DataInputStream::readMatrix(){
|
||||
osg::Matrix DataInputStream::readMatrix()
|
||||
{
|
||||
osg::Matrix mat;
|
||||
_istream->read((char*)(mat.ptr()), FLOATSIZE*16);
|
||||
for(int r=0;r<4;r++)
|
||||
{
|
||||
for(int c=0;c<4;c++)
|
||||
{
|
||||
mat(r,c) = readFloat();
|
||||
}
|
||||
}
|
||||
|
||||
if (_istream->rdstate() & _istream->failbit)
|
||||
throw Exception("DataInputStream::readMatrix(): Failed to read Matrix array.");
|
||||
// float* p = mat.ptr();
|
||||
// for(int i=0;i<16;i++){
|
||||
// p[i] = readFloat();
|
||||
// }
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
@@ -260,10 +260,14 @@ void DataOutputStream::writeVec4Array(osg::Vec4Array* a){
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeMatrix(osg::Matrix mat){
|
||||
float* p = mat.ptr();
|
||||
for(int i=0;i<16;i++){
|
||||
writeFloat(p[i]);
|
||||
void DataOutputStream::writeMatrix(const osg::Matrix& mat)
|
||||
{
|
||||
for(int r=0;r<4;r++)
|
||||
{
|
||||
for(int c=0;c<4;c++)
|
||||
{
|
||||
writeFloat(mat(r,c));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
void writeVec2Array(osg::Vec2Array* a);
|
||||
void writeVec3Array(osg::Vec3Array* a);
|
||||
void writeVec4Array(osg::Vec4Array* a);
|
||||
void writeMatrix(osg::Matrix mat);
|
||||
void writeMatrix(const osg::Matrix& mat);
|
||||
|
||||
void writeStateSet(osg::StateSet* stateset);
|
||||
void writeStateAttribute(osg::StateAttribute* sa);
|
||||
|
||||
@@ -43,11 +43,13 @@ bool DOFTransform_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
osg::Matrix matrix;
|
||||
int k=0;
|
||||
double v;
|
||||
for(int i=0;i<4;++i)
|
||||
{
|
||||
for(int j=0;j<4;++j)
|
||||
{
|
||||
fr[k].getFloat(matrix(i,j));
|
||||
fr[k].getDouble(v);
|
||||
matrix(i,j)=v;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,12 @@ bool readMatrix(osg::Matrix& matrix, osgDB::Input& fr)
|
||||
|
||||
int row=0;
|
||||
int col=0;
|
||||
double v;
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
||||
{
|
||||
if (fr[0].getFloat(matrix(row,col)))
|
||||
if (fr[0].getDouble(v))
|
||||
{
|
||||
matrix(row,col)=v;
|
||||
++col;
|
||||
if (col>=4)
|
||||
{
|
||||
|
||||
@@ -39,11 +39,13 @@ bool TexMat_readLocalData(Object& obj, Input& fr)
|
||||
Matrix& matrix = texmat.getMatrix();
|
||||
|
||||
int k=0;
|
||||
double v;
|
||||
for(int i=0;i<4;++i)
|
||||
{
|
||||
for(int j=0;j<4;++j)
|
||||
{
|
||||
fr[k].getFloat(matrix(i,j));
|
||||
fr[k].getDouble(v);
|
||||
matrix(i,j)=v;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,12 +153,12 @@ float CullVisitor::getDistanceToEyePoint(const Vec3& pos, bool withLODScale) con
|
||||
else return (pos-getEyeLocal()).length();
|
||||
}
|
||||
|
||||
inline CullVisitor::NearFarReal distance(const osg::Vec3& coord,const osg::Matrix& matrix)
|
||||
inline CullVisitor::value_type distance(const osg::Vec3& coord,const osg::Matrix& matrix)
|
||||
{
|
||||
|
||||
//std::cout << "distance("<<coord<<", "<<matrix<<")"<<std::endl;
|
||||
|
||||
return -((CullVisitor::NearFarReal)coord[0]*(CullVisitor::NearFarReal)matrix(0,2)+(CullVisitor::NearFarReal)coord[1]*(CullVisitor::NearFarReal)matrix(1,2)+(CullVisitor::NearFarReal)coord[2]*(CullVisitor::NearFarReal)matrix(2,2)+matrix(3,2));
|
||||
return -((CullVisitor::value_type)coord[0]*(CullVisitor::value_type)matrix(0,2)+(CullVisitor::value_type)coord[1]*(CullVisitor::value_type)matrix(1,2)+(CullVisitor::value_type)coord[2]*(CullVisitor::value_type)matrix(2,2)+matrix(3,2));
|
||||
}
|
||||
|
||||
float CullVisitor::getDistanceFromEyePoint(const osg::Vec3& pos, bool withLODScale) const
|
||||
@@ -184,9 +184,9 @@ void CullVisitor::popProjectionMatrix()
|
||||
{
|
||||
//std::cout << "Orthographic projection "<<projection<<std::endl;
|
||||
|
||||
NearFarReal span = (_computed_zfar-_computed_znear);
|
||||
NearFarReal desired_znear = _computed_znear - span*0.02f;
|
||||
NearFarReal desired_zfar = _computed_zfar + span*0.02f;
|
||||
value_type span = (_computed_zfar-_computed_znear);
|
||||
value_type desired_znear = _computed_znear - span*0.02f;
|
||||
value_type desired_zfar = _computed_zfar + span*0.02f;
|
||||
|
||||
// near plane clamping.
|
||||
//double min_near_plane = _computed_zfar*_nearFarRatio;
|
||||
@@ -212,10 +212,10 @@ void CullVisitor::popProjectionMatrix()
|
||||
//std::cout << "_computed_zfar"<<_computed_zfar<<std::endl;
|
||||
|
||||
|
||||
NearFarReal desired_znear = _computed_znear *0.98;
|
||||
NearFarReal desired_zfar = _computed_zfar *1.02;
|
||||
// NearFarReal desired_znear = _computed_znear *0.5;
|
||||
// NearFarReal desired_zfar = _computed_zfar *2.0;
|
||||
value_type desired_znear = _computed_znear *0.98;
|
||||
value_type desired_zfar = _computed_zfar *1.02;
|
||||
// value_type desired_znear = _computed_znear *0.5;
|
||||
// value_type desired_zfar = _computed_zfar *2.0;
|
||||
|
||||
// near plane clamping.
|
||||
double min_near_plane = _computed_zfar*_nearFarRatio;
|
||||
@@ -228,11 +228,11 @@ void CullVisitor::popProjectionMatrix()
|
||||
_computed_znear = desired_znear;
|
||||
_computed_zfar = desired_zfar;
|
||||
|
||||
NearFarReal trans_near_plane = (-desired_znear*projection(2,2)+projection(3,2))/(-desired_znear*projection(2,3)+projection(3,3));
|
||||
NearFarReal trans_far_plane = (-desired_zfar*projection(2,2)+projection(3,2))/(-desired_zfar*projection(2,3)+projection(3,3));
|
||||
value_type trans_near_plane = (-desired_znear*projection(2,2)+projection(3,2))/(-desired_znear*projection(2,3)+projection(3,3));
|
||||
value_type trans_far_plane = (-desired_zfar*projection(2,2)+projection(3,2))/(-desired_zfar*projection(2,3)+projection(3,3));
|
||||
|
||||
NearFarReal ratio = fabs(2.0/(trans_near_plane-trans_far_plane));
|
||||
NearFarReal center = -(trans_near_plane+trans_far_plane)/2.0;
|
||||
value_type ratio = fabs(2.0/(trans_near_plane-trans_far_plane));
|
||||
value_type center = -(trans_near_plane+trans_far_plane)/2.0;
|
||||
|
||||
projection.postMult(osg::Matrix(1.0f,0.0f,0.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,0.0f,
|
||||
@@ -248,7 +248,8 @@ void CullVisitor::popProjectionMatrix()
|
||||
|
||||
void CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::BoundingBox& bb)
|
||||
{
|
||||
|
||||
#if 0
|
||||
// brute force way, use all corners of the bounding box.
|
||||
updateCalculatedNearFar(bb.corner(0));
|
||||
updateCalculatedNearFar(bb.corner(1));
|
||||
updateCalculatedNearFar(bb.corner(2));
|
||||
@@ -257,28 +258,31 @@ void CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::B
|
||||
updateCalculatedNearFar(bb.corner(5));
|
||||
updateCalculatedNearFar(bb.corner(6));
|
||||
updateCalculatedNearFar(bb.corner(7));
|
||||
//
|
||||
// NearFarReal d_near = distance(bb.corner(_bbCornerNear),matrix);
|
||||
// NearFarReal d_far = distance(bb.corner(_bbCornerFar),matrix);
|
||||
//
|
||||
// if (d_near<=d_far)
|
||||
// {
|
||||
// if (d_near<_computed_znear) _computed_znear = d_near;
|
||||
// if (d_far>_computed_zfar) _computed_zfar = d_far;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if ( !EQUAL_F(d_near, d_far) )
|
||||
// {
|
||||
// osg::notify(osg::WARN)<<"Warning: CullVisitor::updateCalculatedNearFar(.) near>far in range calculation,"<< std::endl;
|
||||
// osg::notify(osg::WARN)<<" correcting by swapping values d_near="<<d_near<<" dfar="<<d_far<< std::endl;
|
||||
// }
|
||||
// // note, need to reverse the d_near/d_far association because they are
|
||||
// // the wrong way around...
|
||||
// if (d_far<_computed_znear) _computed_znear = d_far;
|
||||
// if (d_near>_computed_zfar) _computed_zfar = d_near;
|
||||
// }
|
||||
#else
|
||||
|
||||
// efficient computation of near and far, only taking into account the nearest and furthest
|
||||
// corners of the bounding box.
|
||||
value_type d_near = distance(bb.corner(_bbCornerNear),matrix);
|
||||
value_type d_far = distance(bb.corner(_bbCornerFar),matrix);
|
||||
|
||||
if (d_near<=d_far)
|
||||
{
|
||||
if (d_near<_computed_znear) _computed_znear = d_near;
|
||||
if (d_far>_computed_zfar) _computed_zfar = d_far;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !EQUAL_F(d_near, d_far) )
|
||||
{
|
||||
osg::notify(osg::WARN)<<"Warning: CullVisitor::updateCalculatedNearFar(.) near>far in range calculation,"<< std::endl;
|
||||
osg::notify(osg::WARN)<<" correcting by swapping values d_near="<<d_near<<" dfar="<<d_far<< std::endl;
|
||||
}
|
||||
// note, need to reverse the d_near/d_far association because they are
|
||||
// the wrong way around...
|
||||
if (d_far<_computed_znear) _computed_znear = d_far;
|
||||
if (d_near>_computed_zfar) _computed_zfar = d_near;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void CullVisitor::updateCalculatedNearFar(const osg::Vec3& pos)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user