openscenegraph
AntiSquish
Go to the documentation of this file.
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
15#ifndef _OSG_ANTISQUISH_
16#define _OSG_ANTISQUISH_ 1
17
18#include <osgManipulator/Export>
19
20#include <osg/Transform>
21#include <OpenThreads/Mutex>
22
23namespace osgManipulator {
24
25/**
26 * Class that performs the Anti Squish by making the scaling uniform along all axes.
27 */
28class OSGMANIPULATOR_EXPORT AntiSquish: public osg::Transform
29{
30 public :
31 AntiSquish();
32 AntiSquish(const osg::Vec3d& pivot);
33 AntiSquish(const osg::Vec3d& pivot, const osg::Vec3d& position);
34 AntiSquish(const AntiSquish& pat, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
35
36 virtual osg::Object* cloneType() const { return new AntiSquish(); }
37
38 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new AntiSquish (*this,copyop); }
39
40 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const AntiSquish *>(obj)!=NULL; }
41
42 virtual const char* libraryName() const { return "osgManipulator"; }
43
44 virtual const char* className() const { return "AntiSquish"; }
45
46
47 void setPivot(const osg::Vec3d& pvt)
48 {
49 _pivot = pvt;
50 _usePivot = true;
51 _cacheDirty = true;
52 }
53
54 const osg::Vec3d& getPivot() const { return _pivot; }
55
56 void setPosition(const osg::Vec3d& pos)
57 {
58 _position = pos;
59 _usePosition = true;
60 _cacheDirty = true;
61 }
62
63 const osg::Vec3d& getPosition() const { return _position; }
64
65 bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const;
66 bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const;
67
68 protected:
69
70 virtual ~AntiSquish();
71
72 bool computeUnSquishedMatrix(osg::Matrix&) const;
73
74 osg::Vec3d _pivot;
75 bool _usePivot;
76
77 osg::Vec3d _position;
78 bool _usePosition;
79
80 mutable OpenThreads::Mutex _cacheLock;
81 mutable bool _cacheDirty;
82 mutable osg::Matrix _cacheLocalToWorld;
83 mutable osg::Matrix _cache;
84};
85
86}
87#endif