Hi Haas,
Waay to much code for me to review, please break down into small bit
sized chunks of lines.
Use of EllipsoidModel is the right thing to do, but it'll only take
you from geocentric XYZ to lat/long/height and back, not from screen
XY to lat/long.
I can only guess that you want to have the current mouse position
report back the lat/long or something similiar. Could you explain
what you are trying to do at a higher level.
Robert.
On 10/18/06, Haas, Carlton <[EMAIL PROTECTED]> wrote:
All,
I'm trying to convert a lat/lon position to a screen x/y value
or a screen x/y to a lat/lon position. I used parts of another example I
found on the mailing list archive, but cannot figure out what I'm doing
wrong in the conversion process. I would like to have a map image loaded at
various places in the world that would be displayed when the camera is moved
to that lat/lon position and disappear when moved out of the location
If I use a Lat=0,Lon=0, I can use osg to convert from lat/lon to screen x/y
and back to lat/lon. When I use any other lat/lon position such as Lat=1.0
Lon=0.5, I cannot convert between lat/lon & screen x/y.
1. Is there a way to create a camera that could move to any place in
the world using lat/lon values?
2. I'm not sure of the proper way to initialize my camera ("world
environment" ) before adding other objects to the scene.
Here is the code I'm using below:
osg::ref_ptr<osg::Group> group = new osg::Group;
osg::ref_ptr<osg::Group> ll_group = new osg::Group;
// add the HUD subgraph.
if (scene.valid()) group->addChild(scene.get());
if (scene.valid()) ll_group->addChild(scene.get());
osg::Geode* geode = new osg::Geode;
ll_group->addChild(geode);
osg::Projection* orth_proj = new osg::Projection;
orth_proj->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
ll_group->addChild(orth_proj);
osg::MatrixTransform* modelViewMatrix = new osg::MatrixTransform;
modelViewMatrix->setMatrix(osg::Matrix::identity());
modelViewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
orth_proj->addChild(modelViewMatrix);
osg::EllipsoidModel * view_ll = new
osg::EllipsoidModel(osg::WGS_84_RADIUS_EQUATOR,osg::WGS_84_RADIUS_POLAR);
osg::CoordinateSystemNode* cordsys = new osg::CoordinateSystemNode();
cordsys->setCoordinateSystem("WKT");
cordsys->setFormat("WKT");
cordsys->setEllipsoidModel(view_ll);
orth_proj->addChild(cordsys);
double lat_pos,lon_pos,hgt_val;
double x_pos,y_pos,z_pos;
osg::Matrixd ll2World;
osg::Matrixd local2World;
lat_pos = 0; //(double)argc;
lon_pos = 0; //(double)argc;
hgt_val = 0;
//lat_pos = 36.0;
//lon_pos = 127.0;
//lat_pos = 15.0;
//lon_pos = 0;
std::cout<<"*** Lat: "<<lat_pos<< std::endl;
std::cout<<"*** Lon: "<<lon_pos<< std::endl;
std::cout<<"*** Alt: "<<hgt_val<< std::endl;
double convt_x=0,convt_y=0,convt_z=0;
double convt_lat=0,convt_lon=0,convt_alt=0;
view_ll->computeLocalToWorldTransformFromLatLongHeight(lat_pos,lon_pos,hgt_val,ll2World);
std::cout<<"*** Matrixd Converted Lat/Lon 2 World: "<<ll2World<<
std::endl;
convt_x=convt_lat=ll2World(3,0);
convt_y=convt_lon=ll2World(3,1);
//convt_z=convt_alt=ll2World(3,2);
convt_lat=ll2World(3,0);
convt_lon=ll2World(3,1);
//convt_alt=ll2World(3,2);
std::cout<<"+++ WorldTransform Converted from Lat: "<<convt_lat<<
std::endl;
std::cout<<"+++ WorldTransform Converted from Lon: "<<convt_lon<<
std::endl;
std::cout<<"+++ WorldTransform Converted from Height: "<<convt_alt<<
std::endl<< std::endl;
//double degree1;
//degree1 = osg::RadiansToDegrees(convt_lat);
//std::cout<<"+++ OSG Degree to Radians: "<<degree1<< std::endl;
view_ll->convertLatLongHeightToXYZ(convt_lat,convt_lon,convt_alt,convt_x,convt_y,convt_z);
std::cout<<"*** Converted Lat/Lon to X: "<<convt_x<< std::endl;
std::cout<<"*** Converted Lat/Lon to Y: "<<convt_y<< std::endl;
std::cout<<"*** Converted Lat/Lon to Z: "<<convt_z<< std::endl<<
std::endl;
std::string txtFont("fonts/arial.ttf");
// turn lighting off for the text and disable depth test to ensure its
always ontop.
osg::StateSet* stateset = geode->getOrCreateStateSet();
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
osg::Vec3 txt_pos(150.0f,600.0f,100.0f);
{
osgText::Text* text = new osgText::Text;
geode->addDrawable( text );
text->setFont(txtFont);
text->setPosition(txt_pos);
text->setText("X");
}
double wrld_x=0,wrld_y=0,wrld_alt=0;
std::cout<<"@@@ Before Compute X: "<<convt_x<< std::endl<< std::endl;
view_ll->computeLocalToWorldTransformFromXYZ(convt_x,convt_y,convt_z,local2World);
std::cout<<"Matrixd Converted XYZ 2 World: "<<local2World<< std::endl;
wrld_x=local2World(3,0);
wrld_y=local2World(3,1);
//wrld_alt=local2World(3,2);
std::cout<<"*** WorldTransform Converted from X: "<<wrld_x<< std::endl;
std::cout<<"*** WorldTransform Converted from Y: "<<wrld_y<< std::endl;
//std::cout<<"*** WorldTransform Converted from Z: "<<wrld_alt<<
std::endl<< std::endl;
//view_ll->convertXYZToLatLongHeight(wrld_x,wrld_y,wrld_alt,lat_pos,lon_pos,hgt_val);
view_ll->convertXYZToLatLongHeight(wrld_x,wrld_y,0,lat_pos,lon_pos,hgt_val);
std::cout<<"X to Lat: "<<lat_pos<< std::endl;
std::cout<<"Y to Lon: "<<lon_pos<< std::endl;
//std::cout<<"Z to Alt: "<<hgt_val<< std::endl;
osg::CameraView* cam_position = new osg::CameraView();
float new_x,new_y;
new_x=ll2World(3,0);
new_y=ll2World(3,1);
// std::cout<<"new_x WorldTransform : "<<new_x<< std::endl;
// std::cout<<"new_y WorldTransform : "<<new_y<< std::endl<< std::endl;
osg::Vec3 xy_pos(new_x,new_y,0);
osg::Vec3 new_cam_pos(0.0f,0.0f,0.0f);
cam_position->setPosition(xy_pos);
new_cam_pos = cam_position->getPosition();
double new_cam_x,new_cam_y = 0;
new_cam_x = new_cam_pos.x();
new_cam_y = new_cam_pos.y();
std::cout<<"new_cam x pos: "<<new_cam_x<< std::endl;
std::cout<<"new_cam y pos: "<<new_cam_y<< std::endl;
ll_group->addChild(cam_position);
ll_group->addChild(cordsys);
osg::CameraNode* camera = new osg::CameraNode;
// set the view matrix
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
// set the projection matrix
camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
camera->setViewMatrix(osg::Matrix::identity());
// draw subgraph after main camera view.
camera->setRenderOrder(osg::CameraNode::POST_RENDER);
// only clear the depth buffer
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->addChild(geode);
osg::CameraNode* ll_camera = new osg::CameraNode;
// set the view matrix
ll_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
// set the projection matrix
ll_camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
ll_camera->setViewMatrix(osg::Matrix::identity());
// draw subgraph after main camera view.
ll_camera->setRenderOrder(osg::CameraNode::POST_RENDER);
// only clear the depth buffer
ll_camera->setClearMask(GL_DEPTH_BUFFER_BIT);
ll_group->addChild(ll_camera);
// set the scene to render
viewer.setSceneData(group.get());
viewer.setSceneData(ll_group.get());
Thanks for the help on this problem,
Carlton
email
[EMAIL PROTECTED]
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/