Made Matrix a typedef to Matrixf, and converted the old Matrix to Matrixf, as
part of prep for supporting both Matrixf (float) and Matrixd (double). Added osg::Matrixf::glLoadMatrix() and osg::Matrixf::glMultiMatrix() methods and changed corresponding usage of glLoad/MultMatrixf() calls across to use these methods. Again prep for support Matrixd. Fixes for VisualStudio 6.0 compile.
This commit is contained in:
parent
f90e4ff5f8
commit
e530912744
@ -27,26 +27,35 @@ namespace osg {
|
||||
|
||||
class Quat;
|
||||
|
||||
class SG_EXPORT Matrix
|
||||
class SG_EXPORT Matrixf
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
Matrix();
|
||||
Matrix( const Matrix& other);
|
||||
explicit Matrix( float const * const def );
|
||||
Matrix( float a00, float a01, float a02, float a03,
|
||||
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];
|
||||
}
|
||||
|
||||
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() {}
|
||||
~Matrixf() {}
|
||||
|
||||
int compare(const Matrix& m) const { return memcmp(_mat,m._mat,sizeof(_mat)); }
|
||||
int compare(const Matrixf& m) const { return memcmp(_mat,m._mat,sizeof(_mat)); }
|
||||
|
||||
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; }
|
||||
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; }
|
||||
|
||||
inline float& operator()(int row, int col) { return _mat[row][col]; }
|
||||
inline float operator()(int row, int col) const { return _mat[row][col]; }
|
||||
@ -59,14 +68,14 @@ class SG_EXPORT Matrix
|
||||
|
||||
|
||||
|
||||
inline Matrix& operator = (const Matrix& other)
|
||||
inline Matrixf& operator = (const Matrixf& other)
|
||||
{
|
||||
if( &other == this ) return *this;
|
||||
std::copy((float*)other._mat,(float*)other._mat+16,(float*)(_mat));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void set(const Matrix& other)
|
||||
inline void set(const Matrixf& other)
|
||||
{
|
||||
std::copy((float*)other._mat,(float*)other._mat+16,(float*)(_mat));
|
||||
}
|
||||
@ -82,7 +91,7 @@ class SG_EXPORT Matrix
|
||||
float a30, float a31, float a32, float a33);
|
||||
|
||||
float * ptr() { return (float *)_mat; }
|
||||
float * ptr() const { return (float *)_mat; }
|
||||
const float * ptr() const { return (const float *)_mat; }
|
||||
|
||||
void makeIdentity();
|
||||
|
||||
@ -143,44 +152,44 @@ class SG_EXPORT Matrix
|
||||
/** 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 Matrix& );
|
||||
bool invert( const Matrixf& );
|
||||
|
||||
//basic utility functions to create new matrices
|
||||
inline static Matrix identity( void );
|
||||
inline static Matrix scale( const Vec3& sv);
|
||||
inline static Matrix scale( float sx, float sy, float sz);
|
||||
inline static Matrix translate( const Vec3& dv);
|
||||
inline static Matrix translate( float x, float y, float 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,
|
||||
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,
|
||||
float angle2, const Vec3& axis2,
|
||||
float angle3, const Vec3& axis3);
|
||||
inline static Matrix rotate( const Quat& quat);
|
||||
inline static Matrix inverse( const Matrix& matrix);
|
||||
inline static Matrixf rotate( const Quat& quat);
|
||||
inline static Matrixf inverse( const Matrixf& matrix);
|
||||
|
||||
/** Create a orthographic projection. See glOrtho for further details.*/
|
||||
inline static Matrix ortho(double left, double right,
|
||||
inline static Matrixf 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 Matrix ortho2D(double left, double right,
|
||||
inline static Matrixf ortho2D(double left, double right,
|
||||
double bottom, double top);
|
||||
|
||||
/** Create a perspective projection. See glFrustum for further details.*/
|
||||
inline static Matrix frustum(double left, double right,
|
||||
inline static Matrixf 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 Matrix perspective(double fovy,double aspectRatio,
|
||||
inline static Matrixf 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 Matrix lookAt(const Vec3& eye,const Vec3& center,const Vec3& up);
|
||||
inline static Matrixf lookAt(const Vec3& eye,const Vec3& center,const Vec3& up);
|
||||
|
||||
|
||||
|
||||
@ -199,36 +208,44 @@ class SG_EXPORT Matrix
|
||||
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 Matrix& m);
|
||||
inline static Vec3 transform3x3(const Vec3& v,const Matrixf& m);
|
||||
/** apply apply an 3x3 transform of M[0..2,0..2]*v */
|
||||
inline static Vec3 transform3x3(const Matrix& m,const Vec3& v);
|
||||
inline static Vec3 transform3x3(const Matrixf& m,const Vec3& v);
|
||||
|
||||
|
||||
// basic Matrix multiplication, our workhorse methods.
|
||||
void mult( const Matrix&, const Matrix& );
|
||||
void preMult( const Matrix& );
|
||||
void postMult( const Matrix& );
|
||||
void mult( const Matrixf&, const Matrixf& );
|
||||
void preMult( const Matrixf& );
|
||||
void postMult( const Matrixf& );
|
||||
|
||||
inline void operator *= ( const Matrix& other )
|
||||
inline void operator *= ( const Matrixf& other )
|
||||
{ if( this == &other ) {
|
||||
Matrix temp(other);
|
||||
Matrixf temp(other);
|
||||
postMult( temp );
|
||||
}
|
||||
else postMult( other );
|
||||
}
|
||||
|
||||
inline Matrix operator * ( const Matrix &m ) const
|
||||
inline Matrixf operator * ( const Matrixf &m ) const
|
||||
{
|
||||
osg::Matrix r;
|
||||
osg::Matrixf r;
|
||||
r.mult(*this,m);
|
||||
return r;
|
||||
}
|
||||
|
||||
/** call glLoadMatixf with this matrix.*/
|
||||
void glLoadMatrix() const;
|
||||
|
||||
/** call glMultMatixf with this matrix.*/
|
||||
void glMultMatrix() const;
|
||||
|
||||
protected:
|
||||
float _mat[4][4];
|
||||
|
||||
};
|
||||
|
||||
typedef Matrixf Matrix;
|
||||
|
||||
class RefMatrix : public Object, public Matrix
|
||||
{
|
||||
public:
|
||||
|
@ -100,7 +100,7 @@ class SG_EXPORT State : public Referenced
|
||||
if (matrix)
|
||||
{
|
||||
_projection=matrix;
|
||||
glLoadMatrixf(matrix->ptr());
|
||||
matrix->glLoadMatrix();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -123,7 +123,7 @@ class SG_EXPORT State : public Referenced
|
||||
if (matrix)
|
||||
{
|
||||
_modelView=matrix;
|
||||
glLoadMatrixf(matrix->ptr());
|
||||
matrix->glLoadMatrix();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -215,6 +215,7 @@ 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:
|
||||
@ -251,9 +252,10 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
RenderBin* _currentRenderBin;
|
||||
|
||||
ComputeNearFarMode _computeNearFar;
|
||||
float _nearFarRatio;
|
||||
float _computed_znear;
|
||||
float _computed_zfar;
|
||||
|
||||
NearFarReal _nearFarRatio;
|
||||
NearFarReal _computed_znear;
|
||||
NearFarReal _computed_zfar;
|
||||
|
||||
osg::ref_ptr<const osg::ClearNode> _clearNode;
|
||||
|
||||
|
@ -32,7 +32,7 @@ void ColorMatrix::apply(State&) const
|
||||
if (s_ARB_imaging)
|
||||
{
|
||||
glMatrixMode( GL_COLOR );
|
||||
glLoadMatrixf( _matrix.ptr() );
|
||||
_matrix.glLoadMatrix();
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ void FragmentProgram::apply(State& state) const
|
||||
++itr)
|
||||
{
|
||||
glMatrixMode((*itr).first);
|
||||
glLoadMatrixf((*itr).second.ptr());
|
||||
(*itr).second.glLoadMatrix();
|
||||
}
|
||||
glMatrixMode(GL_MODELVIEW); // restore matrix mode
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include <osg/Notify>
|
||||
#include <osg/Math>
|
||||
|
||||
#include <osg/GL>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace osg;
|
||||
@ -35,22 +37,22 @@ using namespace osg;
|
||||
|
||||
|
||||
|
||||
Matrix::Matrix()
|
||||
Matrixf::Matrixf()
|
||||
{
|
||||
makeIdentity();
|
||||
}
|
||||
|
||||
Matrix::Matrix( const Matrix& other)
|
||||
Matrixf::Matrixf( const Matrixf& other)
|
||||
{
|
||||
set( (const float *) other._mat );
|
||||
}
|
||||
|
||||
Matrix::Matrix( const float * const def )
|
||||
Matrixf::Matrixf( const float * const def )
|
||||
{
|
||||
set( def );
|
||||
}
|
||||
|
||||
Matrix::Matrix( float a00, float a01, float a02, float a03,
|
||||
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)
|
||||
@ -61,7 +63,7 @@ Matrix::Matrix( float a00, float a01, float a02, float a03,
|
||||
SET_ROW(3, a30, a31, a32, a33 )
|
||||
}
|
||||
|
||||
void Matrix::set( float a00, float a01, float a02, float a03,
|
||||
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)
|
||||
@ -72,7 +74,7 @@ void Matrix::set( float a00, float a01, float a02, float a03,
|
||||
SET_ROW(3, a30, a31, a32, a33 )
|
||||
}
|
||||
|
||||
void Matrix::setTrans( float tx, float ty, float tz )
|
||||
void Matrixf::setTrans( float tx, float ty, float tz )
|
||||
{
|
||||
_mat[3][0] = tx;
|
||||
_mat[3][1] = ty;
|
||||
@ -80,14 +82,14 @@ void Matrix::setTrans( float tx, float ty, float tz )
|
||||
}
|
||||
|
||||
|
||||
void Matrix::setTrans( const Vec3& v )
|
||||
void Matrixf::setTrans( const Vec3& v )
|
||||
{
|
||||
_mat[3][0] = v[0];
|
||||
_mat[3][1] = v[1];
|
||||
_mat[3][2] = v[2];
|
||||
}
|
||||
|
||||
void Matrix::makeIdentity()
|
||||
void Matrixf::makeIdentity()
|
||||
{
|
||||
SET_ROW(0, 1, 0, 0, 0 )
|
||||
SET_ROW(1, 0, 1, 0, 0 )
|
||||
@ -95,12 +97,12 @@ void Matrix::makeIdentity()
|
||||
SET_ROW(3, 0, 0, 0, 1 )
|
||||
}
|
||||
|
||||
void Matrix::makeScale( const Vec3& v )
|
||||
void Matrixf::makeScale( const Vec3& v )
|
||||
{
|
||||
makeScale(v[0], v[1], v[2] );
|
||||
}
|
||||
|
||||
void Matrix::makeScale( float x, float y, float z )
|
||||
void Matrixf::makeScale( float x, float y, float z )
|
||||
{
|
||||
SET_ROW(0, x, 0, 0, 0 )
|
||||
SET_ROW(1, 0, y, 0, 0 )
|
||||
@ -108,12 +110,12 @@ void Matrix::makeScale( float x, float y, float z )
|
||||
SET_ROW(3, 0, 0, 0, 1 )
|
||||
}
|
||||
|
||||
void Matrix::makeTranslate( const Vec3& v )
|
||||
void Matrixf::makeTranslate( const Vec3& v )
|
||||
{
|
||||
makeTranslate( v[0], v[1], v[2] );
|
||||
}
|
||||
|
||||
void Matrix::makeTranslate( float x, float y, float z )
|
||||
void Matrixf::makeTranslate( float x, float y, float z )
|
||||
{
|
||||
SET_ROW(0, 1, 0, 0, 0 )
|
||||
SET_ROW(1, 0, 1, 0, 0 )
|
||||
@ -121,33 +123,33 @@ void Matrix::makeTranslate( float x, float y, float z )
|
||||
SET_ROW(3, x, y, z, 1 )
|
||||
}
|
||||
|
||||
void Matrix::makeRotate( const Vec3& from, const Vec3& to )
|
||||
void Matrixf::makeRotate( const Vec3& from, const Vec3& to )
|
||||
{
|
||||
Quat quat;
|
||||
quat.makeRotate(from,to);
|
||||
quat.get(*this);
|
||||
}
|
||||
|
||||
void Matrix::makeRotate( float angle, const Vec3& axis )
|
||||
void Matrixf::makeRotate( float angle, const Vec3& axis )
|
||||
{
|
||||
Quat quat;
|
||||
quat.makeRotate( angle, axis);
|
||||
quat.get(*this);
|
||||
}
|
||||
|
||||
void Matrix::makeRotate( float angle, float x, float y, float z )
|
||||
void Matrixf::makeRotate( float angle, float x, float y, float z )
|
||||
{
|
||||
Quat quat;
|
||||
quat.makeRotate( angle, x, y, z);
|
||||
quat.get(*this);
|
||||
}
|
||||
|
||||
void Matrix::makeRotate( const Quat& q )
|
||||
void Matrixf::makeRotate( const Quat& q )
|
||||
{
|
||||
q.get(*this);
|
||||
}
|
||||
|
||||
void Matrix::makeRotate( float angle1, const Vec3& axis1,
|
||||
void Matrixf::makeRotate( float angle1, const Vec3& axis1,
|
||||
float angle2, const Vec3& axis2,
|
||||
float angle3, const Vec3& axis3)
|
||||
{
|
||||
@ -158,7 +160,7 @@ void Matrix::makeRotate( float angle1, const Vec3& axis1,
|
||||
quat.get(*this);
|
||||
}
|
||||
|
||||
void Matrix::mult( const Matrix& lhs, const Matrix& rhs )
|
||||
void Matrixf::mult( const Matrix& lhs, const Matrix& rhs )
|
||||
{
|
||||
if (&lhs==this)
|
||||
{
|
||||
@ -191,7 +193,7 @@ void Matrix::mult( const Matrix& lhs, const Matrix& rhs )
|
||||
_mat[3][3] = INNER_PRODUCT(lhs, rhs, 3, 3);
|
||||
}
|
||||
|
||||
void Matrix::preMult( const Matrix& other )
|
||||
void Matrixf::preMult( const Matrix& other )
|
||||
{
|
||||
// brute force method requiring a copy
|
||||
//Matrix tmp(other* *this);
|
||||
@ -212,7 +214,7 @@ void Matrix::preMult( const Matrix& other )
|
||||
|
||||
}
|
||||
|
||||
void Matrix::postMult( const Matrix& other )
|
||||
void Matrixf::postMult( const Matrix& other )
|
||||
{
|
||||
// brute force method requiring a copy
|
||||
//Matrix tmp(*this * other);
|
||||
@ -243,7 +245,7 @@ inline T SGL_ABS(T a)
|
||||
#define SGL_SWAP(a,b,temp) ((temp)=(a),(a)=(b),(b)=(temp))
|
||||
#endif
|
||||
|
||||
bool Matrix::invert( const Matrix& mat )
|
||||
bool Matrixf::invert( const Matrix& mat )
|
||||
{
|
||||
if (&mat==this) {
|
||||
Matrix tm(mat);
|
||||
@ -312,7 +314,7 @@ bool Matrix::invert( const Matrix& mat )
|
||||
return true;
|
||||
}
|
||||
|
||||
void Matrix::makeOrtho(double left, double right,
|
||||
void Matrixf::makeOrtho(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
@ -326,7 +328,7 @@ void Matrix::makeOrtho(double left, double right,
|
||||
SET_ROW(3, tx, ty, tz, 1.0f )
|
||||
}
|
||||
|
||||
void Matrix::getOrtho(double& left, double& right,
|
||||
void Matrixf::getOrtho(double& left, double& right,
|
||||
double& bottom, double& top,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
@ -341,7 +343,7 @@ void Matrix::getOrtho(double& left, double& right,
|
||||
}
|
||||
|
||||
|
||||
void Matrix::makeFrustum(double left, double right,
|
||||
void Matrixf::makeFrustum(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
@ -356,7 +358,7 @@ void Matrix::makeFrustum(double left, double right,
|
||||
SET_ROW(3, 0.0f, 0.0f, D, 0.0f )
|
||||
}
|
||||
|
||||
void Matrix::getFrustum(double& left, double& right,
|
||||
void Matrixf::getFrustum(double& left, double& right,
|
||||
double& bottom, double& top,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
@ -371,7 +373,7 @@ void Matrix::getFrustum(double& left, double& right,
|
||||
}
|
||||
|
||||
|
||||
void Matrix::makePerspective(double fovy,double aspectRatio,
|
||||
void Matrixf::makePerspective(double fovy,double aspectRatio,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
// calculate the appropriate left, right etc.
|
||||
@ -384,7 +386,7 @@ void Matrix::makePerspective(double fovy,double aspectRatio,
|
||||
}
|
||||
|
||||
|
||||
void Matrix::makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
|
||||
void Matrixf::makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
|
||||
{
|
||||
Vec3 f(center-eye);
|
||||
f.normalize();
|
||||
@ -399,10 +401,10 @@ void Matrix::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(Matrix::translate(-eye));
|
||||
preMult(Matrixf::translate(-eye));
|
||||
}
|
||||
|
||||
void Matrix::getLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance)
|
||||
void Matrixf::getLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance)
|
||||
{
|
||||
Matrix inv;
|
||||
inv.invert(*this);
|
||||
@ -413,4 +415,13 @@ void Matrix::getLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance)
|
||||
center = eye + center*lookDistance;
|
||||
}
|
||||
|
||||
void Matrixf::glLoadMatrix() const
|
||||
{
|
||||
glLoadMatrixf((GLfloat*)_mat);
|
||||
}
|
||||
|
||||
void Matrixf::glMultMatrix() const
|
||||
{
|
||||
glMultMatrixf((GLfloat*)_mat);
|
||||
}
|
||||
#undef SET_ROW
|
||||
|
@ -168,7 +168,7 @@ void DrawShapeVisitor::apply(const Box& box)
|
||||
if (!box.zeroRotation())
|
||||
{
|
||||
Matrix rotation(box.getRotationMatrix());
|
||||
glMultMatrixf(rotation.ptr());
|
||||
rotation.glMultMatrix();
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
@ -284,7 +284,7 @@ void DrawShapeVisitor::apply(const Cone& cone)
|
||||
if (!cone.zeroRotation())
|
||||
{
|
||||
Matrix rotation(cone.getRotationMatrix());
|
||||
glMultMatrixf(rotation.ptr());
|
||||
rotation.glMultMatrix();
|
||||
}
|
||||
|
||||
// evaluate hints
|
||||
@ -402,7 +402,7 @@ void DrawShapeVisitor::apply(const Cylinder& cylinder)
|
||||
if (!cylinder.zeroRotation())
|
||||
{
|
||||
Matrix rotation(cylinder.getRotationMatrix());
|
||||
glMultMatrixf(rotation.ptr());
|
||||
rotation.glMultMatrix();
|
||||
}
|
||||
|
||||
// evaluate hints
|
||||
@ -568,7 +568,7 @@ void DrawShapeVisitor::apply(const HeightField& field)
|
||||
if (!field.zeroRotation())
|
||||
{
|
||||
Matrix rotation(field.getRotationMatrix());
|
||||
glMultMatrixf(rotation.ptr());
|
||||
rotation.glMultMatrix();
|
||||
}
|
||||
|
||||
float dx = field.getXInterval();
|
||||
|
@ -27,6 +27,6 @@ TexMat::~TexMat()
|
||||
void TexMat::apply(State&) const
|
||||
{
|
||||
glMatrixMode( GL_TEXTURE );
|
||||
glLoadMatrixf( _matrix.ptr() );
|
||||
glMatrixMode( GL_MODELVIEW ); // fix! GWM Aug 2001
|
||||
_matrix.glLoadMatrix();
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ void VertexProgram::apply(State& state) const
|
||||
++itr)
|
||||
{
|
||||
glMatrixMode((*itr).first);
|
||||
glLoadMatrixf((*itr).second.ptr());
|
||||
(*itr).second.glLoadMatrix();
|
||||
}
|
||||
glMatrixMode(GL_MODELVIEW); // restore matrix mode
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -67,7 +67,7 @@ namespace
|
||||
osg::Vec3(lightvec.x(), lightvec.y(), lightvec.z()),
|
||||
eye_light_ref);
|
||||
|
||||
glLoadMatrixf((LM * osg::Matrix::inverse(M)).ptr());
|
||||
(LM * osg::Matrix::inverse(M)).glLoadMatrix();
|
||||
|
||||
} else {
|
||||
glLoadIdentity();
|
||||
|
@ -438,7 +438,11 @@ const osg::Node* OsgCameraGroup::getTopMostSceneData() const
|
||||
|
||||
void OsgCameraGroup::setView(const osg::Matrix& matrix)
|
||||
{
|
||||
Producer::Matrix pm(matrix.ptr());
|
||||
Producer::Matrix pm;//(matrix.ptr());
|
||||
for(int i=0;i<4;++i)
|
||||
for(int j=0;j<4;++j)
|
||||
pm(i,j)=matrix(i,j);
|
||||
|
||||
setViewByMatrix(pm);
|
||||
}
|
||||
|
||||
|
@ -7,15 +7,15 @@ using namespace osgSim;
|
||||
|
||||
std::string ScalarBar::ScalarPrinter::printScalar(float scalar)
|
||||
{
|
||||
std::stringstream ostr;
|
||||
ostr<<scalar;
|
||||
return ostr.str();
|
||||
std::stringstream ostr;
|
||||
ostr<<scalar;
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
void ScalarBar::setNumColors(int numColors)
|
||||
{
|
||||
_numColors = numColors;
|
||||
createDrawables();
|
||||
createDrawables();
|
||||
}
|
||||
|
||||
int ScalarBar::getNumColors() const
|
||||
@ -26,7 +26,7 @@ int ScalarBar::getNumColors() const
|
||||
void ScalarBar::setNumLabels(int numLabels)
|
||||
{
|
||||
_numLabels = numLabels;
|
||||
createDrawables();
|
||||
createDrawables();
|
||||
}
|
||||
|
||||
int ScalarBar::getNumLabels() const
|
||||
@ -37,7 +37,7 @@ int ScalarBar::getNumLabels() const
|
||||
void ScalarBar::setScalarsToColors(ScalarsToColors* stc)
|
||||
{
|
||||
_stc = stc;
|
||||
createDrawables();
|
||||
createDrawables();
|
||||
}
|
||||
|
||||
const ScalarsToColors* ScalarBar::getScalarsToColors() const
|
||||
@ -48,7 +48,7 @@ const ScalarsToColors* ScalarBar::getScalarsToColors() const
|
||||
void ScalarBar::setTitle(const std::string& title)
|
||||
{
|
||||
_title = title;
|
||||
createDrawables();
|
||||
createDrawables();
|
||||
}
|
||||
|
||||
std::string ScalarBar::getTitle() const
|
||||
@ -59,7 +59,7 @@ std::string ScalarBar::getTitle() const
|
||||
void ScalarBar::setOrientation(ScalarBar::Orientation orientation)
|
||||
{
|
||||
_orientation = orientation;
|
||||
createDrawables();
|
||||
createDrawables();
|
||||
}
|
||||
|
||||
ScalarBar::Orientation ScalarBar::getOrientation() const
|
||||
@ -70,7 +70,7 @@ ScalarBar::Orientation ScalarBar::getOrientation() const
|
||||
void ScalarBar::setAspectRatio(float aspectRatio)
|
||||
{
|
||||
_aspectRatio = aspectRatio;
|
||||
createDrawables();
|
||||
createDrawables();
|
||||
}
|
||||
|
||||
float ScalarBar::getAspectRatio() const
|
||||
@ -81,7 +81,7 @@ float ScalarBar::getAspectRatio() const
|
||||
void ScalarBar::setScalarPrinter(ScalarPrinter* sp)
|
||||
{
|
||||
_sp = sp;
|
||||
createDrawables();
|
||||
createDrawables();
|
||||
}
|
||||
|
||||
const ScalarBar::ScalarPrinter* ScalarBar::getScalarPrinter() const
|
||||
@ -93,7 +93,7 @@ const ScalarBar::ScalarPrinter* ScalarBar::getScalarPrinter() const
|
||||
void ScalarBar::setTextProperties(const TextProperties& tp)
|
||||
{
|
||||
_textProperties = tp;
|
||||
createDrawables();
|
||||
createDrawables();
|
||||
}
|
||||
|
||||
const ScalarBar::TextProperties& ScalarBar::getTextProperties() const
|
||||
@ -111,14 +111,14 @@ struct MaxCoordLess
|
||||
|
||||
MaxCoordLess(Axis axis): _axis(axis) {}
|
||||
|
||||
bool operator()(const osgText::Text* d1, const osgText::Text* d2)
|
||||
{
|
||||
if(_axis == X_AXIS ) return d1->getBound().xMax() < d2->getBound().xMax();
|
||||
else if(_axis == Y_AXIS) return d1->getBound().yMax() < d2->getBound().yMax();
|
||||
else if(_axis == Z_AXIS) return d1->getBound().zMax() < d2->getBound().zMax();
|
||||
bool operator()(const osgText::Text* d1, const osgText::Text* d2)
|
||||
{
|
||||
if(_axis == X_AXIS ) return d1->getBound().xMax() < d2->getBound().xMax();
|
||||
else if(_axis == Y_AXIS) return d1->getBound().yMax() < d2->getBound().yMax();
|
||||
else if(_axis == Z_AXIS) return d1->getBound().zMax() < d2->getBound().zMax();
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct AlignCentreOnYValue
|
||||
@ -126,10 +126,10 @@ struct AlignCentreOnYValue
|
||||
float _y;
|
||||
AlignCentreOnYValue(float y): _y(y) {}
|
||||
void operator()(osgText::Text* t)
|
||||
{
|
||||
{
|
||||
t->setPosition(osg::Vec3(t->getBound().center().x(), _y, t->getBound().center().z()));
|
||||
t->setAlignment(osgText::Text::CENTER_CENTER);
|
||||
}
|
||||
t->setAlignment(osgText::Text::CENTER_CENTER);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@ -139,162 +139,163 @@ void ScalarBar::createDrawables()
|
||||
// Remove any existing Drawables
|
||||
_drawables.erase(_drawables.begin(), _drawables.end());
|
||||
|
||||
// 1. First the bar
|
||||
// =================
|
||||
// 1. First the bar
|
||||
// =================
|
||||
osg::ref_ptr<osg::Geometry> bar = new osg::Geometry();
|
||||
|
||||
// Create the bar - created in 'real' coordinate space the moment,
|
||||
// with xyz values reflecting those of the actual scalar values in play.
|
||||
// FIXME: Consider positioning at origin! Should be easy enough to do.
|
||||
// Create the bar - created in 'real' coordinate space the moment,
|
||||
// with xyz values reflecting those of the actual scalar values in play.
|
||||
// FIXME: Consider positioning at origin! Should be easy enough to do.
|
||||
|
||||
// Vertices
|
||||
osg::ref_ptr<osg::Vec3Array> vs(new osg::Vec3Array);
|
||||
vs->reserve(2*(_numColors+1));
|
||||
// Vertices
|
||||
osg::ref_ptr<osg::Vec3Array> vs(new osg::Vec3Array);
|
||||
vs->reserve(2*(_numColors+1));
|
||||
|
||||
float incr = (_stc->getMax() - _stc->getMin()) / _numColors;
|
||||
float arOffset;
|
||||
if(_orientation==HORIZONTAL)
|
||||
{
|
||||
arOffset = _numColors * incr * _aspectRatio; // Bar height for a horizontal bar
|
||||
}
|
||||
else
|
||||
{
|
||||
float arOffset;
|
||||
if(_orientation==HORIZONTAL)
|
||||
{
|
||||
arOffset = _numColors * incr * _aspectRatio; // Bar height for a horizontal bar
|
||||
}
|
||||
else
|
||||
{
|
||||
arOffset = (_numColors*incr)/_aspectRatio; // Bar width for a vertical bar
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=1; i<=_numColors; ++i)
|
||||
{
|
||||
// Make a quad
|
||||
if(_orientation==HORIZONTAL)
|
||||
{
|
||||
vs->push_back(osg::Vec3(_stc->getMin() + (i-1) * incr, 0.0f, 0.0f));
|
||||
vs->push_back(osg::Vec3(_stc->getMin() + (i-1) * incr, arOffset, 0.0f));
|
||||
vs->push_back(osg::Vec3(_stc->getMin() + i * incr, arOffset, 0.0f));
|
||||
vs->push_back(osg::Vec3(_stc->getMin() + i * incr, 0.0f, 0.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
vs->push_back(osg::Vec3(0.0f, _stc->getMin() + (i-1) * incr, 0.0f));
|
||||
vs->push_back(osg::Vec3(arOffset, _stc->getMin() + (i-1) * incr, 0.0f));
|
||||
vs->push_back(osg::Vec3(arOffset, _stc->getMin() + i * incr, 0.0f));
|
||||
vs->push_back(osg::Vec3(0.0f, _stc->getMin() + i * incr, 0.0f));
|
||||
}
|
||||
}
|
||||
bar->setVertexArray(vs.get());
|
||||
int i;
|
||||
for(i=1; i<=_numColors; ++i)
|
||||
{
|
||||
// Make a quad
|
||||
if(_orientation==HORIZONTAL)
|
||||
{
|
||||
vs->push_back(osg::Vec3(_stc->getMin() + (i-1) * incr, 0.0f, 0.0f));
|
||||
vs->push_back(osg::Vec3(_stc->getMin() + (i-1) * incr, arOffset, 0.0f));
|
||||
vs->push_back(osg::Vec3(_stc->getMin() + i * incr, arOffset, 0.0f));
|
||||
vs->push_back(osg::Vec3(_stc->getMin() + i * incr, 0.0f, 0.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
vs->push_back(osg::Vec3(0.0f, _stc->getMin() + (i-1) * incr, 0.0f));
|
||||
vs->push_back(osg::Vec3(arOffset, _stc->getMin() + (i-1) * incr, 0.0f));
|
||||
vs->push_back(osg::Vec3(arOffset, _stc->getMin() + i * incr, 0.0f));
|
||||
vs->push_back(osg::Vec3(0.0f, _stc->getMin() + i * incr, 0.0f));
|
||||
}
|
||||
}
|
||||
bar->setVertexArray(vs.get());
|
||||
|
||||
// Colours
|
||||
osg::ref_ptr<osg::Vec4Array> cs(new osg::Vec4Array);
|
||||
cs->reserve(_numColors);
|
||||
const float halfIncr = incr*0.5;
|
||||
for(int i=0; i<_numColors; ++i)
|
||||
{
|
||||
// We add half an increment to the color look-up to get the color
|
||||
// square in the middle of the 'block'.
|
||||
cs->push_back(_stc->getColor(_stc->getMin() + (i*incr) + halfIncr));
|
||||
}
|
||||
bar->setColorArray(cs.get());
|
||||
bar->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);
|
||||
const float halfIncr = incr*0.5;
|
||||
for(i=0; i<_numColors; ++i)
|
||||
{
|
||||
// We add half an increment to the color look-up to get the color
|
||||
// square in the middle of the 'block'.
|
||||
cs->push_back(_stc->getColor(_stc->getMin() + (i*incr) + halfIncr));
|
||||
}
|
||||
bar->setColorArray(cs.get());
|
||||
bar->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);
|
||||
|
||||
// Normal
|
||||
// Normal
|
||||
osg::ref_ptr<osg::Vec3Array> ns(new osg::Vec3Array);
|
||||
ns->push_back(osg::Vec3(0.0f,0.0f,1.0f));
|
||||
bar->setNormalArray(ns.get());
|
||||
bar->setNormalBinding(osg::Geometry::BIND_OVERALL);
|
||||
bar->setNormalArray(ns.get());
|
||||
bar->setNormalBinding(osg::Geometry::BIND_OVERALL);
|
||||
|
||||
// The Quad strip that represents the bar
|
||||
bar->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,vs->size()));
|
||||
// The Quad strip that represents the bar
|
||||
bar->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,vs->size()));
|
||||
|
||||
addDrawable(bar.get());
|
||||
|
||||
// 2. Then the text labels
|
||||
// =======================
|
||||
// =======================
|
||||
|
||||
// Check the character size, if it's 0, estimate a good character size
|
||||
float characterSize = _textProperties._characterSize;
|
||||
if(characterSize == 0) characterSize = ((_stc->getMax()-_stc->getMin())*0.3)/_numLabels;
|
||||
if(characterSize == 0) characterSize = ((_stc->getMax()-_stc->getMin())*0.3)/_numLabels;
|
||||
|
||||
osgText::Font* font = osgText::readFontFile(_textProperties._fontFile.c_str());
|
||||
osgText::Font* font = osgText::readFontFile(_textProperties._fontFile.c_str());
|
||||
|
||||
std::vector<osgText::Text*> texts(_numLabels); // We'll need to collect pointers to these for later
|
||||
std::vector<osgText::Text*> texts(_numLabels); // We'll need to collect pointers to these for later
|
||||
float labelIncr = (_stc->getMax()-_stc->getMin())/(_numLabels-1);
|
||||
for(int i=0; i<_numLabels; ++i)
|
||||
{
|
||||
for(i=0; i<_numLabels; ++i)
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setFont(font);
|
||||
text->setColor(_textProperties._color);
|
||||
text->setFontResolution(_textProperties._fontResolution.first,_textProperties._fontResolution.second);
|
||||
text->setCharacterSize(characterSize);
|
||||
text->setText(_sp->printScalar(_stc->getMin()+(i*labelIncr)));
|
||||
text->setCharacterSize(characterSize);
|
||||
text->setText(_sp->printScalar(_stc->getMin()+(i*labelIncr)));
|
||||
|
||||
if(_orientation == HORIZONTAL)
|
||||
{
|
||||
if(_orientation == HORIZONTAL)
|
||||
{
|
||||
text->setPosition(osg::Vec3(_stc->getMin() + (i*labelIncr), arOffset, 0.0f));
|
||||
text->setAlignment(osgText::Text::CENTER_BOTTOM);
|
||||
}
|
||||
else
|
||||
{
|
||||
text->setAlignment(osgText::Text::CENTER_BOTTOM);
|
||||
}
|
||||
else
|
||||
{
|
||||
text->setPosition(osg::Vec3(arOffset, _stc->getMin() + (i*labelIncr), 0.0f));
|
||||
text->setAlignment(osgText::Text::LEFT_CENTER);
|
||||
}
|
||||
|
||||
addDrawable(text);
|
||||
|
||||
texts[i] = text;
|
||||
}
|
||||
|
||||
// Make sure the text labels are all properly aligned - different words will have a different
|
||||
// vertical alignment depending on the letters used in the labels. E.g. a 'y' has a dangling tail.
|
||||
if(_orientation == HORIZONTAL)
|
||||
{
|
||||
std::vector<osgText::Text*>::iterator maxYIt = std::max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::Y_AXIS));
|
||||
std::for_each(texts.begin(), texts.end(), AlignCentreOnYValue((*maxYIt)->getBound().center().y()));
|
||||
}
|
||||
|
||||
// 3. And finally the title
|
||||
// ========================
|
||||
|
||||
if(_title != "")
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setFont(font);
|
||||
text->setColor(_textProperties._color);
|
||||
text->setFontResolution(_textProperties._fontResolution.first,_textProperties._fontResolution.second);
|
||||
text->setCharacterSize(characterSize);
|
||||
text->setText(_title);
|
||||
|
||||
if(_orientation==HORIZONTAL)
|
||||
{
|
||||
// Horizontal bars have the title above the scalar bar and the labels.
|
||||
// Need to move the title above any labels, using maximum y value of the
|
||||
// existing text objects
|
||||
|
||||
std::vector<osgText::Text*>::iterator maxYIt = std::max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::Y_AXIS));
|
||||
|
||||
float titleY;
|
||||
if(maxYIt != texts.end()) titleY = (*maxYIt)->getBound().yMax() * 1.1f;
|
||||
else titleY = arOffset; // No labels, so just use arOffset
|
||||
|
||||
// Position the title at the middle of the bar above any labels.
|
||||
text->setPosition(osg::Vec3(_stc->getMin() + ((_stc->getMax()-_stc->getMin())/2.0f), titleY, 0.0f));
|
||||
text->setAlignment(osgText::Text::CENTER_BOTTOM);
|
||||
}
|
||||
else if(_orientation==VERTICAL)
|
||||
{
|
||||
// Vertical bars have the title to the right of the scalar bar and the labels.
|
||||
// Need to move the title out beyond any labels, using the maximum x value of the
|
||||
// existing text objects
|
||||
|
||||
std::vector<osgText::Text*>::iterator maxXIt = std::max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::X_AXIS));
|
||||
|
||||
float titleX;
|
||||
if(maxXIt != texts.end()) titleX = (*maxXIt)->getBound().xMax() * 1.1f;
|
||||
else titleX = arOffset; // No labels, so just use arOffset
|
||||
|
||||
// Position the title in the at the middle of the bar, to the right of any labels.
|
||||
text->setPosition(osg::Vec3(titleX, _stc->getMin() + ((_stc->getMax()-_stc->getMin())/2.0f), 0.0f));
|
||||
text->setAlignment(osgText::Text::LEFT_CENTER);
|
||||
text->setAlignment(osgText::Text::LEFT_CENTER);
|
||||
}
|
||||
|
||||
addDrawable(text);
|
||||
}
|
||||
addDrawable(text);
|
||||
|
||||
texts[i] = text;
|
||||
}
|
||||
|
||||
// Make sure the text labels are all properly aligned - different words will have a different
|
||||
// vertical alignment depending on the letters used in the labels. E.g. a 'y' has a dangling tail.
|
||||
if(_orientation == HORIZONTAL)
|
||||
{
|
||||
std::vector<osgText::Text*>::iterator maxYIt = std::max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::Y_AXIS));
|
||||
std::for_each(texts.begin(), texts.end(), AlignCentreOnYValue((*maxYIt)->getBound().center().y()));
|
||||
}
|
||||
|
||||
// 3. And finally the title
|
||||
// ========================
|
||||
|
||||
if(_title != "")
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setFont(font);
|
||||
text->setColor(_textProperties._color);
|
||||
text->setFontResolution(_textProperties._fontResolution.first,_textProperties._fontResolution.second);
|
||||
text->setCharacterSize(characterSize);
|
||||
text->setText(_title);
|
||||
|
||||
if(_orientation==HORIZONTAL)
|
||||
{
|
||||
// Horizontal bars have the title above the scalar bar and the labels.
|
||||
// Need to move the title above any labels, using maximum y value of the
|
||||
// existing text objects
|
||||
|
||||
std::vector<osgText::Text*>::iterator maxYIt = std::max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::Y_AXIS));
|
||||
|
||||
float titleY;
|
||||
if(maxYIt != texts.end()) titleY = (*maxYIt)->getBound().yMax() * 1.1f;
|
||||
else titleY = arOffset; // No labels, so just use arOffset
|
||||
|
||||
// Position the title at the middle of the bar above any labels.
|
||||
text->setPosition(osg::Vec3(_stc->getMin() + ((_stc->getMax()-_stc->getMin())/2.0f), titleY, 0.0f));
|
||||
text->setAlignment(osgText::Text::CENTER_BOTTOM);
|
||||
}
|
||||
else if(_orientation==VERTICAL)
|
||||
{
|
||||
// Vertical bars have the title to the right of the scalar bar and the labels.
|
||||
// Need to move the title out beyond any labels, using the maximum x value of the
|
||||
// existing text objects
|
||||
|
||||
std::vector<osgText::Text*>::iterator maxXIt = std::max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::X_AXIS));
|
||||
|
||||
float titleX;
|
||||
if(maxXIt != texts.end()) titleX = (*maxXIt)->getBound().xMax() * 1.1f;
|
||||
else titleX = arOffset; // No labels, so just use arOffset
|
||||
|
||||
// Position the title in the at the middle of the bar, to the right of any labels.
|
||||
text->setPosition(osg::Vec3(titleX, _stc->getMin() + ((_stc->getMax()-_stc->getMin())/2.0f), 0.0f));
|
||||
text->setAlignment(osgText::Text::LEFT_CENTER);
|
||||
}
|
||||
|
||||
addDrawable(text);
|
||||
}
|
||||
}
|
||||
|
@ -431,7 +431,8 @@ void SphereSegment::EdgeLine_drawImplementation(osg::State& /* state */) const
|
||||
|
||||
// Top edge
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for(int i=0; i<=_density; i++)
|
||||
int i;
|
||||
for(i=0; i<=_density; i++)
|
||||
{
|
||||
float az = _azMin + (i*azIncr);
|
||||
glVertex3f(
|
||||
@ -443,7 +444,7 @@ void SphereSegment::EdgeLine_drawImplementation(osg::State& /* state */) const
|
||||
|
||||
// Bottom edge
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for(int i=0; i<=_density; i++)
|
||||
for(i=0; i<=_density; i++)
|
||||
{
|
||||
float az = _azMin + (i*azIncr);
|
||||
glVertex3f(
|
||||
@ -455,7 +456,8 @@ void SphereSegment::EdgeLine_drawImplementation(osg::State& /* state */) const
|
||||
|
||||
// Left edge
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for(int j=0; j<=_density; j++)
|
||||
int j;
|
||||
for(j=0; j<=_density; j++)
|
||||
{
|
||||
float elev = _elevMin + (j*elevIncr);
|
||||
glVertex3f(
|
||||
@ -467,7 +469,7 @@ void SphereSegment::EdgeLine_drawImplementation(osg::State& /* state */) const
|
||||
|
||||
// Right edge
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for(int j=0; j<=_density; j++)
|
||||
for(j=0; j<=_density; j++)
|
||||
{
|
||||
float elev = _elevMin + (j*elevIncr);
|
||||
glVertex3f(
|
||||
@ -487,7 +489,8 @@ bool SphereSegment::EdgeLine_computeBound(osg::BoundingBox& bbox) const
|
||||
float elevIncr = (_elevMax - _elevMin)/_density;
|
||||
|
||||
// Top edge
|
||||
for(int i=0; i<=_density; i++)
|
||||
int i;
|
||||
for(i=0; i<=_density; i++)
|
||||
{
|
||||
float az = _azMin + (i*azIncr);
|
||||
bbox.expandBy(
|
||||
@ -497,7 +500,7 @@ bool SphereSegment::EdgeLine_computeBound(osg::BoundingBox& bbox) const
|
||||
}
|
||||
|
||||
// Bottom edge
|
||||
for(int i=0; i<=_density; i++)
|
||||
for(i=0; i<=_density; i++)
|
||||
{
|
||||
float az = _azMin + (i*azIncr);
|
||||
bbox.expandBy(
|
||||
@ -507,7 +510,8 @@ bool SphereSegment::EdgeLine_computeBound(osg::BoundingBox& bbox) const
|
||||
}
|
||||
|
||||
// Left edge
|
||||
for(int j=0; j<=_density; j++)
|
||||
int j;
|
||||
for(j=0; j<=_density; j++)
|
||||
{
|
||||
float elev = _elevMin + (j*elevIncr);
|
||||
bbox.expandBy(
|
||||
@ -517,7 +521,7 @@ bool SphereSegment::EdgeLine_computeBound(osg::BoundingBox& bbox) const
|
||||
}
|
||||
|
||||
// Right edge
|
||||
for(int j=0; j<=_density; j++)
|
||||
for(j=0; j<=_density; j++)
|
||||
{
|
||||
float elev = _elevMin + (j*elevIncr);
|
||||
bbox.expandBy(
|
||||
|
@ -153,9 +153,12 @@ float CullVisitor::getDistanceToEyePoint(const Vec3& pos, bool withLODScale) con
|
||||
else return (pos-getEyeLocal()).length();
|
||||
}
|
||||
|
||||
inline float distance(const osg::Vec3& coord,const osg::Matrix& matrix)
|
||||
inline CullVisitor::NearFarReal distance(const osg::Vec3& coord,const osg::Matrix& matrix)
|
||||
{
|
||||
return -(coord[0]*matrix(0,2)+coord[1]*matrix(1,2)+coord[2]*matrix(2,2)+matrix(3,2));
|
||||
|
||||
//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));
|
||||
}
|
||||
|
||||
float CullVisitor::getDistanceFromEyePoint(const osg::Vec3& pos, bool withLODScale) const
|
||||
@ -181,9 +184,9 @@ void CullVisitor::popProjectionMatrix()
|
||||
{
|
||||
//std::cout << "Orthographic projection "<<projection<<std::endl;
|
||||
|
||||
double span = (_computed_zfar-_computed_znear);
|
||||
double desired_znear = _computed_znear - span*0.02f;
|
||||
double desired_zfar = _computed_zfar + span*0.02f;
|
||||
NearFarReal span = (_computed_zfar-_computed_znear);
|
||||
NearFarReal desired_znear = _computed_znear - span*0.02f;
|
||||
NearFarReal desired_zfar = _computed_zfar + span*0.02f;
|
||||
|
||||
// near plane clamping.
|
||||
//double min_near_plane = _computed_zfar*_nearFarRatio;
|
||||
@ -205,23 +208,32 @@ void CullVisitor::popProjectionMatrix()
|
||||
|
||||
//std::cout << "Perspective projection "<<projection<<std::endl;
|
||||
|
||||
double desired_znear = _computed_znear *0.98f;
|
||||
double desired_zfar = _computed_zfar *1.02f;
|
||||
std::cout << "_computed_znear"<<_computed_znear<<std::endl;
|
||||
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;
|
||||
|
||||
// near plane clamping.
|
||||
double min_near_plane = _computed_zfar*_nearFarRatio;
|
||||
if (desired_znear<min_near_plane) desired_znear=min_near_plane;
|
||||
|
||||
std::cout << " desired_znear"<<desired_znear<<std::endl;
|
||||
std::cout << " desired_zfar"<<desired_zfar<<std::endl;
|
||||
|
||||
// assign the clamped values back to the computed values.
|
||||
_computed_znear = desired_znear;
|
||||
_computed_zfar = desired_zfar;
|
||||
|
||||
double trans_near_plane = (-desired_znear*projection(2,2)+projection(3,2))/(-desired_znear*projection(2,3)+projection(3,3));
|
||||
double trans_far_plane = (-desired_zfar*projection(2,2)+projection(3,2))/(-desired_zfar*projection(2,3)+projection(3,3));
|
||||
|
||||
double ratio = fabs(2.0f/(trans_near_plane-trans_far_plane));
|
||||
double center = -(trans_near_plane+trans_far_plane)/2.0f;
|
||||
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));
|
||||
|
||||
NearFarReal ratio = fabs(2.0/(trans_near_plane-trans_far_plane));
|
||||
NearFarReal 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,
|
||||
0.0f,0.0f,ratio,0.0f,
|
||||
@ -236,26 +248,36 @@ void CullVisitor::popProjectionMatrix()
|
||||
|
||||
void CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::BoundingBox& bb)
|
||||
{
|
||||
float d_near = distance(bb.corner(_bbCornerNear),matrix);
|
||||
float 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;
|
||||
}
|
||||
updateCalculatedNearFar(bb.corner(0));
|
||||
updateCalculatedNearFar(bb.corner(1));
|
||||
updateCalculatedNearFar(bb.corner(2));
|
||||
updateCalculatedNearFar(bb.corner(3));
|
||||
updateCalculatedNearFar(bb.corner(4));
|
||||
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;
|
||||
// }
|
||||
|
||||
}
|
||||
void CullVisitor::updateCalculatedNearFar(const osg::Vec3& pos)
|
||||
|
Loading…
Reference in New Issue
Block a user