osgEarth 2.1.1
Namespaces | Defines | Functions | Variables

/home/cube/sources/osgearth/src/osgEarthUtil/EarthManipulator.cpp File Reference

#include <osgEarthUtil/EarthManipulator>
#include <osgEarth/FindNode>
#include <osg/Quat>
#include <osg/Notify>
#include <osg/MatrixTransform>
#include <osgUtil/LineSegmentIntersector>
#include <osgViewer/View>
#include <iomanip>
#include <osg/io_utils>
Include dependency graph for EarthManipulator.cpp:

Go to the source code of this file.

Namespaces

namespace  anonymous_namespace{EarthManipulator.cpp}

Defines

#define LC   "[EarthManip] "
#define HASMODKEY(W, V)   (( W & V ) == V )

Functions

double anonymous_namespace{EarthManipulator.cpp}::smoothStepInterp (double t)
double anonymous_namespace{EarthManipulator.cpp}::powFast (double x, double y)
double anonymous_namespace{EarthManipulator.cpp}::accelerationInterp (double t, double a)
void anonymous_namespace{EarthManipulator.cpp}::s_getHPRFromQuat (const osg::Quat &q, double &h, double &p, double &r)
static double normalizeAzimRad (double input)
osg::Vec3d closestPtOnLine (const osg::Vec3d &p1, const osg::Vec3d &v, const osg::Vec3d &p)
bool findIntersectionWithPlane (const osg::Vec3d &normal, const osg::Vec3d &pt, const osg::Vec3d &p1, const osg::Vec3d &v, osg::Vec3d &result)
bool sphereInterection (const osg::Vec3d &p0, double r0, const osg::Vec3d &p1, double r1, osg::Vec3d &resultCenter, double &r)
osg::Vec3d calcTangentPoint (const osg::Vec3d &pt, const osg::Vec3d &center, double radius, const osg::Vec3d &ray)
osg::Vec3d getWindowPoint (osgViewer::View *view, float x, float y)
void decomposeCenter (const osg::Vec3d &center, const osg::Quat &centerRotation, osg::Matrix &Me, osg::Matrix &Mlon)
osg::Matrixd rotateAroundPoint (const osg::Vec3d &pt, double theta, const osg::Vec3d &axis)

Variables

static std::string s_actionNames []
static std::string s_actionOptionNames []
static short s_actionOptionTypes [] = { 1, 1, 0, 0, 1, 1 }

Define Documentation

#define HASMODKEY (   W,
 
)    (( W & V ) == V )

Definition at line 243 of file EarthManipulator.cpp.

#define LC   "[EarthManip] "

Definition at line 30 of file EarthManipulator.cpp.


Function Documentation

osg::Vec3d calcTangentPoint ( const osg::Vec3d &  pt,
const osg::Vec3d &  center,
double  radius,
const osg::Vec3d &  ray 
)

Definition at line 2271 of file EarthManipulator.cpp.

{
    using namespace osg;
    // new sphere with center at midpoint between pt and input sphere
    Vec3d center2 = (pt + center) / 2.0;
    double rad2 = (pt - center2).length();
    Vec3d resCtr;
    double resRad;
    // Use Thales' theorem, which states that a triangle inscribed in
    // a circle, with two points on a diameter of the circle and the
    // third on the circle, is a right triangle. Since one endpoint is
    // the center of the original sphere (the earth) and the other is
    // pt, we can get our tangent from that.
    bool valid = sphereInterection(center, radius, center2, rad2, resCtr,
                                   resRad);
    if (!valid)
        return Vec3d(0.0, 0.0, 0.0);
    // Get the tangent point that lies in the plane of the ray and the
    // center line. The sequence of cross products gives us the point
    // that is closest to the ray, rather than the one on the other
    // side of the sphere.
    Vec3d toCenter = center - pt;
    toCenter.normalize();
    Vec3d normal = ray ^ toCenter;
    normal.normalize();
    Vec3d radial = toCenter ^ normal;
    radial = radial * resRad;
    Vec3d result = resCtr + radial;
    return result;
    
}

Here is the call graph for this function:

Here is the caller graph for this function:

osg::Vec3d closestPtOnLine ( const osg::Vec3d &  p1,
const osg::Vec3d &  v,
const osg::Vec3d &  p 
)

Definition at line 2221 of file EarthManipulator.cpp.

{
    double u = (p - p1) * v / v.length2();
    return p1 + v * u;
}
void decomposeCenter ( const osg::Vec3d &  center,
const osg::Quat &  centerRotation,
osg::Matrix &  Me,
osg::Matrix &  Mlon 
)

Definition at line 2327 of file EarthManipulator.cpp.

{
    using namespace osg;
    Mlon.makeIdentity();
    Matrix Mtotal(centerRotation);
    Mtotal.setTrans(center);
    // Use the X axis to determine longitude rotation. Due to the
    // OpenGL camera rotation, this axis will be the Y axis of the
    // longitude matrix.
    Mlon(1, 0) = Mtotal(0, 0);  Mlon(1, 1) = Mtotal(0, 1);
    // X axis is rotated 90 degrees, obviously
    Mlon(0, 0) = Mlon(1, 1);  Mlon(0, 1) = -Mlon(1, 0);
    Matrix MlonInv = Matrixd::inverse(Mlon);
    Me = Mtotal * MlonInv;
}
bool findIntersectionWithPlane ( const osg::Vec3d &  normal,
const osg::Vec3d &  pt,
const osg::Vec3d &  p1,
const osg::Vec3d &  v,
osg::Vec3d &  result 
)

Definition at line 2229 of file EarthManipulator.cpp.

{
    double denom = normal * v;
    if (osg::equivalent(0, denom))
        return false;
    double u = normal * (pt - p1) / denom;
    result = p1 + v * u;
    return true;
}
osg::Vec3d getWindowPoint ( osgViewer::View *  view,
float  x,
float  y 
)

Definition at line 2304 of file EarthManipulator.cpp.

{
    float local_x, local_y;
    const osg::Camera* camera
        = view->getCameraContainingPosition(x, y, local_x, local_y);
    if (!camera)
        camera = view->getCamera();
    osg::Matrix winMat;
    if (camera->getViewport())
        winMat = camera->getViewport()->computeWindowMatrix();
    osg::Matrix projMat = camera->getProjectionMatrix();
    // ray from eye through pointer in camera coordinate system goes
    // from origin through transformed pointer coordinates
    osg::Matrix win2camera = projMat * winMat;
    win2camera.invert(win2camera);
    osg::Vec4d winpt4 = osg::Vec4d(x, y, 0.0, 1.0) * win2camera;
    winpt4 = winpt4 / winpt4.w();
    return osg::Vec3d(winpt4.x(), winpt4.y(), winpt4.z());
}

Here is the caller graph for this function:

static double normalizeAzimRad ( double  input) [static]

Definition at line 740 of file EarthManipulator.cpp.

                                 {
        if(fabs(input) > 2*osg::PI)
                input = fmod(input,2*osg::PI);
    if( input < -osg::PI ) input += osg::PI*2.0;
    if( input > osg::PI ) input -= osg::PI*2.0;
    return input;
}

Here is the caller graph for this function:

osg::Matrixd rotateAroundPoint ( const osg::Vec3d &  pt,
double  theta,
const osg::Vec3d &  axis 
)

Definition at line 2344 of file EarthManipulator.cpp.

{
    return (osg::Matrixd::translate(pt)
            * osg::Matrixd::rotate(theta, axis)
            * osg::Matrixd::translate(pt * -1.0));
}

Here is the caller graph for this function:

bool sphereInterection ( const osg::Vec3d &  p0,
double  r0,
const osg::Vec3d &  p1,
double  r1,
osg::Vec3d &  resultCenter,
double &  r 
)

Definition at line 2243 of file EarthManipulator.cpp.

{
    using namespace osg;
    Vec3d ptvec = (p1 - p0);
    double d = ptvec.normalize();
    if (d > r0 + r1)
        return false;               // spheres are too far apart
    else if (d < fabs(r0 - r1))
        return false;               // One sphere is contained in the other
    else if (equivalent(0, d) && equivalent(r0, r1))
    {
        resultCenter = p0;
        r = r0;
        return true;              // circles are coincident.
    }
    // distance from p0 to the line through the interection points
    double a = (r0 * r0 - r1 * r1 + d * d) / (2 * d);
    // distance from bisection of that line to the intersections
    resultCenter = p0 + ptvec * a;
    r = sqrt(r0 * r0 - a * a);
    return true;
}

Here is the caller graph for this function:


Variable Documentation

std::string s_actionNames[] [static]
Initial value:
 {
    "null",
    "home",
    "goto",
    "pan",
    "pan-left",
    "pan-right",
    "pan-up",
    "pan-down",
    "rotate",
    "rotate-left",
    "rotate-right",
    "rotate-up",
    "rotate-down",
    "zoom",
    "zoom-in",
    "zoom-out",
    "earth-drag"
}

Definition at line 165 of file EarthManipulator.cpp.

std::string s_actionOptionNames[] [static]
Initial value:
 {
    "scale-x",
    "scale-y",
    "continuous",
    "single-axis",
    "goto-range-factor",
    "duration"
}

Definition at line 185 of file EarthManipulator.cpp.

short s_actionOptionTypes[] = { 1, 1, 0, 0, 1, 1 } [static]

Definition at line 194 of file EarthManipulator.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines