]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/SGScaleTransform.hxx
03b1c8a008055c919aa46b1de13c93cb10b63091
[simgear.git] / simgear / scene / model / SGScaleTransform.hxx
1 /* -*-c++-*-
2  *
3  * Copyright (C) 2006-2007 Mathias Froehlich 
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  *
20  */
21
22 #ifndef SG_SCALE_TRANSFORM_HXX
23 #define SG_SCALE_TRANSFORM_HXX
24
25 #include <osg/Transform>
26 #include <simgear/math/SGMath.hxx>
27
28 class SGScaleTransform : public osg::Transform {
29 public:
30   SGScaleTransform();
31
32   void setCenter(const SGVec3f& center)
33   { setCenter(toVec3d(center)); }
34   void setCenter(const SGVec3d& center)
35   { _center = center; dirtyBound(); }
36   const SGVec3d& getCenter() const
37   { return _center; }
38
39   void setScaleFactor(const SGVec3d& scaleFactor)
40   {
41     double boundScale = normI(scaleFactor);
42     if (_boundScale < boundScale || 5*boundScale < _boundScale) {
43       _boundScale = boundScale;
44       dirtyBound();
45     }
46     _scaleFactor = scaleFactor;
47   }
48   void setScaleFactor(double scaleFactor)
49   { 
50     double boundScale = fabs(scaleFactor);
51     if (_boundScale < boundScale || 5*boundScale < _boundScale) {
52       _boundScale = boundScale;
53       dirtyBound();
54     }
55     _scaleFactor = SGVec3d(scaleFactor, scaleFactor, scaleFactor);
56   }
57   const SGVec3d& getScaleFactor() const
58   { return _scaleFactor; }
59
60
61   virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,
62                                          osg::NodeVisitor* nv) const;
63   virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,
64                                          osg::NodeVisitor* nv) const;
65   virtual osg::BoundingSphere computeBound() const;
66
67 private:
68   SGVec3d _center;
69   SGVec3d _scaleFactor;
70   mutable double _boundScale;
71 };
72
73 #endif