#
root/OpenSceneGraph/trunk/include/osgAnimation/CubicBezier
@
10576

Revision 10576, 2.4 kB (checked in by cedricpinson, 5 years ago) |
---|

Rev | Line | |
---|---|---|

[9093] | 1 | /* -*-c++-*- |

[10576] | 2 | * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> |

[9093] | 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 | |

6 | * (at your option) any later version. The full license is in LICENSE file | |

7 | * included with this distribution, and on the openscenegraph.org website. | |

8 | * | |

9 | * This library is distributed in the hope that it will be useful, | |

10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |

11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |

12 | * OpenSceneGraph Public License for more details. | |

13 | */ | |

14 | ||

15 | #ifndef OSGANIMATION_CUBIC_BEZIER_H | |

16 | #define OSGANIMATION_CUBIC_BEZIER_H | |

17 | ||

18 | #include <osg/Vec2> | |

19 | #include <osg/Vec3> | |

20 | #include <osg/Vec4> | |

21 | #include <osg/Quat> | |

22 | ||

23 | namespace osgAnimation | |

24 | { | |

25 | ||

26 | template <class T> | |

27 | struct TemplateCubicBezier | |

28 | { | |

29 | T mPoint[3]; | |

30 | const T& getP0() const { return mPoint[0];} | |

31 | const T& getP1() const { return mPoint[1];} | |

32 | const T& getP2() const { return mPoint[2];} | |

33 | TemplateCubicBezier(const T& v0, const T& v1, const T& v2) | |

34 | { | |

35 | mPoint[0] = v0; | |

36 | mPoint[1] = v1; | |

37 | mPoint[2] = v2; | |

38 | } | |

[10576] | 39 | // Constructor with value only |

40 | TemplateCubicBezier(const T& v0) | |

41 | { | |

42 | mPoint[0] = v0; | |

43 | mPoint[1] = v0; | |

44 | mPoint[2] = v0; | |

45 | } | |

[9093] | 46 | |

47 | TemplateCubicBezier() {} | |

48 | ||

49 | const T& getPosition() const { return mPoint[0];} | |

50 | const T& getTangentPoint1() const { return mPoint[1];} | |

51 | const T& getTangentPoint2() const { return mPoint[2];} | |

[9877] | 52 | |

53 | // steaming operators. | |

54 | friend std::ostream& operator << (std::ostream& output, const TemplateCubicBezier<T>& vec) | |

55 | { | |

56 | output << vec.mPoint[0] << " " | |

57 | << vec.mPoint[1] << " " | |

58 | << vec.mPoint[2]; | |

59 | return output; // to enable cascading | |

60 | } | |

61 | ||

62 | friend std::istream& operator >> (std::istream& input, TemplateCubicBezier<T>& vec) | |

63 | { | |

64 | input >> vec.mPoint[0] >> vec.mPoint[1] >> vec.mPoint[2]; | |

65 | return input; | |

66 | } | |

[9093] | 67 | }; |

68 | ||

69 | ||

70 | typedef TemplateCubicBezier<float> FloatCubicBezier; | |

71 | typedef TemplateCubicBezier<double> DoubleCubicBezier; | |

72 | typedef TemplateCubicBezier<osg::Vec2> Vec2CubicBezier; | |

73 | typedef TemplateCubicBezier<osg::Vec3> Vec3CubicBezier; | |

74 | typedef TemplateCubicBezier<osg::Vec4> Vec4CubicBezier; | |

75 | ||

76 | } | |

77 | ||

78 | #endif |

**Note:**See TracBrowser for help on using the browser.