Changeset 13041 for OpenSceneGraph/trunk/include/osgAnimation/EaseMotion
 Timestamp:
 03/21/12 18:36:20 (4 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/include/osgAnimation/EaseMotion
r12139 r13041 1 /* *c++* 1 /* *c++* 2 2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 * This library is open source and may be redistributed and/or modified under 5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 4 * This library is open source and may be redistributed and/or modified under 5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 6 6 * (at your option) any later version. The full license is in LICENSE file 7 7 * included with this distribution, and on the openscenegraph.org website. 8 * 8 * 9 9 * This library is distributed in the hope that it will be useful, 10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 12 * OpenSceneGraph Public License for more details. 13 13 */ … … 24 24 namespace osgAnimation 25 25 { 26 struct OutBounceFunction 27 { 28 inline static void getValueAt(float t, float& result) 29 { 30 if ((t) < (1/2.75)) 26 struct OutBounceFunction 27 { 28 inline static void getValueAt(float t, float& result) 29 { 30 if ((t) < (1/2.75)) 31 31 { 32 32 result = 7.5625 * t * t; 33 } 34 else if (t < (2/2.75)) 33 } 34 else if (t < (2/2.75)) 35 35 { 36 36 t = t  (1.5/2.75); 37 37 result = 7.5625* t * t + .75; 38 38 } 39 else if (t < (2.5/2.75)) 39 else if (t < (2.5/2.75)) 40 40 { 41 41 t = t  (2.25/2.75); 42 42 result = 7.5625 * t * t + .9375; 43 43 } 44 else 44 else 45 45 { 46 46 t = t  (2.625/2.75); … … 50 50 }; 51 51 52 struct InBounceFunction 53 { 54 inline static void getValueAt(float t, float& result) 55 { 52 struct InBounceFunction 53 { 54 inline static void getValueAt(float t, float& result) 55 { 56 56 OutBounceFunction::getValueAt(1t, result); 57 57 result = 1  result; … … 59 59 }; 60 60 61 struct InOutBounceFunction 62 { 63 inline static void getValueAt(float t, float& result) 64 { 65 if (t < 0.5) 61 struct InOutBounceFunction 62 { 63 inline static void getValueAt(float t, float& result) 64 { 65 if (t < 0.5) 66 66 { 67 67 InBounceFunction::getValueAt(t * 2, result); 68 68 result *= 0.5; 69 } 70 else 69 } 70 else 71 71 { 72 72 OutBounceFunction::getValueAt(t * 2  1 , result); … … 77 77 78 78 /// Linear function 79 struct LinearFunction 79 struct LinearFunction 80 80 { 81 81 inline static void getValueAt(float t, float& result) { result = t;} … … 83 83 84 84 /// Quad function 85 struct OutQuadFunction 85 struct OutQuadFunction 86 86 { 87 87 inline static void getValueAt(float t, float& result) { result =  (t * (t 2.0));} 88 88 }; 89 89 90 struct InQuadFunction 90 struct InQuadFunction 91 91 { 92 92 inline static void getValueAt(float t, float& result) { result = t*t;} 93 93 }; 94 94 95 struct InOutQuadFunction 96 { 97 inline static void getValueAt(float t, float& result) 95 struct InOutQuadFunction 96 { 97 inline static void getValueAt(float t, float& result) 98 98 { 99 99 t *= 2.0; 100 if (t < 1.0) 100 if (t < 1.0) 101 101 result = 0.5 * t * t; 102 else 102 else 103 103 { 104 104 t = 1.0; … … 109 109 110 110 /// Cubic function 111 struct OutCubicFunction 111 struct OutCubicFunction 112 112 { 113 113 inline static void getValueAt(float t, float& result) { t = t1.0; result = t*t*t + 1;} 114 114 }; 115 115 116 struct InCubicFunction 116 struct InCubicFunction 117 117 { 118 118 inline static void getValueAt(float t, float& result) { result = t*t*t;} 119 119 }; 120 120 121 struct InOutCubicFunction 122 { 123 inline static void getValueAt(float t, float& result) 124 { 121 struct InOutCubicFunction 122 { 123 inline static void getValueAt(float t, float& result) 124 { 125 125 t *= 2.0f; 126 126 if (t < 1.0f) … … 132 132 } 133 133 }; 134 134 135 135 /// Quart function 136 struct InQuartFunction 136 struct InQuartFunction 137 137 { 138 138 inline static void getValueAt(float t, float& result) { result = t*t*t*t*t;} … … 146 146 struct InOutQuartFunction 147 147 { 148 inline static void getValueAt(float t, float& result) 148 inline static void getValueAt(float t, float& result) 149 149 { 150 150 t = t * 2.0; … … 160 160 161 161 /// Elastic function 162 struct OutElasticFunction 163 { 164 inline static void getValueAt(float t, float& result) 162 struct OutElasticFunction 163 { 164 inline static void getValueAt(float t, float& result) 165 165 { 166 166 result = pow(2.0f, 10.0f * t) * sinf((t  0.3f / 4.0f) * (2.0f * osg::PI) / 0.3f) + 1.0f; … … 168 168 }; 169 169 170 struct InElasticFunction 171 { 172 inline static void getValueAt(float t, float& result) 170 struct InElasticFunction 171 { 172 inline static void getValueAt(float t, float& result) 173 173 { 174 174 OutElasticFunction::getValueAt(1.0f  t, result); … … 177 177 }; 178 178 179 struct InOutElasticFunction 180 { 181 inline static void getValueAt(float t, float& result) 179 struct InOutElasticFunction 180 { 181 inline static void getValueAt(float t, float& result) 182 182 { 183 183 t *= 2.0f; … … 244 244 float s = 1.70158 * 1.525f; 245 245 t *= 2.0f; 246 if (t < 1.0f) 246 if (t < 1.0f) 247 247 { 248 248 result = 0.5f * (t * t * ((s + 1.0f) * t  s)); … … 318 318 { 319 319 result = powf(2.0f, 10.0f * (t  1.0f)); 320 } 320 } 321 321 } 322 322 }; … … 349 349 public: 350 350 typedef float value_type; 351 enum TimeBehaviour 351 enum TimeBehaviour 352 352 { 353 353 CLAMP, … … 360 360 float evaluateTime(float time) const 361 361 { 362 switch (_behaviour) 362 switch (_behaviour) 363 363 { 364 364 case CLAMP: … … 382 382 _time = evaluateTime(_time + dt); 383 383 } 384 384 385 385 void setTime(float time) { _time = evaluateTime(time);} 386 386 void getValue(value_type& result) const { getValueAt(_time, result); } … … 398 398 } 399 399 value_type getValueAt(float time) const 400 { 400 { 401 401 value_type result; 402 402 getValueAt(evaluateTime(time), result); … … 407 407 408 408 float getDuration() const { return _duration;} 409 protected: 409 protected: 410 410 float _time; 411 411 float _startValue; … … 432 432 const T& getSampler() const { return _sampler;} 433 433 virtual void getValueInNormalizedRange(float t, value_type& result) const 434 { 435 if (!_sampler.getKeyframeContainer()) 434 { 435 if (!_sampler.getKeyframeContainer()) 436 436 { 437 437 result = 0; … … 448 448 typedef std::vector<osg::ref_ptr<Motion> > MotionList; 449 449 MotionList _motions; 450 450 451 451 MotionList& getMotionList() { return _motions; } 452 452 const MotionList& getMotionList() const { return _motions; } 453 453 CompositeMotion(float startValue = 0, float duration = 1, float changeValue = 1, TimeBehaviour tb = CLAMP) : Motion(startValue, duration, changeValue, tb) {} 454 454 455 virtual void getValueInNormalizedRange(float t, value_type& result) const 455 virtual void getValueInNormalizedRange(float t, value_type& result) const 456 456 { 457 457 if (_motions.empty()) … … 521 521 typedef MathMotionTemplate<InCircFunction > InCircMotion; 522 522 typedef MathMotionTemplate<InOutCircFunction > InOutCircMotion; 523 523 524 524 // expo 525 525 typedef MathMotionTemplate<OutExpoFunction > OutExpoMotion;