Coordinate System

classic Classic list List threaded Threaded
4 messages Options
leiserhartbeck leiserhartbeck
Reply | Threaded
Open this post in threaded view
|

Coordinate System

Hello Everyone,
  I am trying to migrate an OSG appplication to osgEarth. In OSG any shape made of lat lon altitude could be created by converted to XYZ using the following function:

 double h = 1.0 + llh[2]/osg::WGS_84_RADIUS_EQUATOR;
    xyz = osg::Vec3d(h * cos(osg::DegreesToRadians(llh[0])) * cos(osg::DegreesToRadians(llh[1])),
        h * cos(osg::DegreesToRadians(llh[0])) * sin(osg::DegreesToRadians(llh[1])),
        h * sin(osg::DegreesToRadians(llh[0])));

The shape then is visible in OSG.

However when I try to add the same to OSGEarth the shape is not visible. What could be wrong?

Leiser
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Coordinate System

Leiser,
What units is your altitude in? Your computation of "h" seems strange.

You can use the osgEarth::GeoPoint class to convert to world coordinates.

const SpatialReference* srs = SpatialReference::get("wgs84");
GeoPoint point(srs, lon, lat, alt);
osg::Vec3d ecef;
point.toWorld(ecef);

Hope this helps.
Glenn Waldron / Pelican Mapping
leiserhartbeck leiserhartbeck
Reply | Threaded
Open this post in threaded view
|

Re: Coordinate System

Hello,
   Thanks for the help. It converts the lat lon and altitude to ECEF Correctly. However I still cannot see the figure drawn. Basically this is I am doing:

// This method will add gpt point from the parameter to the upper and lower bound.
void Airspace::createLODboundary(osg::Group* LODgroup, osg::Vec3Array* upperVerts, osg::Vec3Array* lowerVerts, int LODlevel) {
    unsigned int nthPoint;
    if (LODlevel < 2) {
        nthPoint = (unsigned int)floor(mAirspaceDiameter / LODparams[LODlevel].nthPointParameter);
        if (nthPoint < LODparams[LODlevel].minNthPoint) nthPoint = LODparams[LODlevel].minNthPoint;
    } else {
        nthPoint = LODparams[LODlevel].minNthPoint;
    }

    int i = 0;
    for(osg::Vec3Array::iterator iter = llhBounds->begin(); iter < llhBounds->end(); iter++) {
        VecLLH gpt(iter->x(), iter->y(), Altitude(iter->z()));
        if (i % nthPoint == 0) {
            gpt.setHeight(mLowerAlt);
            lowerVerts->push_back(gpt2Ecef(gpt));
            gpt.setHeight(mUpperAlt);
            upperVerts->push_back(gpt2Ecef(gpt));
        }
        i++;
    }

    // Creation of the airspace outline
    LODgroup->addChild(createBoundGeode(lowerVerts));
    LODgroup->addChild(createBoundGeode(upperVerts));
}


where gpt2Ecef is a function which converts the coordinates to ECEF. Is it ok to add the vertices of a shape in ECEF coordinates and display
Regards

Siddarth
leiserhartbeck leiserhartbeck
Reply | Threaded
Open this post in threaded view
|

Re: Coordinate System

Sorry I did not attach the remaining code.

void OSGPlanet::latLonHeightToXyz(const osg::Vec3d& llh, osg::Vec3d& xyz) const {

    const SpatialReference* srs = SpatialReference::get("wgs84");
    GeoPoint point(srs, llh[1], llh[0], llh[2]);
    point.toWorld(xyz);

}

osg::ref_ptr<osg::Geode> Airspace::createBoundGeode(osg::Vec3Array* points) {
    osg::ref_ptr<osg::Geometry> lineGeom = new osg::Geometry();

    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    for(osg::Vec3Array::iterator iter = points->begin(); iter < points->end(); iter++) {
        osg::Vec3d normal = *iter;
        normal.normalize();
        normals->push_back(normal);
    }

    lineGeom->setVertexArray(points);
    lineGeom->setNormalArray(normals);
    lineGeom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
    lineGeom->setColorArray(mColors);
    lineGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
    lineGeom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_LOOP,0,points->getNumElements()));
    osg::ref_ptr<osg::Geode> geode = new osg::Geode();
    geode->addDrawable(lineGeom);

    return geode;
}

The geode thus created is not visible.  Lat\lon ->ECEF ->Add to OSG vertices. Is it the correct way?
Regards