diff --git a/examples/osgkeystone/osgkeystone.cpp b/examples/osgkeystone/osgkeystone.cpp index 91cd436c5..40c32601b 100644 --- a/examples/osgkeystone/osgkeystone.cpp +++ b/examples/osgkeystone/osgkeystone.cpp @@ -28,10 +28,10 @@ #include -class ControlPoints : public osg::Referenced +class Keystone : public osg::Referenced { public: - ControlPoints(): + Keystone(): bottom_left(-1.0,-1.0), bottom_right(1.0,-1.0), top_left(-1.0,1.0), @@ -45,7 +45,7 @@ public: top_right.set(1.0,1.0); } - ControlPoints& operator = (const ControlPoints& rhs) + Keystone& operator = (const Keystone& rhs) { if (&rhs==this) return *this; bottom_left = rhs.bottom_left; @@ -61,141 +61,6 @@ public: osg::Vec2d top_right; }; -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) - { - } - - double angleBetweenVectors(const osg::Vec2d& v1, const osg::Vec2d& v2) const - { - osg::Vec2d v3(-v2.y(), v2.x()); - double p1 = v1*v2; - double p2 = v1*v3; - double a = atan2(p2, p1); - return a; - } - - osg::Vec2d rotateVector(osg::Vec2d& v, double s, double c) const - { - return osg::Vec2d(v.x()*c-v.y()*s, v.y()*c+v.x()*s); - } - - - void updateKeystone(ControlPoints cp) - { - controlPoints = cp; - - // compute translation - translate = (cp.bottom_left+cp.bottom_right+cp.top_left+cp.top_right)*0.25; - - // adjust control points to fit translation - cp.top_left -= translate; - cp.top_right -= translate; - 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="<taper.x() = (2.0 + (width/distance) * sin(osg::inDegrees(view_angle))) / (2.0 - (width/distance) * sin(osg::inDegrees(view_angle))); - //scale.x() = 1.0/cos(osg::inDegrees(view_angle)); - OSG_NOTICE<<"scale "<scale<taper<angle)) { OSG_NOTICE<<"angle = "<angle<angle = osg::inDegrees(keystone->angle); } - if (arguments.read("-t",keystone->translate.x(), keystone->translate.y())) { OSG_NOTICE<<"translate = "<translate<scale.x(), keystone->scale.y())) { OSG_NOTICE<<"scale = "<scale<taper.x(), keystone->taper.y())) { OSG_NOTICE<<"taper = "<taper< model = osgDB::readNodeFiles(arguments); if (!model) @@ -806,11 +648,7 @@ int main( int argc, char **argv ) // add camera manipulator viewer.setCameraManipulator(new osgGA::TrackballManipulator()); - - if (!oldStyleKeystone) - { - setUpViewForKeystone(&viewer, keystone); - } + setUpViewForKeystone(&viewer, keystone); viewer.realize(); @@ -829,12 +667,6 @@ int main( int argc, char **argv ) viewer.advance(); viewer.eventTraversal(); viewer.updateTraversal(); - - if (oldStyleKeystone && keystone.valid()) - { - viewer.getCamera()->setProjectionMatrix(original_pm * keystone->computeKeystoneMatrix()); - camera->setProjectionMatrix(original_grid_pm * keystone->computeKeystoneMatrix()); - } viewer.renderingTraversals(); } return 0;