Added support for recording camera animation paths in osgGLUT::Viewer, and fixed

the osgGA::AnimationPathManipulator to handle it.

Added a new Drawable::ConstAttributeFunctor and make the accept(PrimitiveFunctor)
be a const method so can disallows modification.  Added Drawable::supports(...) methods
for each of the AttributeFunctor, ConstAttributeFunctor and PrimitiveFunctor so
that programs can querry whether it is possible to use functors with that object type.
This commit is contained in:
Robert Osfield
2002-11-06 10:24:33 +00:00
parent afa27a13ec
commit 5eb65f65cc
21 changed files with 422 additions and 115 deletions

View File

@@ -108,12 +108,17 @@ class SG_EXPORT AnimationPath : public osg::Referenced
LoopMode getLoopMode() const { return _loopMode; }
typedef std::map<double,ControlPoint> TimeControlPointMap;
TimeControlPointMap& getTimeControlPointMap() { return _timeControlPointMap; }
const TimeControlPointMap& getTimeControlPointMap() const { return _timeControlPointMap; }
protected:
virtual ~AnimationPath() {}
typedef std::map<double,ControlPoint> TimeControlPointMap;
TimeControlPointMap _timeControlPointMap;
LoopMode _loopMode;

View File

@@ -284,22 +284,57 @@ class SG_EXPORT Drawable : public Object
virtual void apply(AttributeType,unsigned int,Vec4*) {}
virtual void apply(AttributeType,unsigned int,UByte4*) {}
};
/** return true if the Drawable subclass supports accept(AttributeFunctor&).*/
virtual bool supports(AttributeFunctor&) const { return false; }
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.
* return true if functor handled by drawable, return false on failure of drawable to generate functor calls.*/
virtual void accept(AttributeFunctor&) {}
class ConstAttributeFunctor
{
public:
virtual ~ConstAttributeFunctor() {}
virtual void apply(AttributeType,const unsigned int,const GLbyte*) {}
virtual void apply(AttributeType,const unsigned int,const GLshort*) {}
virtual void apply(AttributeType,const unsigned int,const GLint*) {}
virtual void apply(AttributeType,const unsigned int,const GLubyte*) {}
virtual void apply(AttributeType,const unsigned int,const GLushort*) {}
virtual void apply(AttributeType,const unsigned int,const GLuint*) {}
virtual void apply(AttributeType,const unsigned int,const float*) {}
virtual void apply(AttributeType,const unsigned int,const Vec2*) {}
virtual void apply(AttributeType,const unsigned int,const Vec3*) {}
virtual void apply(AttributeType,const unsigned int,const Vec4*) {}
virtual void apply(AttributeType,const unsigned int,const UByte4*) {}
};
/** return true if the Drawable subclass supports accept(ConstAttributeFunctor&).*/
virtual bool supports(ConstAttributeFunctor&) const { return false; }
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.
* return true if functor handled by drawable, return false on failure of drawable to generate functor calls.*/
virtual void accept(ConstAttributeFunctor&) const {}
class PrimitiveFunctor
{
public:
virtual ~PrimitiveFunctor() {}
virtual void setVertexArray(unsigned int count,Vec3* vertices) = 0;
virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0;
virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
virtual void drawElements(GLenum mode,GLsizei count,GLubyte* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,GLushort* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,GLuint* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0;
virtual void begin(GLenum mode) = 0;
virtual void vertex(const Vec3& vert) = 0;
@@ -308,9 +343,14 @@ class SG_EXPORT Drawable : public Object
};
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
virtual void accept(PrimitiveFunctor&) {}
/** return true if the Drawable subclass supports accept(PrimitiveFunctor&).*/
virtual bool supports(PrimitiveFunctor&) const { return false; }
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.
* return true if functor handled by drawable, return false on failure of drawable to generate functor calls.
* Note, PrimtiveFunctor only provide const access of the primtives, as primitives may be procedurally generated
* so one cannot modify it.*/
virtual void accept(PrimitiveFunctor&) const {}
protected:
@@ -422,7 +462,7 @@ public:
virtual ~TriangleFunctor() {}
virtual void setVertexArray(unsigned int count,Vec3* vertices)
virtual void setVertexArray(unsigned int count,const Vec3* vertices)
{
_vertexArraySize = count;
_vertexArrayPtr = vertices;
@@ -436,14 +476,14 @@ public:
{
case(GL_TRIANGLES):
{
Vec3* vlast = &_vertexArrayPtr[first+count];
for(Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=3)
const Vec3* vlast = &_vertexArrayPtr[first+count];
for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=3)
operator()(*(vptr),*(vptr+1),*(vptr+2));
break;
}
case(GL_TRIANGLE_STRIP):
{
Vec3* vptr = &_vertexArrayPtr[first];
const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=2;i<count;++i,++vptr)
{
if ((i%2)) operator()(*(vptr),*(vptr+2),*(vptr+1));
@@ -453,7 +493,7 @@ public:
}
case(GL_QUADS):
{
Vec3* vptr = &_vertexArrayPtr[first];
const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=3;i<count;i+=4,vptr+=4)
{
operator()(*(vptr),*(vptr+1),*(vptr+2));
@@ -463,7 +503,7 @@ public:
}
case(GL_QUAD_STRIP):
{
Vec3* vptr = &_vertexArrayPtr[first];
const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=3;i<count;i+=2,vptr+=2)
{
operator()(*(vptr),*(vptr+1),*(vptr+2));
@@ -474,8 +514,8 @@ public:
case(GL_POLYGON): // treat polygons as GL_TRIANGLE_FAN
case(GL_TRIANGLE_FAN):
{
Vec3* vfirst = &_vertexArrayPtr[first];
Vec3* vptr = vfirst+1;
const Vec3* vfirst = &_vertexArrayPtr[first];
const Vec3* vptr = vfirst+1;
for(GLsizei i=2;i<count;++i,++vptr)
{
operator()(*(vfirst),*(vptr),*(vptr+1));
@@ -492,11 +532,11 @@ public:
}
}
virtual void drawElements(GLenum mode,GLsizei count,GLubyte* indices)
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices)
{
if (indices==0 || count==0) return;
typedef GLubyte* IndexPointer;
typedef const GLubyte* IndexPointer;
switch(mode)
{
@@ -541,7 +581,7 @@ public:
case(GL_TRIANGLE_FAN):
{
IndexPointer iptr = indices;
Vec3& vfirst = _vertexArrayPtr[*iptr];
const Vec3& vfirst = _vertexArrayPtr[*iptr];
++iptr;
for(GLsizei i=2;i<count;++i,++iptr)
{
@@ -559,11 +599,11 @@ public:
}
}
virtual void drawElements(GLenum mode,GLsizei count,GLushort* indices)
virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices)
{
if (indices==0 || count==0) return;
typedef GLushort* IndexPointer;
typedef const GLushort* IndexPointer;
switch(mode)
{
@@ -610,7 +650,7 @@ public:
case(GL_TRIANGLE_FAN):
{
IndexPointer iptr = indices;
Vec3& vfirst = _vertexArrayPtr[*iptr];
const Vec3& vfirst = _vertexArrayPtr[*iptr];
++iptr;
for(GLsizei i=2;i<count;++i,++iptr)
{
@@ -628,11 +668,11 @@ public:
}
}
virtual void drawElements(GLenum mode,GLsizei count,GLuint* indices)
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices)
{
if (indices==0 || count==0) return;
typedef GLuint* IndexPointer;
typedef const GLuint* IndexPointer;
switch(mode)
{
@@ -677,7 +717,7 @@ public:
case(GL_TRIANGLE_FAN):
{
IndexPointer iptr = indices;
Vec3& vfirst = _vertexArrayPtr[*iptr];
const Vec3& vfirst = _vertexArrayPtr[*iptr];
++iptr;
for(GLsizei i=2;i<count;++i,++iptr)
{
@@ -722,7 +762,7 @@ protected:
unsigned int _vertexArraySize;
Vec3* _vertexArrayPtr;
const Vec3* _vertexArrayPtr;
GLenum _modeCache;
std::vector<Vec3> _vertexCache;

View File

@@ -1,3 +1,4 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
@@ -332,8 +333,11 @@ class SG_EXPORT GeoSet : public Drawable
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
virtual void accept(AttributeFunctor& af);
/** accept an ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
virtual void accept(ConstAttributeFunctor& af) const;
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
virtual void accept(PrimitiveFunctor& pf);
virtual void accept(PrimitiveFunctor& pf) const;
/** convinience function for converting GeoSet's to equivilant Geometry nodes.*/
Geometry* convertToGeometry();

View File

@@ -163,11 +163,23 @@ class SG_EXPORT Geometry : public Drawable
*/
virtual void drawImmediateMode(State& state);
/** return true, osg::Geometry does support accept(AttributeFunctor&).*/
virtual bool supports(AttributeFunctor&) const { return true; }
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
virtual void accept(AttributeFunctor& af);
/** return true, osg::Geometry does support accept(ConstAttributeFunctor&).*/
virtual bool supports(ConstAttributeFunctor&) const { return true; }
/** accept an ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
virtual void accept(ConstAttributeFunctor& af) const;
/** return true, osg::Geometry does support accept(PrimitiveFunctor&) .*/
virtual bool supports(PrimitiveFunctor&) const { return true; }
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
virtual void accept(PrimitiveFunctor& pf);
virtual void accept(PrimitiveFunctor& pf) const;
protected:

View File

@@ -116,11 +116,24 @@ class SG_EXPORT ImpostorSprite : public Drawable
/** draw ImpostorSprite directly. */
virtual void drawImmediateMode(State& state);
/** return true, osg::ImpostorSprite does support accept(AttributeFunctor&).*/
virtual bool supports(AttributeFunctor&) const { return true; }
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
virtual void accept(AttributeFunctor& af);
/** return true, osg::ImpostorSprite does support accept(ConstAttributeFunctor&).*/
virtual bool supports(ConstAttributeFunctor&) const { return true; }
/** accept an ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
virtual void accept(ConstAttributeFunctor& af) const;
/** return true, osg::ImpostorSprite does support accept(PrimitiveFunctor&) .*/
virtual bool supports(PrimitiveFunctor&) const { return true; }
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
virtual void accept(PrimitiveFunctor& pf);
virtual void accept(PrimitiveFunctor& pf) const;
protected:

View File

@@ -233,7 +233,7 @@ class SG_EXPORT Matrix : public Object
// Matrix( const MatrixProduct& p ) //allows implicit evaluation of the product
// { mult( p.A, p.B ); }
private:
protected:
float _mat[4][4];
};

View File

@@ -123,7 +123,7 @@ class PrimitiveSet : public Object
virtual void draw() const = 0;
virtual void accept(Drawable::PrimitiveFunctor&) {}
virtual void accept(Drawable::PrimitiveFunctor& functor) const = 0;
virtual unsigned int index(unsigned int pos) const = 0;
virtual unsigned int getNumIndices() const = 0;
@@ -199,7 +199,7 @@ class SG_EXPORT DrawArrays : public PrimitiveSet
virtual void draw() const;
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual unsigned int getNumIndices() const { return _count; }
virtual unsigned int index(unsigned int pos) const { return _first+pos; }
@@ -252,7 +252,7 @@ class SG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorSizei
virtual void draw() const;
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual unsigned int getNumIndices() const;
virtual unsigned int index(unsigned int pos) const { return _first+pos; }
@@ -313,7 +313,7 @@ class SG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorUByte
virtual void draw() const ;
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual unsigned int getNumIndices() const { return size(); }
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
@@ -353,7 +353,7 @@ class SG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorUShort
virtual void draw() const;
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual unsigned int getNumIndices() const { return size(); }
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
@@ -392,7 +392,7 @@ class SG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorUInt
virtual void draw() const;
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual unsigned int getNumIndices() const { return size(); }
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }

View File

@@ -126,11 +126,20 @@ class SG_EXPORT ProceduralGeometry : public Drawable
*/
virtual void drawImmediateMode(State& state);
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
virtual void accept(AttributeFunctor& af);
/** return false, osg::ProceduralGeoemtry does not support accept(AttributeFunctor&).*/
virtual bool supports(AttributeFunctor&) const { return false; }
/** return true, osg::ProceduralGeometry does support accept(ConstAttributeFunctor&).*/
virtual bool supports(ConstAttributeFunctor&) const { return true; }
/** accept an ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
virtual void accept(ConstAttributeFunctor& af) const;
/** return true, osg::ProceduralGeometry does support accept(PrimitiveFunctor&) .*/
virtual bool supports(PrimitiveFunctor&) const { return true; }
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
virtual void accept(PrimitiveFunctor& pf);
virtual void accept(PrimitiveFunctor& pf) const;
protected:

View File

@@ -64,12 +64,12 @@ class Statistics : public osg::Referenced, public osg::Drawable::PrimitiveFuncto
void setType(statsType t) {stattype=t;}
virtual void setVertexArray(unsigned int count,Vec3*) { _vertexCount += count; }
virtual void setVertexArray(unsigned int count,const Vec3*) { _vertexCount += count; }
virtual void drawArrays(GLenum mode,GLint,GLsizei count) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
virtual void drawElements(GLenum mode,GLsizei count,GLubyte*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
virtual void drawElements(GLenum mode,GLsizei count,GLushort*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
virtual void drawElements(GLenum mode,GLsizei count,GLuint*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
virtual void drawElements(GLenum mode,GLsizei count,const GLushort*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
virtual void drawElements(GLenum mode,GLsizei count,const GLuint*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
virtual void begin(GLenum mode) { _currentPrimtiveFunctorMode=mode; PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; }
virtual void vertex(const Vec3&) { PrimitivePair& prim = _primitiveCount[_currentPrimtiveFunctorMode]; ++prim.second; }

View File

@@ -39,6 +39,10 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
bool valid() const { return _animationPath.valid(); }
void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
private:
@@ -48,6 +52,9 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
void handleFrame( double time );
osg::ref_ptr<osg::AnimationPath> _animationPath;
double _timeOffset;
double _timeScale;
};

View File

@@ -14,6 +14,7 @@
#include <osgGA/GUIEventAdapter>
#include <osgGA/CameraManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/AnimationPathManipulator>
#include <osgUtil/SceneView>
@@ -104,6 +105,14 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter
typedef std::vector<osg::ref_ptr<osgGA::CameraManipulator> > CameraManipList;
typedef std::list<osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlerList;
void setRecordingAnimationPath(bool on) { _recordingAnimationPath = on; }
bool getRecordingAnimationPath() const { return _recordingAnimationPath; }
void setAnimationPath(osg::AnimationPath* path) { _animationPath = path; }
osg::AnimationPath* getAnimationPath() { return _animationPath.get(); }
const osg::AnimationPath* getAnimationPath() const { return _animationPath.get(); }
protected:
virtual void clear();
@@ -177,6 +186,9 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter
osg::ref_ptr<osg::FrameStamp> _frameStamp;
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
bool _recordingAnimationPath;
osg::ref_ptr<osg::AnimationPath> _animationPath;
};