placerMatrix alternative

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

placerMatrix alternative

Hello,
    In earlier versions of osgearth coordinates could be converted to msg coordinate system using following code:

 osg::Matrixd coorTransformation;
  osg::Vec3 coord;

  // Fill the OGL vertexArray
  for (int k = 0; k < pointsWGS->size(); ++k) {
   
    objectPlacer->createPlacerMatrix(
      pointsWGS->at(k).lat,
      pointsWGS->at(k).lon,
      (height*FT_TO_M) ,
      coorTransformation);
    coord = osg::Vec3(0, 0, 0) * coorTransformation;

    vertexData->push_back(coord);
}

Since PlacerMatrix is removed now what is the new alternative?
Regards
Leiser
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: placerMatrix alternative

Leiser,
Please use the GeoTransform class instead.

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

Re: placerMatrix alternative

Sir,
 Could you provide a reference on how to use the GeoTransform class to convert the lat lon alt to msg coordinates. Any example in the application folder? I am not finding any application where in the lagoon alt are converted to msg coordinate system.
Thanks for quick response.

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

Re: placerMatrix alternative

Sorry, I misread your question. What is an "msg coordinate system"?

You can use the GeoPoint API or the SpatialReference API to convert coordinates between different systems and projections.
Glenn Waldron / Pelican Mapping
leiserhartbeck leiserhartbeck
Reply | Threaded
Open this post in threaded view
|

Re: placerMatrix alternative

Hello Sir,
  I mean OSG Coordinate system actually. I facing difficulty in placing a custom Geode in OSGEarth. I am creating the Geode by reading a set of coordinates. I can visualise the Geode in pure OSG when I convert it using the following code:

xyz[0] = llh[1];
    xyz[1] = 180/M_PI * log(tan(M_PI/4 + llh[0]*(M_PI/180)/2));
    xyz[2] = llh[2];

    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])));
    std::cout << "X: " << xyz[0] << "Y: " << xyz[1] << "Z: " << xyz[2] << std::endl;


But when i place the same geode on osgearth using root->addChild() function. I don't see it at all. I even tried converting it using:

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

       or

 osg::EllipsoidModel em;
    em.convertLatLongHeightToXYZ( osg::DegreesToRadians(llh.y()), osg::DegreesToRadians(llh.x()), llh.z(),
        xyz.x(), xyz.y(), xyz.z() );  

In both the cases I am not able to see the Geode.
Kindly show the way.
Regards
Leiser
 
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: placerMatrix alternative

Leiser,
Please print out your values for lla and for xyz.
Glenn Waldron / Pelican Mapping
leiserhartbeck leiserhartbeck
Reply | Threaded
Open this post in threaded view
|

Re: placerMatrix alternative

Hello Sir,

These are some of the values:

Lat: 38.235 Lon: -122.374 Alt: 0
X: -2.68595e+06Y: -4.23665e+06Z: 3.92597e+06
------------------------------------------------------
Lat: 38.235 Lon: -122.374 Alt: 3000
X: -2.68721e+06Y: -4.23864e+06Z: 3.92782e+06
------------------------------------------------------
Lat: 38.1059 Lon: -122.518 Alt: 3600
X: -2.70289e+06Y: -4.23973e+06Z: 3.91693e+06
------------------------------------------------------

I crossed check ecef conversion is fine. Following the ecef conversion I am building up the OGL array like this:

   // points is the Vec3d holding all ecef values

   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;

Then I am adding this geode to the root node.
I don't see it.

As always thanks a ton for quick response. Deperate for help :)
Regards
leiserhartbeck leiserhartbeck
Reply | Threaded
Open this post in threaded view
|

placerMatrix alternative

Hello Sir,
Any luck with ecef data? Is the conversion correct. I tried normalising the data but i still cannot see the shape inside osgearth.
Regards
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: placerMatrix alternative

The ECEF coordinates look OK to me. Sorry, but I don't know what the issue may be at this point.
Glenn Waldron / Pelican Mapping
leiserhartbeck leiserhartbeck
Reply | Threaded
Open this post in threaded view
|

Re: placerMatrix alternative

Hello Sir,
   Thanks for all the help. However, the process of adding ecef coordinates directly to a geode and display it is correct? I don't need to change that? No transformation of any sorts required?
Regards
Leiser
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: placerMatrix alternative

If you are going to look at them from a distance, it should be OK. If you need to see them close up you may run into precision issues since the GPU will only process 32-bit vertex positions by default. But this will only cause a jittering effect; it will not make your geometry invisible. So I would say your problem lies elsewhere.
Glenn Waldron / Pelican Mapping