AntiSquish 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. //osgDragger - Copyright (C) 2007 Fugro-Jason B.V.
  14. #ifndef _OSG_ANTISQUISH_
  15. #define _OSG_ANTISQUISH_ 1
  16. #include <osgManipulator/Export>
  17. #include <osg/Transform>
  18. #include <OpenThreads/Mutex>
  19. namespace osgManipulator {
  20. /**
  21. * Class that performs the Anti Squish by making the scaling uniform along all axes.
  22. */
  23. class OSGMANIPULATOR_EXPORT AntiSquish: public osg::Transform
  24. {
  25. public :
  26. AntiSquish();
  27. AntiSquish(const osg::Vec3d& pivot);
  28. AntiSquish(const osg::Vec3d& pivot, const osg::Vec3d& position);
  29. AntiSquish(const AntiSquish& pat, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  30. virtual osg::Object* cloneType() const { return new AntiSquish(); }
  31. virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new AntiSquish (*this,copyop); }
  32. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const AntiSquish *>(obj)!=NULL; }
  33. virtual const char* libraryName() const { return "osgManipulator"; }
  34. virtual const char* className() const { return "AntiSquish"; }
  35. void setPivot(const osg::Vec3d& pvt)
  36. {
  37. _pivot = pvt;
  38. _usePivot = true;
  39. _cacheDirty = true;
  40. }
  41. const osg::Vec3d& getPivot() const { return _pivot; }
  42. void setPosition(const osg::Vec3d& pos)
  43. {
  44. _position = pos;
  45. _usePosition = true;
  46. _cacheDirty = true;
  47. }
  48. const osg::Vec3d& getPosition() const { return _position; }
  49. bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const;
  50. bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const;
  51. protected:
  52. virtual ~AntiSquish();
  53. bool computeUnSquishedMatrix(osg::Matrix&) const;
  54. osg::Vec3d _pivot;
  55. bool _usePivot;
  56. osg::Vec3d _position;
  57. bool _usePosition;
  58. mutable OpenThreads::Mutex _cacheLock;
  59. mutable bool _cacheDirty;
  60. mutable osg::Matrix _cacheLocalToWorld;
  61. mutable osg::Matrix _cache;
  62. };
  63. }
  64. #endif