OpenFrames
Model.hpp
Go to the documentation of this file.
1 /***********************************
2  Copyright 2018 Ravishankar Mathur
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  ***********************************/
16 
21 #ifndef _OF_MODEL_
22 #define _OF_MODEL_
23 
24 #include <OpenFrames/Export.h>
26 #include <osg/Node>
27 #include <osg/ref_ptr>
28 #include <osgManipulator/TrackballDragger>
29 #include <string>
30 
31 namespace OpenFrames
32 {
41  class OF_EXPORT Model : public ReferenceFrame
42  {
43  public:
44  Model( const std::string &name );
45  Model( const std::string &name, const osg::Vec3 &color );
46  Model( const std::string &name, const osg::Vec4 &color );
47  Model( const std::string &name , float r, float g, float b, float a = 1.0 );
48 
53  virtual osg::Group* getGroup() const;
54 
56  bool setModel( const std::string& filename, bool force_reload = false );
57  osg::Node* getModel() const { return _model.get(); }
58  osg::Geode* getExtras() const { return _extras.get(); }
59 
61  bool shareModel( const Model* otherModel );
62 
66  void setModelPosition( const double &x, const double &y, const double &z );
67 
68  void setModelPosition( const osg::Vec3d &pos )
69  { _modelXform->setPosition(pos); }
70 
71  void getModelPosition( double &x, double &y, double &z ) const
72  { _modelXform->getPosition(x, y, z); }
73 
74  void getModelPosition( osg::Vec3d &pos ) const
75  { _modelXform->getPosition(pos); }
76 
78  void setModelAttitude( const osg::Quat &att )
79  { _modelXform->setAttitude(att); }
80 
81  void getModelAttitude( osg::Quat &att ) const
82  { _modelXform->getAttitude(att); }
83 
85  void setModelScale( const double &sx, const double &sy, const double &sz);
86 
87  void getModelScale( double &sx, double &sy, double &sz ) const
88  {
89  _modelXform->getScale(sx, sy, sz);
90  }
91 
95  void setModelPivot(const double &px, const double &py, const double &pz);
96 
97  void getModelPivot( double &px, double &py, double &pz ) const
98  {
99  _modelXform->getPivot(px, py, pz);
100  }
101 
103  const FrameTransform* getModelTransform() const { return _modelXform; }
104 
107  void addDraggerCallback(osgManipulator::DraggerCallback* callback);
108 
110  virtual const osg::BoundingSphere& getBound() const;
111 
112  protected:
113  virtual ~Model();
114 
115  void init();
116  void repositionAxes();
117 
119  osg::ref_ptr<osg::Group> _group;
120 
122  osg::ref_ptr<osg::Node> _model;
123 
125  osg::ref_ptr<FrameTransform> _modelXform;
126 
129  osg::ref_ptr<osg::Geode> _extras;
130 
131  osg::ref_ptr<osgManipulator::TrackballDragger> _dragger;
132  osg::ref_ptr<osg::MatrixTransform> _draggerXform;
133  };
134 
135 
147  class OF_EXPORT ModelDraggerTransformCallback : public osgManipulator::DraggerTransformCallback
148  {
149  public:
150  ModelDraggerTransformCallback(FrameTransform* modelxform, osg::MatrixTransform* draggerxform);
151 
152  virtual bool receive(const osgManipulator::MotionCommand& command);
153 
154  protected:
155  osg::observer_ptr<FrameTransform> _modelXform;
156  };
157 
158 } // !namespace OpenFrames
159 
160 #endif // !define _OF_MODEL_
Definition: CoordinateAxes.hpp:29
osg::ref_ptr< osg::Node > _model
Definition: Model.hpp:122
This class enables dragging of a model.
Definition: Model.hpp:147
const FrameTransform * getModelTransform() const
Definition: Model.hpp:103
osg::ref_ptr< FrameTransform > _modelXform
Definition: Model.hpp:125
This class transforms from local to world coordinates or vice versa.
Definition: FrameTransform.hpp:37
void setModelAttitude(const osg::Quat &att)
Definition: Model.hpp:78
A Reference Frame that contains a 3D model.
Definition: Model.hpp:41
Definition: ReferenceFrame.hpp:54
osg::ref_ptr< osg::Geode > _extras
Definition: Model.hpp:129
osg::ref_ptr< osg::Group > _group
Definition: Model.hpp:119