]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/placementtrans.hxx
OSG Reader and Writer for BTG files
[simgear.git] / simgear / scene / model / placementtrans.hxx
1 // placementtrans.hxx -- class for carrying transforms for placing models in the world
2 //
3 // Written by Mathias Froehlich, started April 2005.
4 //
5 // Copyright (C) 2005 Mathias Froehlich
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21
22
23 #ifndef _SG_PLACEMENTTRANS_HXX
24 #define _SG_PLACEMENTTRANS_HXX
25
26 #ifndef __cplusplus
27 # error This library requires C++
28 #endif
29
30 #include <simgear/compiler.h>
31 #include <simgear/constants.h>
32 #include <simgear/math/SGMath.hxx>
33
34 #include <osg/Transform>
35
36 class SGPlacementTransform : public osg::Transform
37 {
38 public:
39   
40   SGPlacementTransform(void);
41   SGPlacementTransform(const SGPlacementTransform&,
42                        const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
43
44   META_Node(simgear, SGPlacementTransform);
45   
46   void setTransform(const SGVec3d& off)
47   { _placement_offset = off; dirtyBound(); }
48   void setTransform(const SGVec3d& off, const SGMatrixd& rot)
49   { _placement_offset = off; _rotation = rot; dirtyBound(); }
50   void setSceneryCenter(const SGVec3d& center)
51   { _scenery_center = center; dirtyBound(); }
52   
53   const SGVec3d& getGlobalPos() const
54   { return _placement_offset; }
55   const SGMatrixd& getRotation() const { return _rotation; }
56   const SGVec3d& getSceneryCenter() const { return _scenery_center; }
57   
58   virtual bool computeLocalToWorldMatrix(osg::Matrix&,osg::NodeVisitor*) const;
59   virtual bool computeWorldToLocalMatrix(osg::Matrix&,osg::NodeVisitor*) const;
60
61 protected:
62   virtual ~SGPlacementTransform(void);
63
64 private:
65
66   class UpdateCallback;
67
68   //////////////////////////////////////////////////////////////////
69   // private data                                                 //
70   //////////////////////////////////////////////////////////////////
71   
72   SGVec3d _placement_offset;
73   SGVec3d _scenery_center;
74   SGMatrixd _rotation;
75 };
76
77 #endif // _SG_LOCATION_HXX