| | 197 | // Sine function |
| | 198 | struct OutSineFunction |
| | 199 | { |
| | 200 | inline static void getValueAt(float t, float& result) |
| | 201 | { |
| | 202 | result = sinf(t * (osg::PI / 2.0f)); |
| | 203 | } |
| | 204 | }; |
| | 205 | |
| | 206 | struct InSineFunction |
| | 207 | { |
| | 208 | inline static void getValueAt(float t, float& result) |
| | 209 | { |
| | 210 | result = -cosf(t * (osg::PI / 2.0f)) + 1.0f; |
| | 211 | } |
| | 212 | }; |
| | 213 | |
| | 214 | struct InOutSineFunction |
| | 215 | { |
| | 216 | inline static void getValueAt(float t, float& result) |
| | 217 | { |
| | 218 | result = -0.5f * (cosf((osg::PI * t)) - 1.0f); |
| | 219 | } |
| | 220 | }; |
| | 221 | |
| | 222 | // Back function |
| | 223 | struct OutBackFunction |
| | 224 | { |
| | 225 | inline static void getValueAt(float t, float& result) |
| | 226 | { |
| | 227 | t -= 1.0f; |
| | 228 | result = t * t * ((1.70158 + 1.0f) * t + 1.70158) + 1.0f; |
| | 229 | } |
| | 230 | }; |
| | 231 | |
| | 232 | struct InBackFunction |
| | 233 | { |
| | 234 | inline static void getValueAt(float t, float& result) |
| | 235 | { |
| | 236 | result = t * t * ((1.70158 + 1.0f) * t - 1.70158); |
| | 237 | } |
| | 238 | }; |
| | 239 | |
| | 240 | struct InOutBackFunction |
| | 241 | { |
| | 242 | inline static void getValueAt(float t, float& result) |
| | 243 | { |
| | 244 | float s = 1.70158 * 1.525f; |
| | 245 | t *= 2.0f; |
| | 246 | if (t < 1.0f) |
| | 247 | { |
| | 248 | result = 0.5f * (t * t * ((s + 1.0f) * t - s)); |
| | 249 | } |
| | 250 | else |
| | 251 | { |
| | 252 | float p = t -= 2.0f; |
| | 253 | result = 0.5f * ((p) * t * ((s + 1.0f) * t + s) + 2.0f); |
| | 254 | } |
| | 255 | } |
| | 256 | }; |
| | 257 | |
| | 258 | // Circ function |
| | 259 | struct OutCircFunction |
| | 260 | { |
| | 261 | inline static void getValueAt(float t, float& result) |
| | 262 | { |
| | 263 | t -= 1.0f; |
| | 264 | result = sqrt(1.0f - t * t); |
| | 265 | } |
| | 266 | }; |
| | 267 | |
| | 268 | struct InCircFunction |
| | 269 | { |
| | 270 | inline static void getValueAt(float t, float& result) |
| | 271 | { |
| | 272 | result = -(sqrt(1.0f - (t * t)) - 1.0f); |
| | 273 | } |
| | 274 | }; |
| | 275 | |
| | 276 | struct InOutCircFunction |
| | 277 | { |
| | 278 | inline static void getValueAt(float t, float& result) |
| | 279 | { |
| | 280 | t *= 2.0f; |
| | 281 | if (t < 1.0f) |
| | 282 | { |
| | 283 | result = -0.5f * (sqrt(1.0f - t * t) - 1.0f); |
| | 284 | } |
| | 285 | else |
| | 286 | { |
| | 287 | t -= 2.0f; |
| | 288 | result = 0.5f * (sqrt(1 - t * t) + 1.0f); |
| | 289 | } |
| | 290 | } |
| | 291 | }; |
| | 292 | |
| | 293 | // Expo function |
| | 294 | struct OutExpoFunction |
| | 295 | { |
| | 296 | inline static void getValueAt(float t, float& result) |
| | 297 | { |
| | 298 | if(t == 1.0f) |
| | 299 | { |
| | 300 | result = 0.0f; |
| | 301 | } |
| | 302 | else |
| | 303 | { |
| | 304 | result = -powf(2.0f, -10.0f * t) + 1.0f; |
| | 305 | } |
| | 306 | } |
| | 307 | }; |
| | 308 | |
| | 309 | struct InExpoFunction |
| | 310 | { |
| | 311 | inline static void getValueAt(float t, float& result) |
| | 312 | { |
| | 313 | if(t == 0.0f) |
| | 314 | { |
| | 315 | result = 0.0f; |
| | 316 | } |
| | 317 | else |
| | 318 | { |
| | 319 | result = powf(2.0f, 10.0f * (t - 1.0f)); |
| | 320 | } |
| | 321 | } |
| | 322 | }; |
| | 323 | |
| | 324 | struct InOutExpoFunction |
| | 325 | { |
| | 326 | inline static void getValueAt(float t, float& result) |
| | 327 | { |
| | 328 | if(t == 0.0f || t == 1.0f) |
| | 329 | { |
| | 330 | result = 0.0f; |
| | 331 | } |
| | 332 | else |
| | 333 | { |
| | 334 | t *= 2.0f; |
| | 335 | if(t < 1.0f) |
| | 336 | { |
| | 337 | result = 0.5f * powf(2.0f, 10.0f * (t - 1.0f)); |
| | 338 | } |
| | 339 | else |
| | 340 | { |
| | 341 | result = 0.5f * (-powf(2.0f, -10.0f * (t - 1.0f)) + 2.0f); |
| | 342 | } |
| | 343 | } |
| | 344 | } |
| | 345 | }; |
| | 509 | // sine |
| | 510 | typedef MathMotionTemplate<OutSineFunction > OutSineMotion; |
| | 511 | typedef MathMotionTemplate<InSineFunction > InSineMotion; |
| | 512 | typedef MathMotionTemplate<InOutSineFunction > InOutSineMotion; |
| | 513 | |
| | 514 | // back |
| | 515 | typedef MathMotionTemplate<OutBackFunction > OutBackMotion; |
| | 516 | typedef MathMotionTemplate<InBackFunction > InBackMotion; |
| | 517 | typedef MathMotionTemplate<InOutBackFunction > InOutBackMotion; |
| | 518 | |
| | 519 | // circ |
| | 520 | typedef MathMotionTemplate<OutCircFunction > OutCircMotion; |
| | 521 | typedef MathMotionTemplate<InCircFunction > InCircMotion; |
| | 522 | typedef MathMotionTemplate<InOutCircFunction > InOutCircMotion; |
| | 523 | |
| | 524 | // expo |
| | 525 | typedef MathMotionTemplate<OutExpoFunction > OutExpoMotion; |
| | 526 | typedef MathMotionTemplate<InExpoFunction > InExpoMotion; |
| | 527 | typedef MathMotionTemplate<InOutExpoFunction > InOutExpoMotion; |