AnimatLab  2
Test
VsAutoTransform.h
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 
14 //#ifndef OSG_AUTOTRANSFORM
15 //#define OSG_AUTOTRANSFORM 1
16 
17 #include "StdAfx.h"
18 //#include <osg/Group>
19 //#include <osg/Transform>
20 //#include <osg/Quat>
21 //#include <osg/Viewport>
22 
23 namespace VortexAnimatSim
24 {
25  namespace Visualization
26  {
27 
31 class VsAutoTransform : public osg::Transform
32 {
33  public :
35 
36  VsAutoTransform(const VsAutoTransform& pat,const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY);
37 
38  virtual osg::Object* cloneType() const { return new VsAutoTransform (); }
39  virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new VsAutoTransform (*this,copyop); }
40  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const VsAutoTransform *>(obj)!=NULL; }
41  virtual const char* className() const { return "VsAutoTransform"; }
42  virtual const char* libraryName() const { return "osg"; }
43 
44  virtual void accept(osg::NodeVisitor& nv);
45 
46  virtual VsAutoTransform* asAutoTransform() { return this; }
47  virtual const VsAutoTransform* asAutoTransform() const { return this; }
48 
49  inline void setPosition(const osg::Vec3d& pos) { _position = pos; _matrixDirty=true; dirtyBound(); }
50  inline const osg::Vec3d& getPosition() const { return _position; }
51 
52 
53  inline void setRotation(const osg::Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); }
54  inline const osg::Quat& getRotation() const { return _rotation; }
55 
56  inline void setScale(double scale) { setScale(osg::Vec3(scale,scale,scale)); }
57 
58  void setScale(const osg::Vec3d& scale);
59  inline const osg::Vec3d& getScale() { return _scale; }
60 
61  void setMinimumScale(double minimumScale) { _minimumScale = minimumScale; }
62  double getMinimumScale() { return _minimumScale; }
63 
64  void setMaximumScale(double maximumScale) { _maximumScale = maximumScale; }
65  double getMaximumScale() { return _maximumScale; }
66 
67  inline void setPivotPoint(const osg::Vec3d& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); }
68  inline const osg::Vec3d& getPivotPoint() { return _pivotPoint; }
69 
70 
71  void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; }
72  float getAutoUpdateEyeMovementTolerance() { return _autoUpdateEyeMovementTolerance; }
73 
74 
75  enum AutoRotateMode
76  {
77  NO_ROTATION,
78  ROTATE_TO_SCREEN,
79  ROTATE_TO_CAMERA
80  };
81 
82  void setAutoRotateMode(AutoRotateMode mode) { _autoRotateMode = mode; _firstTimeToInitEyePoint = true; }
83 
84  AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; }
85 
86  void setAutoScaleToScreen(bool autoScaleToScreen) { _autoScaleToScreen = autoScaleToScreen; _matrixDirty=true; }
87 
88  bool getAutoScaleToScreen() const { return _autoScaleToScreen; }
89 
90  void setAutoScaleTransitionWidthRatio(float ratio) { _autoScaleTransitionWidthRatio = ratio; }
91  float getAutoScaleTransitionWidthRatio() const { return _autoScaleTransitionWidthRatio; }
92 
93 
94  virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
95 
96  virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
97 
98  virtual osg::BoundingSphere computeBound() const;
99 
100 
101  protected :
102 
103  virtual ~VsAutoTransform() {}
104 
105  osg::Vec3d _position;
106  osg::Vec3d _pivotPoint;
107  double _autoUpdateEyeMovementTolerance;
108 
109  AutoRotateMode _autoRotateMode;
110 
111  bool _autoScaleToScreen;
112 
113  mutable osg::Quat _rotation;
114  mutable osg::Vec3d _scale;
115  mutable bool _firstTimeToInitEyePoint;
116  mutable osg::Vec3 _previousEyePoint;
117  mutable osg::Vec3 _previousLocalUp;
118  mutable osg::Viewport::value_type _previousWidth;
119  mutable osg::Viewport::value_type _previousHeight;
120  mutable osg::Matrixd _previousProjection;
121  mutable osg::Vec3d _previousPosition;
122 
123  double _minimumScale;
124  double _maximumScale;
125  double _autoScaleTransitionWidthRatio;
126 
127  void computeMatrix() const;
128 
129  mutable bool _matrixDirty;
130  mutable osg::Matrixd _cachedMatrix;
131 };
132 
133  }// end Visualization
134 }// end VortexAnimatSim
135 
136 //#endif
Classes for implementing the cm-labs vortex physics engine for AnimatLab.