diff --git a/examples/osgkeystone/osgkeystone.cpp b/examples/osgkeystone/osgkeystone.cpp index c7c2cd7be..945e4a1a4 100644 --- a/examples/osgkeystone/osgkeystone.cpp +++ b/examples/osgkeystone/osgkeystone.cpp @@ -66,6 +66,7 @@ class Keystone : public osg::Referenced public: Keystone(): translate(0.0,0.0), + shear(0.0,0.0), scale(1.0,1.0), taper(1.0,1.0), angle(0.0) @@ -98,11 +99,28 @@ public: cp.bottom_right -= translate; cp.bottom_left -= translate; + osg::Vec2d mid_left = (cp.top_left+cp.bottom_left)*0.5; + osg::Vec2d mid_right = (cp.top_right+cp.bottom_right)*0.5; + osg::Vec2d mid_top = (cp.top_left+cp.top_right)*0.5; + osg::Vec2d mid_bottom = (cp.bottom_left+cp.bottom_right)*0.5; + shear.x() = (mid_top.x()-mid_bottom.x())/(mid_top.y()-mid_bottom.y()); + shear.y() = (mid_right.y()-mid_left.y())/(mid_right.x()-mid_left.x()); + + cp.top_left.x() += cp.top_left.y() * shear.x(); + cp.top_left.y() += cp.top_left.x() * shear.y(); + cp.top_right.x() += cp.top_right.y() * shear.x(); + cp.top_right.y() += cp.top_right.x() * shear.y(); + cp.bottom_left.x() += cp.bottom_left.y() * shear.x(); + cp.bottom_left.y() += cp.bottom_left.x() * shear.y(); + cp.bottom_right.x() += cp.bottom_right.y() * shear.x(); + cp.bottom_right.y() += cp.bottom_right.x() * shear.y(); + +#if 0 angle = (angleBetweenVectors(cp.top_left, osg::Vec2d(-1.0,1.0)) + angleBetweenVectors(cp.top_right, osg::Vec2d(1.0,1.0)) + angleBetweenVectors(cp.bottom_right, osg::Vec2d(1.0,-1.0)) + angleBetweenVectors(cp.bottom_left, osg::Vec2d(-1.0,-1.0)))*0.25; - +#endif OSG_NOTICE<<"cp.top_left="<