From 2916d9b7eaa080b3c1fbed4fe4f703df8ddb1a39 Mon Sep 17 00:00:00 2001 From: Cedric Pinson Date: Thu, 6 Aug 2009 12:40:06 +0000 Subject: [PATCH] From Michael Platings, Changes to allow osgAnimation::*CubicBezierChannel to be used Added TemplateStepInterpolator class --- include/osgAnimation/Bone | 27 ++++++------------- include/osgAnimation/Channel | 25 ++++++++++++++--- include/osgAnimation/Interpolator | 42 +++++++++++++++++++++++++++-- include/osgAnimation/Sampler | 16 +++++++++-- src/osgAnimation/UpdateCallback.cpp | 34 +++++++---------------- 5 files changed, 92 insertions(+), 52 deletions(-) diff --git a/include/osgAnimation/Bone b/include/osgAnimation/Bone index 8c7a63d05..425b6a065 100644 --- a/include/osgAnimation/Bone +++ b/include/osgAnimation/Bone @@ -10,7 +10,11 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. -*/ + * + * Authors: + * Cedric Pinson + * Michael Platings + */ #ifndef OSGANIMATION_BONE_H #define OSGANIMATION_BONE_H @@ -129,30 +133,15 @@ namespace osgAnimation { if (channel->getName().find("quaternion") != std::string::npos) { - osgAnimation::QuatSphericalLinearChannel* qc = dynamic_cast(channel); - if (qc) - { - qc->setTarget(_quaternion.get()); - return true; - } + return channel->setTarget(_quaternion.get()); } else if (channel->getName().find("position") != std::string::npos) { - osgAnimation::Vec3LinearChannel* vc = dynamic_cast(channel); - if (vc) - { - vc->setTarget(_position.get()); - return true; - } + return channel->setTarget(_position.get()); } else if (channel->getName().find("scale") != std::string::npos) { - osgAnimation::Vec3LinearChannel* vc = dynamic_cast(channel); - if (vc) - { - vc->setTarget(_scale.get()); - return true; - } + return channel->setTarget(_scale.get()); } else { diff --git a/include/osgAnimation/Channel b/include/osgAnimation/Channel index 60062d59f..d0be95dca 100644 --- a/include/osgAnimation/Channel +++ b/include/osgAnimation/Channel @@ -1,5 +1,5 @@ /* -*-c++-*- - * Copyright (C) 2008 Cedric Pinson + * Copyright (C) 2008 Cedric Pinson * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -10,7 +10,11 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. -*/ + * + * Authors: + * Cedric Pinson + * Michael Platings + */ #ifndef OSGANIMATION_CHANNEL_H #define OSGANIMATION_CHANNEL_H @@ -36,6 +40,7 @@ namespace osgAnimation virtual void update(float time) = 0; virtual void reset() = 0; virtual Target* getTarget() = 0; + virtual bool setTarget(Target*) = 0; const std::string& getName() const; void setName(const std::string& name); @@ -98,8 +103,13 @@ namespace osgAnimation } virtual void reset() { _target->reset(); } virtual Target* getTarget() { return _target.get();} + virtual bool setTarget(Target* target) + { + _target = dynamic_cast(target); + return _target.get() == target; + } - SamplerType* getOrCreateSampler() + SamplerType* getOrCreateSampler() { if (!_sampler.valid()) _sampler = new SamplerType; @@ -126,9 +136,16 @@ namespace osgAnimation typedef std::vector > ChannelList; + + typedef TemplateChannel DoubleStepChannel; + typedef TemplateChannel FloatStepChannel; + typedef TemplateChannel Vec2StepChannel; + typedef TemplateChannel Vec3StepChannel; + typedef TemplateChannel Vec4StepChannel; + typedef TemplateChannel QuatStepChannel; + typedef TemplateChannel DoubleLinearChannel; typedef TemplateChannel FloatLinearChannel; - typedef TemplateChannel Vec2LinearChannel; typedef TemplateChannel Vec3LinearChannel; typedef TemplateChannel Vec4LinearChannel; diff --git a/include/osgAnimation/Interpolator b/include/osgAnimation/Interpolator index f50310818..5a99c1bd9 100644 --- a/include/osgAnimation/Interpolator +++ b/include/osgAnimation/Interpolator @@ -1,5 +1,5 @@ /* -*-c++-*- - * Copyright (C) 2008 Cedric Pinson + * Copyright (C) 2008 Cedric Pinson * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -10,7 +10,11 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. -*/ + * + * Authors: + * Cedric Pinson + * Michael Platings + */ #ifndef OSGANIMATION_INTERPOLATOR_H #define OSGANIMATION_INTERPOLATOR_H @@ -61,6 +65,32 @@ namespace osgAnimation }; + template + class TemplateStepInterpolator : public TemplateInterpolatorBase + { + public: + + TemplateStepInterpolator() {} + void getValue(const TemplateKeyframeContainer& keyframes, float time, TYPE& result) const + { + + if (time >= keyframes.back().getTime()) + { + result = keyframes.back().getValue(); + return; + } + else if (time <= keyframes.front().getTime()) + { + result = keyframes.front().getValue(); + return; + } + + int i = getKeyIndexFromTime(keyframes,time); + return keyframes[i].getValue(); + } + }; + + template class TemplateLinearInterpolator : public TemplateInterpolatorBase { @@ -184,6 +214,14 @@ namespace osgAnimation } }; + typedef TemplateStepInterpolator DoubleStepInterpolator; + typedef TemplateStepInterpolator FloatStepInterpolator; + typedef TemplateStepInterpolator Vec2StepInterpolator; + typedef TemplateStepInterpolator Vec3StepInterpolator; + typedef TemplateStepInterpolator Vec3PackedStepInterpolator; + typedef TemplateStepInterpolator Vec4StepInterpolator; + typedef TemplateStepInterpolator QuatStepInterpolator; + typedef TemplateLinearInterpolator DoubleLinearInterpolator; typedef TemplateLinearInterpolator FloatLinearInterpolator; typedef TemplateLinearInterpolator Vec2LinearInterpolator; diff --git a/include/osgAnimation/Sampler b/include/osgAnimation/Sampler index 1f5a66c1b..55a1b9cc9 100644 --- a/include/osgAnimation/Sampler +++ b/include/osgAnimation/Sampler @@ -1,5 +1,5 @@ /* -*-c++-*- - * Copyright (C) 2008 Cedric Pinson + * Copyright (C) 2008 Cedric Pinson * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -10,7 +10,11 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. -*/ + * + * Authors: + * Cedric Pinson + * Michael Platings + */ #ifndef OSGANIMATION_SAMPLER_H #define OSGANIMATION_SAMPLER_H @@ -108,12 +112,20 @@ namespace osgAnimation }; + typedef TemplateSampler DoubleStepSampler; + typedef TemplateSampler FloatStepSampler; + typedef TemplateSampler Vec2StepSampler; + typedef TemplateSampler Vec3StepSampler; + typedef TemplateSampler Vec4StepSampler; + typedef TemplateSampler QuatStepSampler; + typedef TemplateSampler DoubleLinearSampler; typedef TemplateSampler FloatLinearSampler; typedef TemplateSampler Vec2LinearSampler; typedef TemplateSampler Vec3LinearSampler; typedef TemplateSampler Vec4LinearSampler; typedef TemplateSampler QuatSphericalLinearSampler; + typedef TemplateSampler FloatCubicBezierSampler; typedef TemplateSampler DoubleCubicBezierSampler; typedef TemplateSampler Vec2CubicBezierSampler; diff --git a/src/osgAnimation/UpdateCallback.cpp b/src/osgAnimation/UpdateCallback.cpp index c95442db3..411c6814c 100644 --- a/src/osgAnimation/UpdateCallback.cpp +++ b/src/osgAnimation/UpdateCallback.cpp @@ -10,7 +10,11 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. -*/ + * + * Authors: + * Cedric Pinson + * Michael Platings + */ #include #include @@ -95,30 +99,15 @@ bool UpdateTransform::link(osgAnimation::Channel* channel) { if (channel->getName().find("euler") != std::string::npos) { - osgAnimation::Vec3LinearChannel* qc = dynamic_cast(channel); - if (qc) - { - qc->setTarget(_euler.get()); - return true; - } + return channel->setTarget(_euler.get()); } else if (channel->getName().find("position") != std::string::npos) { - osgAnimation::Vec3LinearChannel* vc = dynamic_cast(channel); - if (vc) - { - vc->setTarget(_position.get()); - return true; - } + return channel->setTarget(_position.get()); } else if (channel->getName().find("scale") != std::string::npos) { - osgAnimation::Vec3LinearChannel* vc = dynamic_cast(channel); - if (vc) - { - vc->setTarget(_scale.get()); - return true; - } + return channel->setTarget(_scale.get()); } else { @@ -171,12 +160,7 @@ bool UpdateMaterial::link(osgAnimation::Channel* channel) { if (channel->getName().find("diffuse") != std::string::npos) { - osgAnimation::Vec4LinearChannel* d = dynamic_cast(channel); - if (d) - { - d->setTarget(_diffuse.get()); - return true; - } + return channel->setTarget(_diffuse.get()); } else {