Moved Keystone class into osgViewer library.

This commit is contained in:
Robert Osfield
2013-05-09 15:18:14 +00:00
parent 046c3fca7a
commit e545627571
6 changed files with 772 additions and 596 deletions

View File

@@ -283,9 +283,17 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
/** Get the hint of the profile mask to use in when creating graphic contexts.*/
unsigned int getGLContextProfileMask() const { return _glContextProfileMask; }
typedef std::vector<std::string> FileNames;
void setKeystoneFileNames(const FileNames& filenames) { _keystoneFileNames = filenames; }
FileNames& getKeystoneFileNames() { return _keystoneFileNames; }
const FileNames& getKeystoneFileNames() const { return _keystoneFileNames; }
typedef std::vector< osg::ref_ptr<osg::Object> > Objects;
void setKeystones(const Objects& objects) { _keystones = objects; }
Objects& getKeystones() { return _keystones; }
const Objects& getKeystones() const { return _keystones; }
/** helper function for computing the left eye projection matrix.*/
@@ -298,7 +306,7 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
virtual osg::Matrixd computeRightEyeProjectionImplementation(const osg::Matrixd& projection) const;
/** helper function for computing the right eye view matrix.*/
virtual osg::Matrixd computeRightEyeViewImplementation(const osg::Matrixd& view, double eyeSeperationScale=1.0) const;
virtual osg::Matrixd computeRightEyeViewImplementation(const osg::Matrixd& view, double eyeSeperationScale=1.0) const;
protected:
@@ -353,6 +361,11 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
unsigned int _glContextProfileMask;
SwapMethod _swapMethod;
FileNames _keystoneFileNames;
Objects _keystones;
};
}

143
include/osgViewer/Keystone Normal file
View File

@@ -0,0 +1,143 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGVIEWER_Keystone
#define OSGVIEWER_Keystone 1
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/DisplaySettings>
#include <osgGA/GUIEventHandler>
#include <osgViewer/Export>
namespace osgViewer
{
class OSGVIEWER_EXPORT Keystone : public osg::Object
{
public:
Keystone();
Keystone(const Keystone& rhs, const osg::CopyOp& copop=osg::CopyOp::SHALLOW_COPY);
META_Object(osg, Keystone)
void reset();
Keystone& operator = (const Keystone& rhs);
void setKeystoneEditingEnabled(bool flag) { keystoneEditingEnabled = flag; }
bool getKeystoneEditingEnabled() const { return keystoneEditingEnabled; }
void setGridColor(const osg::Vec4& color) { gridColour = color; }
osg::Vec4& getGridColor() { return gridColour; }
const osg::Vec4& getGridColor() const { return gridColour; }
void setBottomLeft(const osg::Vec2d& v) { bottom_left = v; }
osg::Vec2d& getBottomLeft() { return bottom_left; }
const osg::Vec2d& getBottomLeft() const { return bottom_left; }
void setBottomRight(const osg::Vec2d& v) { bottom_right = v; }
osg::Vec2d& getBottomRight() { return bottom_right; }
const osg::Vec2d& getBottomRight() const { return bottom_right; }
void setTopLeft(const osg::Vec2d& v) { top_left = v; }
osg::Vec2d& getTopLeft() { return top_left; }
const osg::Vec2d& getTopLeft() const { return top_left; }
void setTopRight(const osg::Vec2d& v) { top_right = v; }
osg::Vec2d& getTopRight() { return top_right; }
const osg::Vec2d& getTopRight() const { return top_right; }
void compute3DPositions(osg::DisplaySettings* ds, osg::Vec3& tl, osg::Vec3& tr, osg::Vec3& br, osg::Vec3& bl) const;
osg::Geode* createKeystoneDistortionMesh();
osg::Node* createGrid();
protected:
bool keystoneEditingEnabled;
osg::Vec4 gridColour;
osg::Vec2d bottom_left;
osg::Vec2d bottom_right;
osg::Vec2d top_left;
osg::Vec2d top_right;
protected:
virtual ~Keystone() {}
};
class OSGVIEWER_EXPORT KeystoneHandler : public osgGA::GUIEventHandler
{
public:
KeystoneHandler(Keystone* keystone);
~KeystoneHandler() {}
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* obj, osg::NodeVisitor* nv);
void setKeystoneEditingEnabled(bool enabled) { if (_currentControlPoints.valid()) _currentControlPoints->setKeystoneEditingEnabled(enabled); }
bool getKeystoneEditingEnabled() const { return _currentControlPoints.valid() ? _currentControlPoints->getKeystoneEditingEnabled() : false; }
enum Region
{
NONE_SELECTED,
TOP_LEFT,
TOP,
TOP_RIGHT,
RIGHT,
BOTTOM_RIGHT,
BOTTOM,
BOTTOM_LEFT,
LEFT,
CENTER
};
osg::Vec2d incrementScale(const osgGA::GUIEventAdapter& ea) const;
Region computeRegion(const osgGA::GUIEventAdapter& ea) const;
void move(Region region, const osg::Vec2d& delta);
protected:
osg::ref_ptr<Keystone> _keystone;
osg::Vec2d _defaultIncrement;
osg::Vec2d _ctrlIncrement;
osg::Vec2d _shiftIncrement;
osg::Vec2d _keyIncrement;
osg::Vec2d _startPosition;
osg::ref_ptr<Keystone> _startControlPoints;
Region _selectedRegion;
osg::ref_ptr<Keystone> _currentControlPoints;
};
}
#endif