diff --git a/Make/makedirdefs b/Make/makedirdefs index a1d03ea10..250358c0e 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -69,6 +69,7 @@ PLUGIN_DIRS += tiff # Directories traversed in the TOPDIR/src/Demos directory DEMOS_DIRS = \ + osganimate\ osgbillboard\ osgcallback\ osgclip\ diff --git a/VisualStudio/Demos/osganimate/osganimate.dsp b/VisualStudio/Demos/osganimate/osganimate.dsp new file mode 100755 index 000000000..f1b7d4855 --- /dev/null +++ b/VisualStudio/Demos/osganimate/osganimate.dsp @@ -0,0 +1,95 @@ +# Microsoft Developer Studio Project File - Name="Demo osganimate" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Demo osganimate - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "osganimate.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "osganimate.mak" CFG="Demo osganimate - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Demo osganimate - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "Demo osganimate - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Demo osganimate - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osganimate.exe" /libpath:"../../../lib" + +!ELSEIF "$(CFG)" == "Demo osganimate - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 glut32.lib glu32.lib opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osganimated.exe" /pdbtype:sept /libpath:"../../../lib" +# SUBTRACT LINK32 /incremental:no + +!ENDIF + +# Begin Target + +# Name "Demo osganimate - Win32 Release" +# Name "Demo osganimate - Win32 Debug" +# Begin Source File + +SOURCE=..\..\..\src\Demos\osganimate\osganimate.cpp +# End Source File +# End Target +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Project diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index 6b912aa7e..4801abcba 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -327,6 +327,33 @@ Package=<4> ############################################################################### +Project: "Demo osganimate"=.\Demos\osganimate\osganimate.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Core osg + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgDB + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgGA + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgGLUT + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgUtil + End Project Dependency +}}} + +############################################################################### + Project: "Demo osgcube"=.\Demos\osgcube\osgcube.dsp - Package Owner=<4> Package=<5> diff --git a/include/osg/MatrixTransform b/include/osg/MatrixTransform index 2525dc4ce..b606afb03 100644 --- a/include/osg/MatrixTransform +++ b/include/osg/MatrixTransform @@ -85,14 +85,18 @@ class SG_EXPORT MatrixTransform : public Transform { public: - AnimationPathCallback(AnimationPath* ap): + AnimationPathCallback(AnimationPath* ap,double timeOffset=0.0f,double timeMultiplier=1.0f): _animationPath(ap), + _timeOffset(timeOffset), + _timeMultiplier(timeMultiplier), _firstTime(0.0) {} /** implements the callback*/ virtual void operator()(Node* node, NodeVisitor* nv); ref_ptr _animationPath; + double _timeOffset; + double _timeMultiplier; double _firstTime; }; diff --git a/include/osg/PositionAttitudeTransform b/include/osg/PositionAttitudeTransform index cec17ad7c..c37e0f479 100644 --- a/include/osg/PositionAttitudeTransform +++ b/include/osg/PositionAttitudeTransform @@ -57,14 +57,18 @@ class SG_EXPORT PositionAttitudeTransform : public Transform { public: - AnimationPathCallback(AnimationPath* ap): + AnimationPathCallback(AnimationPath* ap,double timeOffset=0.0f,double timeMultiplier=1.0f): _animationPath(ap), + _timeOffset(timeOffset), + _timeMultiplier(timeMultiplier), _firstTime(0.0) {} /** implements the callback*/ virtual void operator()(Node* node, NodeVisitor* nv); ref_ptr _animationPath; + double _timeOffset; + double _timeMultiplier; double _firstTime; }; diff --git a/include/osg/Quat b/include/osg/Quat index bd5e58087..1088ccaaa 100644 --- a/include/osg/Quat +++ b/include/osg/Quat @@ -29,9 +29,21 @@ class SG_EXPORT Quat ---------------------------------------------------------- */ Vec4 _fv; // a four-vector - Quat(): _fv(0.0f,0.0f,0.0f,1.0f) {} - Quat( float x, float y, float z, float w ): _fv(x,y,z,w) {} - Quat( const Vec4& v ): _fv(v) {} + inline Quat(): _fv(0.0f,0.0f,0.0f,1.0f) {} + inline Quat( float x, float y, float z, float w ): _fv(x,y,z,w) {} + inline Quat( const Vec4& v ): _fv(v) {} + + inline Quat( float angle, const Vec3& axis) + { + makeRotate(angle,axis); + } + + inline Quat( float angle1, const Vec3& axis1, + float angle2, const Vec3& axis2, + float angle3, const Vec3& axis3) + { + makeRotate(angle1,axis1,angle2,axis2,angle3,axis3); + } /* ---------------------------------- Methods to access data members diff --git a/src/Demos/osganimate/Makefile b/src/Demos/osganimate/Makefile new file mode 100644 index 000000000..2bd5a9f69 --- /dev/null +++ b/src/Demos/osganimate/Makefile @@ -0,0 +1,16 @@ +TOPDIR = ../../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osganimate.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +INSTFILES = \ + $(CXXFILES)\ + Makefile.inst=Makefile + +EXEC = osganimate + +include $(TOPDIR)/Make/makerules + diff --git a/src/Demos/osganimate/Makefile.inst b/src/Demos/osganimate/Makefile.inst new file mode 100644 index 000000000..2136ca321 --- /dev/null +++ b/src/Demos/osganimate/Makefile.inst @@ -0,0 +1,12 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osganimate.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osganimate + + +include $(TOPDIR)/Make/makerules diff --git a/src/Demos/osganimate/osganimate.cpp b/src/Demos/osganimate/osganimate.cpp new file mode 100644 index 000000000..c09baa551 --- /dev/null +++ b/src/Demos/osganimate/osganimate.cpp @@ -0,0 +1,233 @@ +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + + +#include +#include + + +osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime) +{ + // set up the animation path + osg::AnimationPath* animationPath = new osg::AnimationPath; + animationPath->setLoopMode(osg::AnimationPath::LOOP); + + int numSamples = 40; + float yaw = 0.0f; + float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f); + float roll = osg::inDegrees(30.0f); + + double time=0.0f; + double time_delta = looptime/(double)numSamples; + for(int i=0;iinsert(time,osg::AnimationPath::ControlPoint(position,rotation)); + + yaw += yaw_delta; + time += time_delta; + + } + return animationPath; +} + +osg::Node* createBase(const osg::Vec3& center,float radius) +{ + + + + int numTilesX = 10; + int numTilesY = 10; + + float width = 2*radius; + float height = 2*radius; + + osg::Vec3 v000(center - osg::Vec3(width*0.5f,height*0.5f,0.0f)); + osg::Vec3 dx(osg::Vec3(width/((float)numTilesX),0.0,0.0f)); + osg::Vec3 dy(osg::Vec3(0.0f,height/((float)numTilesY),0.0f)); + + // fill in vertices for grid, note numTilesX+1 * numTilesY+1... + osg::Vec3Array* coords = osgNew osg::Vec3Array; + int iy; + for(iy=0;iy<=numTilesY;++iy) + { + for(int ix=0;ix<=numTilesX;++ix) + { + coords->push_back(v000+dx*(float)ix+dy*(float)iy); + } + } + + //Just two colours - black and white. + osg::Vec4Array* colors = osgNew osg::Vec4Array; + colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); // white + colors->push_back(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); // black + int numColors=colors->size(); + + + int numIndicesPerRow=numTilesX+1; + osg::UByteArray* coordIndices = osgNew osg::UByteArray; // assumes we are using less than 256 points... + osg::UByteArray* colorIndices = osgNew osg::UByteArray; + for(iy=0;iypush_back(ix +(iy+1)*numIndicesPerRow); + coordIndices->push_back(ix +iy*numIndicesPerRow); + coordIndices->push_back((ix+1)+iy*numIndicesPerRow); + coordIndices->push_back((ix+1)+(iy+1)*numIndicesPerRow); + + // one color per quad + colorIndices->push_back((ix+iy)%numColors); + } + } + + + // set up a single normal + osg::Vec3Array* normals = osgNew osg::Vec3Array; + normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); + + + osg::Geometry* geom = osgNew osg::Geometry; + geom->setVertexArray(coords); + geom->setVertexIndices(coordIndices); + + geom->setColorArray(colors); + geom->setColorIndices(colorIndices); + geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE); + + geom->setNormalArray(normals); + geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + + geom->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,coordIndices->size())); + + osg::Geode* geode = osgNew osg::Geode; + geode->addDrawable(geom); + + return geode; +} + +osg::Node* createModel() +{ + osg::Vec3 center(0.0f,0.0f,0.0f); + float radius = 100.0f; + + osg::Group* root = osgNew osg::Group; + + float animationLength = 10.0f; + osg::AnimationPath* animationPath = createAnimationPath(center,radius,animationLength); + + osg::Node* glider = osgDB::readNodeFile("glider.osg"); + if (glider) + { + const osg::BoundingSphere& bs = glider->getBound(); + + float size = radius/bs.radius()*0.3f; + osg::MatrixTransform* positioned = osgNew osg::MatrixTransform; + positioned->setDataVariance(osg::Object::STATIC); + positioned->setMatrix(osg::Matrix::translate(-bs.center())* + osg::Matrix::scale(size,size,size)* + osg::Matrix::rotate(osg::inDegrees(-90.0f),0.0f,0.0f,1.0f)); + + positioned->addChild(glider); + + osg::PositionAttitudeTransform* xform = osgNew osg::PositionAttitudeTransform; + xform->setAppCallback(new osg::PositionAttitudeTransform::AnimationPathCallback(animationPath,0.0,1.0)); + xform->addChild(positioned); + + root->addChild(xform); + } + + osg::Node* cessna = osgDB::readNodeFile("cessna.osg"); + if (cessna) + { + const osg::BoundingSphere& bs = cessna->getBound(); + + float size = radius/bs.radius()*0.3f; + osg::MatrixTransform* positioned = osgNew osg::MatrixTransform; + positioned->setDataVariance(osg::Object::STATIC); + positioned->setMatrix(osg::Matrix::translate(-bs.center())* + osg::Matrix::scale(size,size,size)* + osg::Matrix::rotate(osg::inDegrees(180.0f),0.0f,0.0f,1.0f)); + + positioned->addChild(cessna); + + osg::MatrixTransform* xform = osgNew osg::MatrixTransform; + xform->setAppCallback(new osg::MatrixTransform::AnimationPathCallback(animationPath,0.0f,2.0)); + xform->addChild(positioned); + + root->addChild(xform); + } + +// osg::Node* truck = osgDB::readNodeFile("dumptruck.osg"); + + root->addChild(createBase(center-osg::Vec3(0.0f,0.0f,radius*0.5),radius)); + + return root; +} + + +int main( int argc, char **argv ) +{ + + // initialize the GLUT + glutInit( &argc, argv ); + + // create the commandline args. + std::vector commandLine; + for(int i=1;igetFrameStamp()->getReferenceTime(); if (_firstTime==0.0) _firstTime = time; Matrix matrix; - if (_animationPath->getMatrix(time-_firstTime,matrix)) + if (_animationPath->getMatrix(((time-_firstTime)-_timeOffset)*_timeMultiplier,matrix)) { mt->setMatrix(matrix); } diff --git a/src/osg/PositionAttitudeTransform.cpp b/src/osg/PositionAttitudeTransform.cpp index e122b868f..64ab25e8d 100644 --- a/src/osg/PositionAttitudeTransform.cpp +++ b/src/osg/PositionAttitudeTransform.cpp @@ -52,7 +52,7 @@ void PositionAttitudeTransform::AnimationPathCallback::operator()(Node* node, No double time = nv->getFrameStamp()->getReferenceTime(); if (_firstTime==0.0) _firstTime = time; AnimationPath::ControlPoint cp; - if (_animationPath->getInterpolatedControlPoint(time-_firstTime,cp)) + if (_animationPath->getInterpolatedControlPoint(((time-_firstTime)-_timeOffset)*_timeMultiplier,cp)) { pat->setPosition(cp._position); pat->setAttitude(cp._rotation); diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index cd71a6083..a0e84d4e3 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -150,6 +150,10 @@ void SceneView::app() //std::cout<<"*************************** New frame ************"<