Fixed a bug in the Optimizer where BIND_PER_PRIMITIVE_SET primitives where being eroneously merged.
Added missing support for reading geometry indices from the .osg format. Added handling of geometry indices into the primitive functor in osg::Geometry. Moved the method implementions of AnimationPathManipulator into src/osgGA and added extra convinience methods for setting the manipulator with an hand built AnimationPath. FCVS: VisualStudio/osgPlugins/iv/iv.dsp
This commit is contained in:
80
src/osgGA/AnimationPathManipulator.cpp
Normal file
80
src/osgGA/AnimationPathManipulator.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include <osgGA/AnimationPathManipulator>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace osgGA;
|
||||
|
||||
AnimationPathManipulator::AnimationPathManipulator(osg::AnimationPath* animationPath)
|
||||
{
|
||||
_animationPath = animationPath;
|
||||
}
|
||||
|
||||
AnimationPathManipulator::AnimationPathManipulator( const std::string& filename )
|
||||
{
|
||||
_animationPath = osgNew osg::AnimationPath;
|
||||
_animationPath->setLoopMode(osg::AnimationPath::LOOP);
|
||||
|
||||
FILE *fp = fopen( filename.c_str(), "r" );
|
||||
if( fp == NULL )
|
||||
{
|
||||
osg::notify(osg::WARN) << "AnimationPathManipulator: Cannot open animation path file \"" << filename << "\".\n";
|
||||
_valid = false;
|
||||
return;
|
||||
}
|
||||
while( !feof( fp ))
|
||||
{
|
||||
double time;
|
||||
osg::Vec3 position;
|
||||
osg::Quat rotation;
|
||||
fscanf( fp, "%lf %f %f %f %f %f %f %f\n",
|
||||
&time, &position[0], &position[1], &position[2],
|
||||
&rotation[0], &rotation[1], &rotation[2], &rotation[3] );
|
||||
|
||||
if( !feof(fp))
|
||||
_animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us)
|
||||
{
|
||||
if( !valid() ) return false;
|
||||
|
||||
us = us;
|
||||
|
||||
bool retval = false;
|
||||
switch( ea.getEventType() )
|
||||
{
|
||||
case GUIEventAdapter::FRAME:
|
||||
handleFrame( ea.time() );
|
||||
|
||||
break;
|
||||
case GUIEventAdapter::KEYBOARD:
|
||||
switch( ea.getKey())
|
||||
{
|
||||
default:
|
||||
retval = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void AnimationPathManipulator::handleFrame( double time )
|
||||
{
|
||||
osg::AnimationPath::ControlPoint cp;
|
||||
_animationPath->getInterpolatedControlPoint( time, cp );
|
||||
|
||||
osg::Matrix mat;
|
||||
cp.getMatrix( mat );
|
||||
|
||||
osg::Vec3 eye(mat(3,0), mat(3,1), mat(3,2));
|
||||
mat(3,0) = 0.0;
|
||||
mat(3,1) = 0.0;
|
||||
mat(3,2) = 0.0;
|
||||
osg::Vec3 look = eye + (osg::Vec3(0,1,0) * mat);
|
||||
osg::Vec3 up = osg::Vec3(0,0,1) * mat;
|
||||
if( _camera.valid() )
|
||||
_camera->setView( eye, look, up );
|
||||
}
|
||||
Reference in New Issue
Block a user