Various work on osgViewer library, including warp point and graphics window resize support
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <osg/Group>
|
||||
#include <osg/Transform>
|
||||
#include <osg/Quat>
|
||||
#include <osg/Viewport>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -60,8 +61,6 @@ class OSG_EXPORT AutoTransform : public Transform
|
||||
float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; }
|
||||
|
||||
|
||||
|
||||
|
||||
enum AutoRotateMode
|
||||
{
|
||||
NO_ROTATION,
|
||||
@@ -88,25 +87,24 @@ class OSG_EXPORT AutoTransform : public Transform
|
||||
protected :
|
||||
|
||||
virtual ~AutoTransform() {}
|
||||
|
||||
Vec3 _position;
|
||||
Vec3 _pivotPoint;
|
||||
float _autoUpdateEyeMovementTolerance;
|
||||
|
||||
AutoRotateMode _autoRotateMode;
|
||||
|
||||
bool _autoScaleToScreen;
|
||||
|
||||
|
||||
Vec3 _position;
|
||||
Vec3 _pivotPoint;
|
||||
float _autoUpdateEyeMovementTolerance;
|
||||
|
||||
AutoRotateMode _autoRotateMode;
|
||||
|
||||
bool _autoScaleToScreen;
|
||||
|
||||
mutable Quat _rotation;
|
||||
mutable Vec3 _scale;
|
||||
mutable bool _firstTimeToInitEyePoint;
|
||||
mutable osg::Vec3 _previousEyePoint;
|
||||
mutable osg::Vec3 _previousLocalUp;
|
||||
mutable int _previousWidth;
|
||||
mutable int _previousHeight;
|
||||
mutable osg::Matrix _previousProjection;
|
||||
mutable osg::Vec3 _previousPosition;
|
||||
mutable Quat _rotation;
|
||||
mutable Vec3 _scale;
|
||||
mutable bool _firstTimeToInitEyePoint;
|
||||
mutable osg::Vec3 _previousEyePoint;
|
||||
mutable osg::Vec3 _previousLocalUp;
|
||||
mutable Viewport::value_type _previousWidth;
|
||||
mutable Viewport::value_type _previousHeight;
|
||||
mutable osg::Matrix _previousProjection;
|
||||
mutable osg::Vec3 _previousPosition;
|
||||
|
||||
|
||||
void computeMatrix() const;
|
||||
|
||||
@@ -310,7 +310,7 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
|
||||
|
||||
|
||||
/** Set the GraphicsContext that provides the mechansim for managing the OpenGL graphics context associated with this camera.*/
|
||||
void setGraphicsContext(GraphicsContext* context) { _graphicsContext = context; }
|
||||
void setGraphicsContext(GraphicsContext* context);
|
||||
|
||||
/** Get the GraphicsContext.*/
|
||||
GraphicsContext* getGraphicsContext() { return _graphicsContext.get(); }
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
// forward declare osg::Camera
|
||||
class Camera;
|
||||
|
||||
/** Base class for providing Windowing API agnostic access to creating and managing graphics context.*/
|
||||
class OSG_EXPORT GraphicsContext : public Referenced
|
||||
{
|
||||
@@ -74,10 +77,10 @@ class OSG_EXPORT GraphicsContext : public Referenced
|
||||
sharedContext(0) {}
|
||||
|
||||
// graphics context orginal and size
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
// window decoration and baviour
|
||||
std::string windowName;
|
||||
@@ -258,12 +261,30 @@ class OSG_EXPORT GraphicsContext : public Referenced
|
||||
virtual void swapBuffersImplementation() = 0;
|
||||
|
||||
|
||||
/** resized method should be called when the underlying window has been resized and the GraphicsWindow and associated Cameras must
|
||||
be updated to keep in sync with the new size. */
|
||||
void resized(int x, int y, int width, int height);
|
||||
|
||||
typedef std::list< osg::Camera* > Cameras;
|
||||
|
||||
/** Get the the list of cameras associated with this graphics context.*/
|
||||
Cameras& getCameras() { return _cameras; }
|
||||
|
||||
/** Get the the const list of cameras associated with this graphics context.*/
|
||||
const Cameras& getCameras() const { return _cameras; }
|
||||
|
||||
protected:
|
||||
|
||||
GraphicsContext();
|
||||
|
||||
virtual ~GraphicsContext();
|
||||
|
||||
void addCamera(osg::Camera* camera);
|
||||
void removeCamera(osg::Camera* camera);
|
||||
|
||||
Cameras _cameras;
|
||||
|
||||
friend class osg::Camera;
|
||||
|
||||
ref_ptr<Traits> _traits;
|
||||
ref_ptr<State> _state;
|
||||
|
||||
@@ -200,13 +200,15 @@ class OSG_EXPORT PrimitiveSet : public Object
|
||||
PrimitiveSet(Type primType=PrimitiveType,GLenum mode=0):
|
||||
_primitiveType(primType),
|
||||
_mode(mode),
|
||||
_modifiedCount(0) {}
|
||||
_modifiedCount(0),
|
||||
_rangeModifiedCount(0) {}
|
||||
|
||||
PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Object(prim,copyop),
|
||||
_primitiveType(prim._primitiveType),
|
||||
_mode(prim._mode),
|
||||
_modifiedCount(0) {}
|
||||
_modifiedCount(0),
|
||||
_rangeModifiedCount(0) {}
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const PrimitiveSet*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
@@ -245,6 +247,8 @@ class OSG_EXPORT PrimitiveSet : public Object
|
||||
* for all graphics contexts. */
|
||||
virtual void releaseGLObjects(State* /*state*/=0) const {}
|
||||
|
||||
virtual void computeRange() const {}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~PrimitiveSet() {}
|
||||
@@ -252,7 +256,7 @@ class OSG_EXPORT PrimitiveSet : public Object
|
||||
Type _primitiveType;
|
||||
GLenum _mode;
|
||||
unsigned int _modifiedCount;
|
||||
|
||||
mutable unsigned int _rangeModifiedCount;
|
||||
|
||||
struct ObjectIDModifiedCountPair
|
||||
{
|
||||
@@ -435,10 +439,34 @@ class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorGLubyte
|
||||
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
virtual void computeRange() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
_minIndex = 0;
|
||||
_maxIndex = 0;
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
return;
|
||||
}
|
||||
|
||||
_minIndex = front();
|
||||
_maxIndex = _minIndex;
|
||||
|
||||
for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr)
|
||||
{
|
||||
if (*itr<_minIndex) _minIndex = *itr;
|
||||
if (*itr>_maxIndex) _maxIndex = *itr;
|
||||
}
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DrawElementsUByte();
|
||||
|
||||
mutable unsigned int _minIndex;
|
||||
mutable unsigned int _maxIndex;
|
||||
|
||||
mutable GLObjectList _vboList;
|
||||
|
||||
};
|
||||
@@ -491,10 +519,34 @@ class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorGLushort
|
||||
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
virtual void computeRange() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
_minIndex = 0;
|
||||
_maxIndex = 0;
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
return;
|
||||
}
|
||||
|
||||
_minIndex = front();
|
||||
_maxIndex = _minIndex;
|
||||
|
||||
for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr)
|
||||
{
|
||||
if (*itr<_minIndex) _minIndex = *itr;
|
||||
if (*itr>_maxIndex) _maxIndex = *itr;
|
||||
}
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DrawElementsUShort();
|
||||
|
||||
mutable unsigned int _minIndex;
|
||||
mutable unsigned int _maxIndex;
|
||||
|
||||
mutable GLObjectList _vboList;
|
||||
};
|
||||
|
||||
@@ -545,10 +597,34 @@ class OSG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorGLuint
|
||||
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
virtual void computeRange() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
_minIndex = 0;
|
||||
_maxIndex = 0;
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
return;
|
||||
}
|
||||
|
||||
_minIndex = front();
|
||||
_maxIndex = _minIndex;
|
||||
|
||||
for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr)
|
||||
{
|
||||
if (*itr<_minIndex) _minIndex = *itr;
|
||||
if (*itr>_maxIndex) _maxIndex = *itr;
|
||||
}
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DrawElementsUInt();
|
||||
|
||||
mutable unsigned int _minIndex;
|
||||
mutable unsigned int _maxIndex;
|
||||
|
||||
mutable GLObjectList _vboList;
|
||||
};
|
||||
|
||||
|
||||
@@ -59,8 +59,8 @@ class OSG_EXPORT View : public virtual osg::Referenced
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
osg::Matrixd _projectionOffset;
|
||||
osg::Matrixd _viewOffset;
|
||||
osg::Matrixd _projectionOffset;
|
||||
osg::Matrixd _viewOffset;
|
||||
};
|
||||
|
||||
bool addSlave(osg::Camera* camera) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity()); }
|
||||
@@ -73,8 +73,12 @@ class OSG_EXPORT View : public virtual osg::Referenced
|
||||
|
||||
Slave& getSlave(unsigned int pos) { return _slaves[pos]; }
|
||||
const Slave& getSlave(unsigned int pos) const { return _slaves[pos]; }
|
||||
|
||||
Slave* findSlaveForCamera(osg::Camera* camera);
|
||||
|
||||
void updateSlaves();
|
||||
|
||||
void updateSlave(unsigned int i);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -23,9 +23,15 @@ namespace osg {
|
||||
class OSG_EXPORT Viewport : public StateAttribute
|
||||
{
|
||||
public :
|
||||
|
||||
#if 0
|
||||
typedef int value_type;
|
||||
#else
|
||||
typedef double value_type;
|
||||
#endif
|
||||
Viewport();
|
||||
|
||||
Viewport(int x,int y,int width,int height):
|
||||
Viewport(value_type x,value_type y,value_type width,value_type height):
|
||||
_x(x),
|
||||
_y(y),
|
||||
_width(width),
|
||||
@@ -58,14 +64,15 @@ class OSG_EXPORT Viewport : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
inline void setViewport(int x,int y,int width,int height)
|
||||
inline void setViewport(value_type x,value_type y,value_type width,value_type height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
void getViewport(int& x,int& y,int& width,int& height) const
|
||||
{
|
||||
x = _x;
|
||||
@@ -74,24 +81,32 @@ class OSG_EXPORT Viewport : public StateAttribute
|
||||
height = _height;
|
||||
}
|
||||
|
||||
inline int& x() { return _x; }
|
||||
inline int x() const { return _x; }
|
||||
void getViewport(double& x,double& y,double& width,double& height) const
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
width = _width;
|
||||
height = _height;
|
||||
}
|
||||
#endif
|
||||
inline value_type& x() { return _x; }
|
||||
inline value_type x() const { return _x; }
|
||||
|
||||
inline int& y() { return _y; }
|
||||
inline int y() const { return _y; }
|
||||
inline value_type& y() { return _y; }
|
||||
inline value_type y() const { return _y; }
|
||||
|
||||
inline int& width() { return _width; }
|
||||
inline int width() const { return _width; }
|
||||
inline value_type& width() { return _width; }
|
||||
inline value_type width() const { return _width; }
|
||||
|
||||
inline int& height() { return _height; }
|
||||
inline int height() const { return _height; }
|
||||
inline value_type& height() { return _height; }
|
||||
inline value_type height() const { return _height; }
|
||||
|
||||
inline bool valid() const { return _width!=0 && _height!=0; }
|
||||
inline bool valid() const { return _width>0 && _height>0; }
|
||||
|
||||
/** Return the aspectRatio of the viewport, which is equal to width/height.
|
||||
* If height is zero, the potental division by zero is avoided by simply returning 1.0f.
|
||||
*/
|
||||
inline float aspectRatio() const { if (_height!=0) return (float)_width/(float)_height; else return 1.0f; }
|
||||
inline double aspectRatio() const { if (_height!=0) return (double)_width/(double)_height; else return 1.0; }
|
||||
|
||||
/** Compute the Window Matrix which takes projected coords into Window coordinates.
|
||||
* To convert local coordinates into window coordinates use v_window = v_local * MVPW matrix,
|
||||
@@ -101,7 +116,7 @@ class OSG_EXPORT Viewport : public StateAttribute
|
||||
*/
|
||||
inline const osg::Matrix computeWindowMatrix() const
|
||||
{
|
||||
return osg::Matrix::translate(1.0f,1.0f,1.0f)*osg::Matrix::scale(0.5f*width(),0.5f*height(),0.5f)*osg::Matrix::translate(x(),y(),0.0f);
|
||||
return osg::Matrix::translate(1.0,1.0,1.0)*osg::Matrix::scale(0.5*width(),0.5*height(),0.5f)*osg::Matrix::translate(x(),y(),0.0f);
|
||||
}
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
@@ -110,10 +125,10 @@ class OSG_EXPORT Viewport : public StateAttribute
|
||||
|
||||
virtual ~Viewport();
|
||||
|
||||
int _x;
|
||||
int _y;
|
||||
int _width;
|
||||
int _height;
|
||||
value_type _x;
|
||||
value_type _y;
|
||||
value_type _width;
|
||||
value_type _height;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user