Changeset 13041 for OpenSceneGraph/trunk/include/osgAnimation/Interpolator
- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgAnimation/Interpolator
r12608 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 * 14 14 * Authors: 15 15 * Cedric Pinson <cedric.pinson@plopbyte.net> … … 39 39 40 40 void reset() { _lastKeyAccess = -1; } 41 int getKeyIndexFromTime(const TemplateKeyframeContainer<KEY>& keys, double time) const 41 int getKeyIndexFromTime(const TemplateKeyframeContainer<KEY>& keys, double time) const 42 42 { 43 43 // todo use a cache … … 53 53 double time1 = keysVector[i+1].getTime(); 54 54 55 if ( time >= time0 && time < time1 ) 55 if ( time >= time0 && time < time1 ) 56 56 { 57 57 _lastKeyAccess = i; … … 71 71 72 72 TemplateStepInterpolator() {} 73 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 74 { 75 76 if (time >= keyframes.back().getTime()) 73 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 74 { 75 76 if (time >= keyframes.back().getTime()) 77 77 { 78 78 result = keyframes.back().getValue(); 79 79 return; 80 } 81 else if (time <= keyframes.front().getTime()) 80 } 81 else if (time <= keyframes.front().getTime()) 82 82 { 83 83 result = keyframes.front().getValue(); … … 97 97 98 98 TemplateLinearInterpolator() {} 99 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 100 { 101 102 if (time >= keyframes.back().getTime()) 99 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 100 { 101 102 if (time >= keyframes.back().getTime()) 103 103 { 104 104 result = keyframes.back().getValue(); 105 105 return; 106 } 107 else if (time <= keyframes.front().getTime()) 106 } 107 else if (time <= keyframes.front().getTime()) 108 108 { 109 109 result = keyframes.front().getValue(); 110 110 return; 111 111 } 112 112 113 113 int i = this->getKeyIndexFromTime(keyframes,time); 114 114 float blend = (time - keyframes[i].getTime()) / ( keyframes[i+1].getTime() - keyframes[i].getTime()); … … 125 125 public: 126 126 TemplateSphericalLinearInterpolator() {} 127 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 128 { 129 if (time >= keyframes.back().getTime()) 127 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 128 { 129 if (time >= keyframes.back().getTime()) 130 130 { 131 131 result = keyframes.back().getValue(); 132 132 return; 133 133 } 134 else if (time <= keyframes.front().getTime()) 134 else if (time <= keyframes.front().getTime()) 135 135 { 136 136 result = keyframes.front().getValue(); … … 153 153 154 154 TemplateLinearPackedInterpolator() {} 155 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 156 { 157 if (time >= keyframes.back().getTime()) 155 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 156 { 157 if (time >= keyframes.back().getTime()) 158 158 { 159 159 keyframes.back().getValue().uncompress(keyframes.mScale, keyframes.mMin, result); 160 160 return; 161 161 } 162 else if (time <= keyframes.front().getTime()) 162 else if (time <= keyframes.front().getTime()) 163 163 { 164 164 keyframes.front().getValue().uncompress(keyframes.mScale, keyframes.mMin, result); … … 183 183 184 184 TemplateCubicBezierInterpolator() {} 185 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 186 { 187 188 if (time >= keyframes.back().getTime()) 185 void getValue(const TemplateKeyframeContainer<KEY>& keyframes, double time, TYPE& result) const 186 { 187 188 if (time >= keyframes.back().getTime()) 189 189 { 190 190 result = keyframes.back().getValue().getPosition(); 191 191 return; 192 192 } 193 else if (time <= keyframes.front().getTime()) 193 else if (time <= keyframes.front().getTime()) 194 194 { 195 195 result = keyframes.front().getValue().getPosition(); … … 198 198 199 199 int i = this->getKeyIndexFromTime(keyframes,time); 200 200 201 201 float t = (time - keyframes[i].getTime()) / ( keyframes[i+1].getTime() - keyframes[i].getTime()); 202 202 float one_minus_t = 1.0-t;
