OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AnimationMaterial.h
Go to the documentation of this file.
1 /* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2  *
3  * This software is open source and may be redistributed and/or modified under
4  * the terms of the GNU General Public License (GPL) version 2.0.
5  * The full license is in LICENSE.txt file included with this distribution,.
6  *
7  * This software is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * include LICENSE.txt for more details.
11 */
12 
13 #ifndef OSG_ANIMATIONMATERIAL
14 #define OSG_ANIMATIONMATERIAL 1
15 
16 #include <osg/Material>
17 #include <osg/Callback>
18 
19 #include <osgPresentation/Export>
20 
21 #include <iosfwd>
22 #include <map>
23 #include <float.h>
24 
25 namespace osgPresentation {
26 
32 {
33  public:
34 
35  AnimationMaterial():_loopMode(LOOP) {}
36 
38  Object(ap,copyop),
39  _timeControlPointMap(ap._timeControlPointMap),
40  _loopMode(ap._loopMode) {}
41 
43 
44 
46  bool getMaterial(double time,osg::Material& material) const;
47 
48  void insert(double time,osg::Material* material);
49 
50  double getFirstTime() const { if (!_timeControlPointMap.empty()) return _timeControlPointMap.begin()->first; else return 0.0;}
51  double getLastTime() const { if (!_timeControlPointMap.empty()) return _timeControlPointMap.rbegin()->first; else return 0.0;}
52  double getPeriod() const { return getLastTime()-getFirstTime();}
53 
54  enum LoopMode
55  {
58  NO_LOOPING
59  };
60 
61  void setLoopMode(LoopMode lm) { _loopMode = lm; }
62 
63  LoopMode getLoopMode() const { return _loopMode; }
64 
65 
66  typedef std::map<double, osg::ref_ptr<osg::Material> > TimeControlPointMap;
67 
68  TimeControlPointMap& getTimeControlPointMap() { return _timeControlPointMap; }
69 
70  const TimeControlPointMap& getTimeControlPointMap() const { return _timeControlPointMap; }
71 
73  void read(std::istream& in);
74 
76  void write(std::ostream& out) const;
77 
78  bool requiresBlending() const;
79 
80  protected:
81 
82  virtual ~AnimationMaterial() {}
83 
84  void interpolate(osg::Material& material, float r, const osg::Material& lhs,const osg::Material& rhs) const;
85 
86  TimeControlPointMap _timeControlPointMap;
88 
89 };
90 
91 
93 {
94  public:
95 
97  _timeOffset(0.0),
98  _timeMultiplier(1.0),
99  _firstTime(DBL_MAX),
100  _latestTime(0.0),
101  _pause(false),
102  _pauseTime(0.0) {}
103 
104 
106  osg::NodeCallback(apc,copyop),
107  _animationMaterial(apc._animationMaterial),
108  _useInverseMatrix(apc._useInverseMatrix),
109  _timeOffset(apc._timeOffset),
110  _timeMultiplier(apc._timeMultiplier),
111  _firstTime(apc._firstTime),
112  _latestTime(apc._latestTime),
113  _pause(apc._pause),
114  _pauseTime(apc._pauseTime) {}
115 
116 
118 
119  AnimationMaterialCallback(AnimationMaterial* ap,double timeOffset=0.0f,double timeMultiplier=1.0f):
120  _animationMaterial(ap),
121  _useInverseMatrix(false),
122  _timeOffset(timeOffset),
123  _timeMultiplier(timeMultiplier),
124  _firstTime(DBL_MAX),
125  _latestTime(0.0),
126  _pause(false),
127  _pauseTime(0.0) {}
128 
129  void setAnimationMaterial(AnimationMaterial* path) { _animationMaterial = path; }
130 
131  AnimationMaterial* getAnimationMaterial() { return _animationMaterial.get(); }
132 
133  const AnimationMaterial* getAnimationMaterial() const { return _animationMaterial.get(); }
134 
135  void setTimeOffset(double offset) { _timeOffset = offset; }
136  double getTimeOffset() const { return _timeOffset; }
137 
138  void setTimeMultiplier(double multiplier) { _timeMultiplier = multiplier; }
139  double getTimeMultiplier() const { return _timeMultiplier; }
140 
141  void reset();
142 
143  void setPause(bool pause);
144 
147  double getAnimationTime() const;
148 
150  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
151 
152  void update(osg::Node& node);
153 
154  public:
155 
158  double _timeOffset;
160  double _firstTime;
161  double _latestTime;
162  bool _pause;
163  double _pauseTime;
164 
165  protected:
166 
168 
169 };
170 
171 }
172 
173 #endif
TimeControlPointMap _timeControlPointMap
std::map< double, osg::ref_ptr< osg::Material > > TimeControlPointMap
#define OSGPRESENTATION_EXPORT
Definition: Export.h:38
const AnimationMaterial * getAnimationMaterial() const
const TimeControlPointMap & getTimeControlPointMap() const
AnimationMaterialCallback(AnimationMaterial *ap, double timeOffset=0.0f, double timeMultiplier=1.0f)
#define META_Object(library, name)
Definition: Object.h:42
Definition: Node.h:71
AnimationMaterial(const AnimationMaterial &ap, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: AlphaFunc.h:19
osg::ref_ptr< AnimationMaterial > _animationMaterial
TimeControlPointMap & getTimeControlPointMap()
AnimationMaterialCallback(const AnimationMaterialCallback &apc, const osg::CopyOp &copyop)
void setAnimationMaterial(AnimationMaterial *path)