#
root/OpenSceneGraph/trunk/src/osgAnimation/StackedRotateAxisElement.cpp
@
11009

Revision 11009, 2.2 kB (checked in by robert, 7 years ago) |
---|

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

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

2 | * Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net> | |

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 | #include <osgAnimation/StackedRotateAxisElement> | |

16 | ||

17 | using namespace osgAnimation; | |

18 | ||

19 | StackedRotateAxisElement::StackedRotateAxisElement(const std::string& name, const osg::Vec3& axis, double angle) : StackedTransformElement(), _axis(axis), _angle(angle) { setName(name); } | |

20 | StackedRotateAxisElement::StackedRotateAxisElement(const osg::Vec3& axis, double angle) : _axis(axis), _angle(angle) { setName("rotateaxis"); } | |

21 | StackedRotateAxisElement::StackedRotateAxisElement() {} | |

22 | StackedRotateAxisElement::StackedRotateAxisElement(const StackedRotateAxisElement& rhs, const osg::CopyOp&) : StackedTransformElement(rhs), _axis(rhs._axis), _angle(rhs._angle) | |

23 | { | |

24 | if (rhs._target.valid()) | |

25 | _target = new FloatTarget(*rhs._target); | |

26 | } | |

27 | ||

28 | ||

29 | osg::Matrix StackedRotateAxisElement::getAsMatrix() const { return osg::Matrix::rotate(osg::Quat(_angle, _axis)); } | |

30 | void StackedRotateAxisElement::update() | |

31 | { | |

32 | if (_target.valid()) | |

33 | _angle = _target->getValue(); | |

34 | } | |

35 | ||

36 | const osg::Vec3& StackedRotateAxisElement::getAxis() const { return _axis; } | |

37 | const double StackedRotateAxisElement::getAngle() const { return _angle; } | |

38 | void StackedRotateAxisElement::setAxis(const osg::Vec3& axis) | |

39 | { | |

40 | _axis = axis; | |

41 | } | |

42 | ||

43 | void StackedRotateAxisElement::setAngle(const double& angle) | |

44 | { | |

45 | _angle = angle; | |

46 | } | |

47 | ||

48 | Target* StackedRotateAxisElement::getOrCreateTarget() | |

49 | { | |

50 | if (!_target.valid()) | |

51 | _target = new FloatTarget(_angle); | |

52 | return _target.get(); | |

53 | } | |

54 | ||

55 | void StackedRotateAxisElement::applyToMatrix(osg::Matrix& matrix) const { matrix.preMultRotate(osg::Quat(_angle, _axis)); } |

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