Skip to content

Commit

Permalink
Annotations: fixed handle visibility; fixed bad bearings on ellipse d…
Browse files Browse the repository at this point in the history
…raggers
  • Loading branch information
gwaldron committed Feb 5, 2015
1 parent c43738e commit 2f45c86
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
12 changes: 10 additions & 2 deletions src/osgEarthAnnotation/AnnotationEditing
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@
#include <osgEarth/Draggers>
#include <osgEarth/MapNode>

namespace osgEarth { namespace Annotation {
namespace osgEarth { namespace Annotation
{
class OSGEARTHANNO_EXPORT AnnotationEditor : public osg::Group
{
protected:
AnnotationEditor();

virtual ~AnnotationEditor() { }
};

/**
* An editor node that allows you to move the position of LocalizedNode annotations
*/
class OSGEARTHANNO_EXPORT LocalizedNodeEditor : public osg::Group
class OSGEARTHANNO_EXPORT LocalizedNodeEditor : public AnnotationEditor
{
public:
/**
Expand Down
48 changes: 37 additions & 11 deletions src/osgEarthAnnotation/AnnotationEditing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class DraggerCallback : public Dragger::PositionChangedCallback
LocalizedNodeEditor* _editor;
};

/**********************************************************************/
AnnotationEditor::AnnotationEditor() :
osg::Group()
{
// editor geometry should always be visible.
osg::StateSet* stateSet = this->getOrCreateStateSet();
stateSet->setMode(GL_DEPTH_TEST, 0);
stateSet->setRenderBinDetails(99, "RenderBin");
}

/**********************************************************************/
LocalizedNodeEditor::LocalizedNodeEditor(LocalizedNode* node):
_node( node )
Expand Down Expand Up @@ -208,6 +218,7 @@ class SetEllipseRadiusCallback : public Dragger::PositionChangedCallback

//Figure out the distance between the center of the circle and this new location
GeoPoint center = _node->getPosition();

double distance = GeoMath::distance(osg::DegreesToRadians( center.y() ), osg::DegreesToRadians( center.x() ),
osg::DegreesToRadians( position.y() ), osg::DegreesToRadians( position.x() ),
em->getRadiusEquator());
Expand All @@ -219,13 +230,13 @@ class SetEllipseRadiusCallback : public Dragger::PositionChangedCallback
//Compute the new angular rotation based on how they moved the point
if (_major)
{
_node->setRotationAngle( Angular( -bearing, Units::RADIANS ) );
_node->setRadiusMajor( Linear(distance, Units::METERS ) );
_node->setRotationAngle( Angle( bearing-osg::PI_2, Units::RADIANS ) );
_node->setRadiusMajor( Distance(distance, Units::METERS ) );
}
else
else // minor
{
_node->setRotationAngle( Angular( osg::PI_2 - bearing, Units::RADIANS ) );
_node->setRadiusMinor( Linear(distance, Units::METERS ) );
_node->setRotationAngle( Angle( bearing, Units::RADIANS ) );
_node->setRadiusMinor( Distance(distance, Units::METERS ) );
}
_editor->updateDraggers();
}
Expand Down Expand Up @@ -281,15 +292,30 @@ EllipseNodeEditor::updateDraggers()

double rotation = ellipse->getRotationAngle().as( Units::RADIANS );

double lat, lon;
GeoMath::destination(osg::DegreesToRadians( location.y() ), osg::DegreesToRadians( location.x() ), osg::PI_2 - rotation, minorR, lat, lon, em->getRadiusEquator());
double latRad, lonRad;

GeoPoint minorLocation(location.getSRS(), osg::RadiansToDegrees( lon ), osg::RadiansToDegrees( lat ));
// minor dragger: end of the rotated +Y axis:
GeoMath::destination(
osg::DegreesToRadians( location.y() ), osg::DegreesToRadians( location.x() ),
rotation,
minorR,
latRad, lonRad,
em->getRadiusEquator());

GeoPoint minorLocation(location.getSRS(), osg::RadiansToDegrees( lonRad ), osg::RadiansToDegrees( latRad ));
minorLocation.z() = 0;
_minorDragger->setPosition( minorLocation, false);
_minorDragger->setPosition( minorLocation, false );

GeoMath::destination(osg::DegreesToRadians( location.y() ), osg::DegreesToRadians( location.x() ), -rotation, majorR, lat, lon, em->getRadiusEquator());
GeoPoint majorLocation(location.getSRS(), osg::RadiansToDegrees( lon ), osg::RadiansToDegrees( lat ));
// major dragger: end of the rotated +X axis
GeoMath::destination(
osg::DegreesToRadians( location.y() ),
osg::DegreesToRadians( location.x() ),
rotation + osg::PI_2,
majorR,
latRad, lonRad,
em->getRadiusEquator());

GeoPoint majorLocation(location.getSRS(), osg::RadiansToDegrees( lonRad ), osg::RadiansToDegrees( latRad ));
majorLocation.z() = 0;
_majorDragger->setPosition( majorLocation, false);
}
Expand Down
8 changes: 4 additions & 4 deletions src/osgEarthAnnotation/FeatureEditing
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
#ifndef OSGEARTHANNO_FEATURE_EDITING_H
#define OSGEARTHANNO_FEATURE_EDITING_H 1

#include <osgEarthAnnotation/Common>
#include <osgEarthAnnotation/AnnotationEditing>
#include <osgEarth/MapNode>
#include <osgGA/GUIEventHandler>
#include <osgViewer/View>

#include <osgEarthAnnotation/FeatureNode>

namespace osgEarth { namespace Annotation {

namespace osgEarth { namespace Annotation
{
/**
* AddPointHandler is a GUIEventHandler that allows you to append points to a Feature's Geometry
*/
Expand Down Expand Up @@ -74,7 +74,7 @@ namespace osgEarth { namespace Annotation {
/**
* Node you can add to your scene graph to edit the verts of a Feature's Geometry
*/
class OSGEARTHANNO_EXPORT FeatureEditor : public osg::Group
class OSGEARTHANNO_EXPORT FeatureEditor : public AnnotationEditor
{
public:
/**
Expand Down
3 changes: 2 additions & 1 deletion src/osgEarthAnnotation/ImageOverlayEditor
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

#include <osgEarthAnnotation/Common>
#include <osgEarthAnnotation/ImageOverlay>
#include <osgEarthAnnotation/AnnotationEditing>
#include <osgEarth/Draggers>
#include <osgEarth/MapNode>
#include <osg/MatrixTransform>
#include <osgGA/GUIEventHandler>

namespace osgEarth { namespace Annotation
{
class OSGEARTHANNO_EXPORT ImageOverlayEditor : public osg::Group
class OSGEARTHANNO_EXPORT ImageOverlayEditor : public AnnotationEditor
{
public:
typedef std::map< ImageOverlay::ControlPoint, osg::ref_ptr< Dragger > > ControlPointDraggerMap;
Expand Down
7 changes: 4 additions & 3 deletions src/osgEarthAnnotation/ImageOverlayEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ struct OverlayCallback : public ImageOverlay::ImageOverlayCallback



ImageOverlayEditor::ImageOverlayEditor(ImageOverlay* overlay, bool singleVert):
_overlay (overlay),
_singleVert( singleVert )
ImageOverlayEditor::ImageOverlayEditor(ImageOverlay* overlay, bool singleVert) :
AnnotationEditor(),
_overlay ( overlay ),
_singleVert ( singleVert )
{
_overlayCallback = new OverlayCallback(this);
_overlay->addCallback( _overlayCallback.get() );
Expand Down

0 comments on commit 2f45c86

Please sign in to comment.