The camera rotates along the scene

Source: Internet
Author: User

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 ();

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.