I am trying to move a loaded object dynamically, but to do so, Need to get 4x4 matrix for the object.
In the code given below I have loaded the Cesna and Cow models in this scene and I only want to rotate the cow model.
Example from "Cesna" OpenGenGrop 3.0 Beginner's Guide page 234.
Note: - The tree is already generated. The changing tree user needs to rotate the selected object using the navigation keys. User will select the required object using the mouse
#include Set matrix (matrix); break; Default: Break; } return false; } Int main (int argc, char * argv []) {osg :: ref_ptr & lt; Osg :: node & gt; Model = osgDB :: readNodeFile ("cessna.osg"); OSG :: ref_ptr & lt; OSG :: node & gt; Model1 = osgDB :: readNodeFile ("cow.osg"); OSG :: ref_ptr & lt; OSG :: MatrixTransform & gt; Mt = new osg :: Matrix Transform; Mt-> gt; Add Chald (model.get ()); Mt- & gt; AddChild (model1.get ()); Root-> gt; Add Chald (mt.get ()); Osg :: Matrix Transformer * MT1 = Dynamic_Cast & lt; Osg :: Metric Transform * & gt; (Model1.get ()); OSG :: ref_ptr & lt; ModelController & gt; Seater = new model controller (MT1); OsgViewer :: viewer viewer; the audience. AddEventHandler (ctrler.get ()); Viewer.getCamera () - & gt; SetViewMatrixAsLookAt (OSG :: Vec3 (0.0f, -100.0f, 0.0f), OSG :: Vec3 (), OSG :: Z_AXIS); Viewer .Setcinata (Route get) the audience. AddEventHandler (new osgViewer :: WindowSizeHandler); Return viewer. Ron (); }
You get it with a new matrix transform
can do. Instead of putting both cow and cassation in the same MatrixTransform
, use two:
OSG :: ref_ptr & lt; OSG :: MatrixTransform & gt; Mt = new osg :: Matrix Transform; Mt-> gt; Add Chald (model.get ()); OSG :: ref_ptr & lt; OSG :: MatrixTransform & gt; MT2 = new Oz :: Matrix Transform; Mt2-> AddChild (model1.get ()); Root-> gt; Add Chald (mt.get ()); Root- & gt; Add Chald (mt2.get ());
Then you can pass matrix transformer
, you want the controller
, leaving the other model "default":
OSG :: ref_ptr & lt; ModelController & gt; Seater = new model controller (MT2);
No comments:
Post a Comment