Changeset 10576
- Timestamp:
- 09/09/09 11:52:54 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 8 modified
-
include/osgAnimation/AnimationManagerBase (modified) (1 diff)
-
include/osgAnimation/Channel (modified) (4 diffs)
-
include/osgAnimation/CubicBezier (modified) (2 diffs)
-
include/osgAnimation/Target (modified) (5 diffs)
-
src/osgAnimation/AnimationManagerBase.cpp (modified) (1 diff)
-
src/osgAnimation/BasicAnimationManager.cpp (modified) (1 diff)
-
src/osgAnimation/CMakeLists.txt (modified) (1 diff)
-
src/osgAnimation/TimelineAnimationManager.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgAnimation/AnimationManagerBase
r10557 r10576 47 47 /// Operation that must be done each frame 48 48 void clearTargets(); 49 void normalizeTargets();50 49 51 50 LinkVisitor* getOrCreateLinkVisitor(); -
OpenSceneGraph/trunk/include/osgAnimation/Channel
r10556 r10576 55 55 virtual const Sampler* getSampler() const = 0; 56 56 57 // create a keyframe container from current target value 58 // with one key only, can be used for debug or to create 59 // easily a default channel from an existing one 60 virtual bool createKeyframeContainerFromTargetValue() = 0; 61 57 62 protected: 58 63 … … 72 77 Channel* clone() const { return new TemplateChannel<SamplerType>(*this); } 73 78 74 TemplateChannel (const TemplateChannel& channel) : 79 TemplateChannel (const TemplateChannel& channel) : 75 80 Channel(channel), 76 _target(new TargetType ),81 _target(new TargetType(*channel.getTargetTyped())), 77 82 _sampler(channel._sampler.get()) 78 83 { … … 86 91 _target = new TargetType; 87 92 _sampler = s; 93 } 94 95 virtual bool createKeyframeContainerFromTargetValue() 96 { 97 if (!_target.valid()) // no target it does not make sense to do it 98 { 99 return false; 100 } 101 102 // create a key from current target value 103 typename KeyframeContainerType::KeyType key(0, _target->getValue()); 104 // recreate the keyframe container 105 getOrCreateSampler()->setKeyframeContainer(0); 106 getOrCreateSampler()->getOrCreateKeyframeContainer(); 107 // add the key 108 _sampler->getKeyframeContainerTyped()->push_back(key); 109 return true; 88 110 } 89 111 … … 121 143 122 144 TargetType* getTargetTyped() { return _target.get(); } 145 const TargetType* getTargetTyped() const { return _target.get(); } 123 146 void setTarget(TargetType* target) { _target = target; } 124 147 -
OpenSceneGraph/trunk/include/osgAnimation/CubicBezier
r9877 r10576 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 37 37 mPoint[2] = v2; 38 38 } 39 // Constructor with value only 40 TemplateCubicBezier(const T& v0) 41 { 42 mPoint[0] = v0; 43 mPoint[1] = v0; 44 mPoint[2] = v0; 45 } 39 46 40 47 TemplateCubicBezier() {} -
OpenSceneGraph/trunk/include/osgAnimation/Target
r10561 r10576 36 36 Target(); 37 37 virtual ~Target() {} 38 virtual void normalize() = 0;39 38 void reset() { _weight = 0; _priorityWeight = 0; } 40 39 int getCount() const { return referenceCount(); } … … 54 53 TemplateTarget() {} 55 54 TemplateTarget(const T& v) { setValue(v); } 55 TemplateTarget(const TemplateTarget& v) { setValue(v.getValue()); } 56 56 57 57 inline void lerp(float t, const T& a, const T& b); … … 92 92 const T& getValue() const { return _target; } 93 93 94 inline void normalize();95 96 94 void setValue(const T& value) { _target = value; } 97 95 … … 100 98 T _target; 101 99 }; 102 103 template <class T>104 inline void TemplateTarget<T>::normalize()105 {106 _weight += _priorityWeight * (1.0f - _weight);107 if (_weight < 0.9999f )108 if (_weight > 0.0001f)109 _target /= _weight; // rescale by default110 }111 100 112 101 template <class T> … … 119 108 inline void TemplateTarget<osg::Quat>::lerp(float t, const osg::Quat& a, const osg::Quat& b) 120 109 { 121 _target = a * (1.0f - t) + b * t; 110 if (a.asVec4() * b.asVec4() < 0.0) 111 { 112 _target = a * (1.0f - t) + b * -t; 113 } 114 else 115 { 116 _target = a * (1.0f - t) + b * t; 117 } 118 122 119 osg::Quat::value_type len2 = _target.length2(); 123 120 if ( len2 != 1.0 && len2 != 0.0) 124 121 _target *= 1.0/sqrt(len2); 125 122 } 126 template <> 127 inline void TemplateTarget<osg::Quat>::normalize() 128 { 129 _weight += _priorityWeight * (1.0f - _weight); 130 if (_weight < 0.9999f ) 131 if (_weight > 0.0001f) 132 { 133 osg::Quat::value_type len2 = _target.length2(); // normalize 134 if ( len2 != 1.0 && len2 != 0.0) 135 _target *= 1.0/sqrt(len2); 136 } 137 } 138 123 139 124 typedef TemplateTarget<osg::Quat> QuatTarget; 140 125 typedef TemplateTarget<osg::Vec3> Vec3Target; -
OpenSceneGraph/trunk/src/osgAnimation/AnimationManagerBase.cpp
r10557 r10576 30 30 for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++) 31 31 (*it).get()->reset(); 32 }33 void AnimationManagerBase::normalizeTargets()34 {35 for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++)36 (*it).get()->normalize();37 32 } 38 33 -
OpenSceneGraph/trunk/src/osgAnimation/BasicAnimationManager.cpp
r10556 r10576 114 114 } 115 115 } 116 117 for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++)118 (*it).get()->normalize();119 116 } 120 117 -
OpenSceneGraph/trunk/src/osgAnimation/CMakeLists.txt
r10561 r10576 54 54 Animation.cpp 55 55 AnimationManagerBase.cpp 56 AnimationManager.cpp57 56 BasicAnimationManager.cpp 58 57 Bone.cpp -
OpenSceneGraph/trunk/src/osgAnimation/TimelineAnimationManager.cpp
r9370 r10576 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 37 37 clearTargets(); 38 38 _timeline->update(time); 39 normalizeTargets();40 39 }
