From 347dc9532a342a3f9a93f2f3f7baf3057e0920b8 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Thu, 27 Dec 2012 22:37:29 +0100 Subject: Support for rad, deg and % in rotation --- .../invoker/graphics/openscenegraph/OSGInvoker.cpp | 45 +++++++++++++++++----- test/samples/uscxml/test-scenegraph.scxml | 2 +- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp index 5c3dfef..2712be3 100644 --- a/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp +++ b/src/uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.cpp @@ -147,18 +147,43 @@ void OSGInvoker::processRotation(const Arabica::DOM::Node& element) assert(_nodes.find(element.getParentNode()) != _nodes.end()); osg::Node* node = _nodes[element.getParentNode()]; - double x = 0, y = 0, z = 0, angle = 0; - if (HAS_ATTR(element, "x")) - x = strTo(ATTR(element, "x")); - if (HAS_ATTR(element, "y")) - y = strTo(ATTR(element, "y")); - if (HAS_ATTR(element, "z")) - z = strTo(ATTR(element, "z")); - if (HAS_ATTR(element, "angle")) - z = strTo(ATTR(element, "angle")); + double pitch = 0, roll = 0, yaw = 0; + if (HAS_ATTR(element, "pitch")) { + NumAttr pitchAttr = NumAttr(ATTR(element, "pitch")); + if (boost::iequals(pitchAttr.unit, "deg")) { + pitch = osg::DegreesToRadians(strTo(pitchAttr.value)); + } else if (boost::iequals(pitchAttr.unit, "%")) { + pitch = osg::DegreesToRadians((strTo(pitchAttr.value) * 360) / 100); + } else { + pitch = strTo(pitchAttr.value); + } + } + if (HAS_ATTR(element, "roll")) { + NumAttr rollAttr = NumAttr(ATTR(element, "roll")); + if (boost::iequals(rollAttr.unit, "deg")) { + roll = osg::DegreesToRadians(strTo(rollAttr.value)); + } else if (boost::iequals(rollAttr.unit, "%")) { + roll = osg::DegreesToRadians((strTo(rollAttr.value) * 360) / 100); + } else { + roll = strTo(rollAttr.value); + } + } + if (HAS_ATTR(element, "yaw")) { + NumAttr yawAttr = NumAttr(ATTR(element, "yaw")); + if (boost::iequals(yawAttr.unit, "deg")) { + yaw = osg::DegreesToRadians(strTo(yawAttr.value)); + } else if (boost::iequals(yawAttr.unit, "%")) { + yaw = osg::DegreesToRadians((strTo(yawAttr.value) * 360) / 100); + } else { + yaw = strTo(yawAttr.value); + } + } osg::Matrix rotation; - rotation.makeRotate(angle, x, y, z); + rotation.makeRotate(roll, osg::Vec3(0,1,0), // roll + pitch, osg::Vec3(1,0,0) , // pitch + yaw, osg::Vec3(0,0,1) ); // heading + osg::MatrixTransform* transform = new osg::MatrixTransform(); transform->setMatrix(rotation); diff --git a/test/samples/uscxml/test-scenegraph.scxml b/test/samples/uscxml/test-scenegraph.scxml index e159fdd..25e13ed 100644 --- a/test/samples/uscxml/test-scenegraph.scxml +++ b/test/samples/uscxml/test-scenegraph.scxml @@ -16,7 +16,7 @@ - + -- cgit v0.12