Class test: Public osgga: animationpathmanipulator
{
Public:
Test (OSG: animationpath * path): animationpathmanipulator (PATH)
{
}
~ Test (){}
PRIVATE:
OSG: quat _ rotation;
OSG: vec3d _ center;
Double _ distance;
Double _ current;
Public:
Virtual void setbymatrix (const OSG: matrixd & matrix) {_ matrix = matrix ;}
/** Set the position of the matrix manipulator using a 4x4 matrix .*/
Virtual void setbyinversematrix (const OSG: matrixd & matrix) {_ matrix. Invert (matrix );}
/** Get the position of the manipulator as 4x4 matrix .*/
Virtual OSG: matrixd getmatrix () const {return _ matrix ;}
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix. */
virtual OSG: matrixd getinversematrix () const
{< br> return _ matrix;
}
Void home (const osgga: guieventadapter & EA, osgga: guiactionadapter & US)
{
_ Current = OSG: Timer: instance ()-> tick ();
}
Bool handle (const osgga: guieventadapter & EA, osgga: guiactionadapter & US)
{
If (! Valid () return false;
Switch (EA. geteventtype ())
{
Case osgga: guieventadapter: frame:
{
OSG: animationpath: controlpoint CP;
Double T = _ animationpath-> getlasttime ()-_ animationpath-> getfirsttime ();
Double KK = OSG: Timer: instance ()-> tick ();
Double duration = OSG: Timer: instance ()-> delta_s (_ current, KK );
Duration = fmod (duration, t );
Duration + = _ animationpath-> getfirsttime ();
_ Animationpath-> getinterpolatedcontrolpoint (duration, CP );
CP. getmatrix (_ matrix );
}
Case osgga: guieventadapter: keyup:
{
If (EA. getkey () ='s ')
{
}
}
Case osgga: guieventadapter: keyup
{
If (EA. getkey () = 'P ')
{
}
}
}
Return true;
}
};
Osgviewer: viewer;
OSG: Group * Group = new OSG: group;
OSG: node * node = osgdb: readnodefile ("D:/osgbin/bin/cow. OSG ");
Group-> addchild (node );
OSG: matrixtransform * transform = new OSG: matrixtransform;
Transform-> setmatrix (OSG: matrixd: translate (20, 0, 0 ));
OSG: node * node1 = osgdb: readnodefile ("D:/osgbin/bin/cow. OSG ");
Transform-> addchild (node1 );
Group-> addchild (Transform );
OSG: animationpath * Path = new OSG: animationpath;
Path-> setloopmode (OSG: animationpath: loop );
For (INT I = 0; I <36; I ++)
{
OSG: quat (10 * I, OSG: vec3d (0.0, 1.0, 0.0 ));
OSG: matrixd M = OSG: matrixd: translate (-group-> getbound (). center () * OSG: matrixd: Rotate (quat) * OSG: matrixd: translate (0, 0,-group-> getbound (). radius () * 3 );
OSG: vec3f Pos = M. gettrans ();
OSG: quat rot = M. getrotate ();
Path-> insert (I * 5, OSG: animationpath: controlpoint (Pos, rot ));
}
Viewer. setcameramanipulator (new test (PATH ));
Viewer. setscenedata (node );
Return viewer. Run ();