/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
* Copyright 2020 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see
*/
#ifndef OSGEARTH_VIEWPOINT
#define OSGEARTH_VIEWPOINT
#include
#include
#include
#include
#include
#include
namespace osgEarth
{
/**
* Viewpoint stores a focal point (or a focal node) and camera parameters
* relative to that point.
*/
class OSGEARTH_EXPORT Viewpoint
{
public:
/**
* Constructs a blank (invalid) viewpoint.
*/
Viewpoint();
/**
* Copy constructor.
*/
Viewpoint(const Viewpoint& rhs);
/**
* Deserialize a Config into this viewpoint object.
*/
Viewpoint(const Config& conf);
public:
/**
* Returns true if this viewpoint contains either a valid focal point or
* a valid tracked node.
*/
bool isValid() const;
bool valid() const { return isValid(); }
/**
* Gets or sets the name of the viewpoint.
*/
optional& name() { return _name; }
const optional& name() const { return _name; }
void setName(const std::string& value) { _name = value; }
/**
* The geospatial location at which the camera is pointing. If the Node (below)
* is set, this is ignored.
*/
optional& focalPoint() { return _point; }
const optional& focalPoint() const { return _point; }
void setFocalPoint(const GeoPoint& value) { _point = value; }
/**
* The node in the scene graph at which the camera is pointing. The "getter" follows
* the observer pattern; i.e. you must copy its value into a ref_ptr before safely
* accessing it. getNode() returns true if the safe-reference was successful.
*
* If a node is set, the Focal Point is ignored.
* Node will not serialize into a Config.
*/
void setNode(osg::Node* value) { _node = value; }
osg::ref_ptr getNode() const;
bool nodeIsSet() const { return _node.valid(); }
/**
* Heading (in degrees) of the camera relative to the focal point.
*/
optional& heading() { return _heading; }
const optional& heading() const { return _heading; }
void setHeading(const Angle& value) { _heading = value; }
/**
* The pitch of the camera relative to the focal point.
*/
optional& pitch() { return _pitch; }
const optional& pitch() const { return _pitch; }
void setPitch(const Angle& value) { _pitch = value; }
/**
* The distance from the camera to the focal point.
*/
optional& range() { return _range; }
const optional& range() const { return _range; }
void setRange(const Distance& value) { _range = value; }
/**
* Local offsets from the focal point, in meters. For example if the Viewpoint
* is looking at a Node, this will shift the focal point so it is offset from
* the node in a cartesian coordinate system where X=east, Y=north, Z=up.
*/
optional& positionOffset() { return _posOffset; }
const optional& positionOffset() const { return _posOffset; }
void setPositionOffset(const osg::Vec3d& value) { _posOffset = value; }
/**
* Returns a printable string with the viewpoint data
*/
std::string toString() const;
/**
* Serialize this viewpoint to a config object.
*/
Config getConfig() const;
public:
//! Convenience constructor - SRS is WGS84, angles are in degrees, range is in meters.
Viewpoint(const char* name, double lon, double lat, double z, double heading, double pitch, double range);
public:
//! DTOR
~Viewpoint() { }
private:
optional _name;
optional _point;
optional _heading;
optional _pitch;
optional _range;
optional _posOffset;
osg::observer_ptr _node;
};
} // namespace osgEarth
#endif // OSGEARTH_VIEWPOINT