Changeset 10576

Show
Ignore:
Timestamp:
09/09/09 11:52:54 (5 years ago)
Author:
cedricpinson
Message:

From Michael Platings, I have removed Target::normalize() as calling it was incorrect - the interpolation is already done in such a way that the Target's value is always normalized.
Finally, I have fixed TemplateTarget?<osg::Quat>::lerp() as it was giving incorrect results when interpolating between some small rotations.
From Cedric Pinson, i renamed the method in channel to be more general. Adjusted the CubicBezier? key constructor to use a single value as input.

Location:
OpenSceneGraph/trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgAnimation/AnimationManagerBase

    r10557 r10576  
    4747        /// Operation that must be done each frame 
    4848        void clearTargets(); 
    49         void normalizeTargets(); 
    5049 
    5150        LinkVisitor* getOrCreateLinkVisitor(); 
  • OpenSceneGraph/trunk/include/osgAnimation/Channel

    r10556 r10576  
    5555        virtual const Sampler* getSampler() const = 0; 
    5656 
     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 
    5762    protected: 
    5863     
     
    7277        Channel* clone() const { return new TemplateChannel<SamplerType>(*this); } 
    7378 
    74         TemplateChannel (const TemplateChannel& channel) :  
     79        TemplateChannel (const TemplateChannel& channel) : 
    7580            Channel(channel), 
    76             _target(new TargetType), 
     81            _target(new TargetType(*channel.getTargetTyped())), 
    7782            _sampler(channel._sampler.get()) 
    7883        { 
     
    8691                _target = new TargetType; 
    8792            _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; 
    88110        } 
    89111 
     
    121143 
    122144        TargetType* getTargetTyped() { return _target.get(); } 
     145        const TargetType* getTargetTyped() const { return _target.get(); } 
    123146        void setTarget(TargetType* target) { _target = target; } 
    124147 
  • OpenSceneGraph/trunk/include/osgAnimation/CubicBezier

    r9877 r10576  
    11/*  -*-c++-*-  
    2  *  Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net> 
     2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 
    33 * 
    44 * This library is open source and may be redistributed and/or modified under   
     
    3737            mPoint[2] = v2; 
    3838        } 
     39        // Constructor with value only 
     40        TemplateCubicBezier(const T& v0)  
     41        { 
     42            mPoint[0] = v0; 
     43            mPoint[1] = v0; 
     44            mPoint[2] = v0; 
     45        } 
    3946 
    4047        TemplateCubicBezier() {} 
  • OpenSceneGraph/trunk/include/osgAnimation/Target

    r10561 r10576  
    3636        Target(); 
    3737        virtual ~Target() {} 
    38         virtual void normalize() = 0; 
    3938        void reset() { _weight = 0; _priorityWeight = 0; } 
    4039        int getCount() const { return referenceCount(); } 
     
    5453        TemplateTarget() {} 
    5554        TemplateTarget(const T& v) { setValue(v); } 
     55        TemplateTarget(const TemplateTarget& v) { setValue(v.getValue()); } 
    5656 
    5757        inline void lerp(float t, const T& a, const T& b); 
     
    9292        const T& getValue() const { return _target; } 
    9393 
    94         inline void normalize(); 
    95  
    9694        void setValue(const T& value) { _target = value; } 
    9795 
     
    10098        T _target; 
    10199    }; 
    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 default 
    110     } 
    111100 
    112101    template <class T> 
     
    119108    inline void TemplateTarget<osg::Quat>::lerp(float t, const osg::Quat& a, const osg::Quat& b) 
    120109    { 
    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 
    122119        osg::Quat::value_type len2 = _target.length2(); 
    123120        if ( len2 != 1.0 && len2 != 0.0)  
    124121            _target *= 1.0/sqrt(len2); 
    125122    } 
    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 
    139124    typedef TemplateTarget<osg::Quat> QuatTarget; 
    140125    typedef TemplateTarget<osg::Vec3> Vec3Target; 
  • OpenSceneGraph/trunk/src/osgAnimation/AnimationManagerBase.cpp

    r10557 r10576  
    3030    for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++) 
    3131        (*it).get()->reset(); 
    32 } 
    33 void AnimationManagerBase::normalizeTargets() 
    34 { 
    35     for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++) 
    36         (*it).get()->normalize(); 
    3732} 
    3833 
  • OpenSceneGraph/trunk/src/osgAnimation/BasicAnimationManager.cpp

    r10556 r10576  
    114114        } 
    115115    } 
    116  
    117     for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++) 
    118         (*it).get()->normalize(); 
    119116} 
    120117 
  • OpenSceneGraph/trunk/src/osgAnimation/CMakeLists.txt

    r10561 r10576  
    5454    Animation.cpp 
    5555    AnimationManagerBase.cpp 
    56     AnimationManager.cpp 
    5756    BasicAnimationManager.cpp 
    5857    Bone.cpp 
  • OpenSceneGraph/trunk/src/osgAnimation/TimelineAnimationManager.cpp

    r9370 r10576  
    11/*  -*-c++-*-  
    2  *  Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net> 
     2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 
    33 * 
    44 * This library is open source and may be redistributed and/or modified under   
     
    3737    clearTargets(); 
    3838    _timeline->update(time); 
    39     normalizeTargets(); 
    4039}