OpenFrames
FrameTransform.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_FRAMETRANSFORM_
22 #define _OF_FRAMETRANSFORM_
23 
24 #include <OpenFrames/Export.h>
25 #include <osg/Transform>
26 
27 namespace OpenFrames
28 {
37  class OF_EXPORT FrameTransform : public osg::Transform
38  {
39  public:
40 
42 
43  // Don't allow copying from another FrameTransform
44  FrameTransform(const FrameTransform& xform, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) {}
45 
46  // Standard OSG Node methods
47  META_Node( OpenFrames, FrameTransform );
48 
49  void reset();
50 
51  // Set whether this frame should follow the viewer's eye point.
52  // This is used, e.g., for a SkyBox.
53  inline void setFollowEye(bool f) { _followEye = f; }
54  inline bool getFollowEye() const { return _followEye; }
55 
56  // Set whether this frame applies its transform or not.
57  inline void setDisabled(bool d) { _disabled = d; }
58  inline bool isDisabled() const { return _disabled; }
59 
60  // Set position wrt parent frame
61  void setPosition(const double &x, const double &y, const double &z);
62  void setPosition(const osg::Vec3d &pos);
63  void getPosition(double &x, double &y, double &z) const;
64  void getPosition(osg::Vec3d &pos) const;
65 
66  // Set attitude (orientation) wrt parent frame. Note that this is
67  // a quaternion (qx, qy, qx, qw).
68  void setAttitude(const double &rx, const double &ry, const double &rz, const double &angle);
69  void setAttitude(const osg::Quat &att);
70  void getAttitude(double &rx, double &ry, double &rz, double &angle) const;
71  void getAttitude(osg::Quat &att) const;
72 
73  // Set scale wrt parent frame
74  void setScale(const double &sx, const double &sy, const double &sz);
75  void getScale(double &sx, double &sy, double &sz);
76 
77  // Set the pivot point about which scales & rotations are computed.
78  void setPivot(const double &px, const double &py, const double &pz);
79  void getPivot(double &px, double &py, double &pz);
80 
81  // Inherited functions to compute transformation matrix
82  virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const;
83  virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const;
84 
85  protected:
86  virtual ~FrameTransform();
87 
88  osg::Vec3d _position; // Position relative to parent frame's origin
89  osg::Quat _attitude; // Attitude relative to parent frame
90  osg::Vec3d _scale; // Scale in addition to parent frame's scale
91  osg::Vec3d _pivot; // Pivot point relative to local origin
92 
93  // If disabled, this transform will have no effect
94  bool _disabled;
95 
96  // Allows frame to follow the current eye point. Only effective
97  // if the reference frame is of type RELATIVE_RF.
98  bool _followEye;
99  };
100 
101 } // !namespace OpenFrames
102 
103 #endif // !define _OF_FRAMETRANSFORM_
Definition: CoordinateAxes.hpp:29
This class transforms from local to world coordinates or vice versa.
Definition: FrameTransform.hpp:37