Added basic image sequencing
This commit is contained in:
@@ -13,13 +13,19 @@
|
||||
|
||||
#include <OpenThreads/ScopedLock>
|
||||
#include <osg/ImageSequence>
|
||||
#include <osg/Notify>
|
||||
#include <osg/Camera>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
ImageSequence::ImageSequence()
|
||||
{
|
||||
_referenceTime = 0.0;
|
||||
_referenceTime = DBL_MAX;
|
||||
_imageIteratorTime = DBL_MAX;
|
||||
_timeMultiplier = 1.0;
|
||||
_imageIterator = _imageDuationSequence.end();
|
||||
}
|
||||
|
||||
ImageSequence::ImageSequence(const ImageSequence& is,const CopyOp& copyop):
|
||||
@@ -36,17 +42,81 @@ int ImageSequence::compare(const Image& rhs) const
|
||||
|
||||
void ImageSequence::addImageFile(const std::string& fileName, double duration)
|
||||
{
|
||||
if (duration<0.01) duration = 0.01;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
_fileNameDurationSequence.push_back(FileNameDurationPair(fileName, duration));
|
||||
}
|
||||
|
||||
void ImageSequence::addImage(osg::Image* image, double duration)
|
||||
{
|
||||
if (duration<0.01) duration = 0.01;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
_imageDuationSequence.push_back(ImageDurationPair(image, duration));
|
||||
|
||||
if (_imageIterator==_imageDuationSequence.end())
|
||||
{
|
||||
_imageIterator = _imageDuationSequence.begin();
|
||||
_imageIteratorTime = _referenceTime;
|
||||
setImageToChild(_imageIterator->first.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ImageSequence::update(osg::FrameStamp* fs)
|
||||
void ImageSequence::setImageToChild(const osg::Image* image)
|
||||
{
|
||||
setImage(image->s(),image->t(),image->r(),
|
||||
image->getInternalTextureFormat(),
|
||||
image->getPixelFormat(),image->getDataType(),
|
||||
const_cast<unsigned char*>(image->data()),
|
||||
osg::Image::NO_DELETE,
|
||||
image->getPacking());
|
||||
}
|
||||
|
||||
void ImageSequence::update(const osg::FrameStamp* fs)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
// osg::notify(osg::NOTICE)<<"ImageSequence::update("<<fs<<")"<<std::endl;
|
||||
|
||||
if (_referenceTime == DBL_MAX)
|
||||
{
|
||||
_referenceTime = fs->getSimulationTime();
|
||||
}
|
||||
|
||||
if (_imageIteratorTime == DBL_MAX)
|
||||
{
|
||||
_imageIteratorTime = _referenceTime;
|
||||
}
|
||||
|
||||
double time = (fs->getSimulationTime() - _referenceTime)*_timeMultiplier;
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"time = "<<time<<std::endl;
|
||||
|
||||
if (_imageIterator!=_imageDuationSequence.end())
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<" _imageIteratorTime = "<<_imageIteratorTime<<std::endl;
|
||||
while(time > (_imageIteratorTime + _imageIterator->second))
|
||||
{
|
||||
_imageIteratorTime += _imageIterator->second;
|
||||
// osg::notify(osg::NOTICE)<<" _imageIteratorTime = "<<_imageIteratorTime<<std::endl;
|
||||
++_imageIterator;
|
||||
|
||||
if (_imageIterator ==_imageDuationSequence.end())
|
||||
{
|
||||
// return iterator to begining of set.
|
||||
_imageIterator = _imageDuationSequence.begin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_imageIterator==_imageDuationSequence.end())
|
||||
{
|
||||
_imageIterator = _imageDuationSequence.begin();
|
||||
}
|
||||
|
||||
if (_imageIterator!=_imageDuationSequence.end())
|
||||
{
|
||||
setImageToChild(_imageIterator->first.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <osg/BufferObject>
|
||||
#include <osg/CopyOp>
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/Image>
|
||||
#include <osg/Object>
|
||||
#include <osg/Vec2>
|
||||
@@ -351,6 +352,21 @@ BEGIN_OBJECT_REFLECTOR(osg::Image)
|
||||
__C5_PixelBufferObject_P1__getPixelBufferObject,
|
||||
"Get the const PixelBufferObject. ",
|
||||
"");
|
||||
I_Method1(void, setCallUpdateInDraw, IN, bool, flag,
|
||||
Properties::NON_VIRTUAL,
|
||||
__void__setCallUpdateInDraw__bool,
|
||||
"",
|
||||
"");
|
||||
I_Method0(bool, getCallUpdateInDraw,
|
||||
Properties::NON_VIRTUAL,
|
||||
__bool__getCallUpdateInDraw,
|
||||
"",
|
||||
"");
|
||||
I_Method1(void, update, IN, const osg::FrameStamp *, fs,
|
||||
Properties::VIRTUAL,
|
||||
__void__update__C5_osg_FrameStamp_P1,
|
||||
"",
|
||||
"");
|
||||
I_StaticMethod1(bool, isPackedType, IN, GLenum, type,
|
||||
__bool__isPackedType__GLenum_S,
|
||||
"",
|
||||
@@ -394,6 +410,9 @@ BEGIN_OBJECT_REFLECTOR(osg::Image)
|
||||
I_SimpleProperty(osg::Image::AllocationMode, AllocationMode,
|
||||
__AllocationMode__getAllocationMode,
|
||||
__void__setAllocationMode__AllocationMode);
|
||||
I_SimpleProperty(bool, CallUpdateInDraw,
|
||||
__bool__getCallUpdateInDraw,
|
||||
__void__setCallUpdateInDraw__bool);
|
||||
I_SimpleProperty(GLenum, DataType,
|
||||
__GLenum__getDataType,
|
||||
__void__setDataType__GLenum);
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <osgIntrospection/Attributes>
|
||||
|
||||
#include <osg/CopyOp>
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/Image>
|
||||
#include <osg/ImageStream>
|
||||
#include <osg/Object>
|
||||
@@ -148,11 +147,6 @@ BEGIN_OBJECT_REFLECTOR(osg::ImageStream)
|
||||
__float__getVolume,
|
||||
"",
|
||||
"");
|
||||
I_Method1(void, update, IN, osg::FrameStamp *, fs,
|
||||
Properties::VIRTUAL,
|
||||
__void__update__osg_FrameStamp_P1,
|
||||
"",
|
||||
"");
|
||||
I_ProtectedMethod0(void, applyLoopingMode,
|
||||
Properties::VIRTUAL,
|
||||
Properties::NON_CONST,
|
||||
|
||||
Reference in New Issue
Block a user