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
StackedRotateAxisElement(const std::string & name,const osg::Vec3 & axis,double angle)19 StackedRotateAxisElement::StackedRotateAxisElement(const std::string& name, const osg::Vec3& axis, double angle) : StackedTransformElement(), _axis(axis), _angle(angle) { setName(name); }
StackedRotateAxisElement(const osg::Vec3 & axis,double angle)20 StackedRotateAxisElement::StackedRotateAxisElement(const osg::Vec3& axis, double angle) : _axis(axis), _angle(angle) { setName("rotateaxis"); }
StackedRotateAxisElement()21 StackedRotateAxisElement::StackedRotateAxisElement() : _axis(osg::Vec3(1,0,0)), _angle(0) {}
StackedRotateAxisElement(const StackedRotateAxisElement & rhs,const osg::CopyOp &)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
getAsMatrix() const29 osg::Matrix StackedRotateAxisElement::getAsMatrix() const { return osg::Matrix::rotate(osg::Quat(_angle, _axis)); }
update(float)30 void StackedRotateAxisElement::update(float /*t*/)
31 {
32 if (_target.valid())
33 _angle = _target->getValue();
34 }
35
getAxis() const36 const osg::Vec3& StackedRotateAxisElement::getAxis() const { return _axis; }
getAngle() const37 double StackedRotateAxisElement::getAngle() const { return _angle; }
setAxis(const osg::Vec3 & axis)38 void StackedRotateAxisElement::setAxis(const osg::Vec3& axis)
39 {
40 _axis = axis;
41 }
42
setAngle(double angle)43 void StackedRotateAxisElement::setAngle(double angle)
44 {
45 _angle = angle;
46 }
47
getOrCreateTarget()48 Target* StackedRotateAxisElement::getOrCreateTarget()
49 {
50 if (!_target.valid())
51 _target = new FloatTarget(_angle);
52 return _target.get();
53 }
54
applyToMatrix(osg::Matrix & matrix) const55 void StackedRotateAxisElement::applyToMatrix(osg::Matrix& matrix) const { matrix.preMultRotate(osg::Quat(_angle, _axis)); }
56