OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

geographic to geocentric coordinate transformation


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> VirtualPlanetBuilder [vpb]
View previous topic :: View next topic  
Author Message
denizdiktas
User


Joined: 03 Dec 2010
Posts: 32

PostPosted: Mon Dec 27, 2010 10:34 pm    Post subject:
geographic to geocentric coordinate transformation
Reply with quote

Hi,

I am using osgdem to generate a terrain from a set of dted-files in geocentric coordinates. What I am trying to do next is to navigate the camera along a path given in geographic coordinates (lat, long, alt).

However, when I try to convert a geographic coordinate (of which I am sure from where the terrain is visible) to geocentric coordinates, and place my camera there I do not get to see anything. I transform the coordinates using osg:EllipsoidModel.

I also realized that I am getting weird output results from the Ellipsoid transformation: when I construct a bounding sphere bounding the whole terrain (built in geocentric coord-sys) and test a point at the center of the terrain (converted from geographic to geocentric coordinates) to see if it is included in this bonding sphere, it turns out that this point in geocentric coordinates is not included inside this bounding sphere - which is a contradiction.

am I missing something when performing the transformation from geographic to geocentric coordinates?
are there other transformations I have to incorporate into my calculation?
or am I building my terrain database with the wrong parameters ?

I use --geocentric option and I pass the root directory of all dted files.
I use osg-version 2.9.5 and virtual-planet-builder-v11.

any help is greatly appreciated..

Thank you!

Cheers,
deniz
Back to top
View user's profile Send private message
S2LR
Appreciator


Joined: 13 Nov 2010
Posts: 208

PostPosted: Tue Dec 28, 2010 4:19 pm    Post subject:
geographic to geocentric coordinate transformation
Reply with quote

Deniz,

If you're using osgdem with the --geocentric flag set, you're building a
geocentric database which is correct.

Here's a code snippet that may help you position your camera on the spheroid
in geocentric space. It sets the view matrix for the camera given the lat,
lon and alt. Roll, pitch, and yaw are zero in this example which means you
will be flying level looking north.

osg::Matrixd vm;
ellipsoid->computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadia
ns(lat),
osg::DegreesToRadians(lon),
alt, vm);
vm.invert(vm);

osg::Matrixd rotation2YUp;
rotation2YUp.makeRotate(-M_PI_2, osg::Vec3f(1.0, 0.0, 0.0));
vm *= rotation2YUp;
view->getCamera()->setViewMatrix(vm);

Hope this helps...
-Shayne

-----Original Message-----
From:
[mailto:] On Behalf Of deniz
diktas
Sent: Monday, December 27, 2010 3:35 PM
To:
Subject: [vpb] geographic to geocentric coordinate
transformation

Hi,

I am using osgdem to generate a terrain from a set of dted-files in
geocentric coordinates. What I am trying to do next is to navigate the
camera along a path given in geographic coordinates (lat, long, alt).

However, when I try to convert a geographic coordinate (of which I am sure
from where the terrain is visible) to geocentric coordinates, and place my
camera there I do not get to see anything. I transform the coordinates using
osg:EllipsoidModel.

I also realized that I am getting weird output results from the Ellipsoid
transformation: when I construct a bounding sphere bounding the whole
terrain (built in geocentric coord-sys) and test a point at the center of
the terrain (converted from geographic to geocentric coordinates) to see if
it is included in this bonding sphere, it turns out that this point in
geocentric coordinates is not included inside this bounding sphere - which
is a contradiction.

am I missing something when performing the transformation from geographic to
geocentric coordinates?
are there other transformations I have to incorporate into my calculation?
or am I building my terrain database with the wrong parameters ?

I use --geocentric option and I pass the root directory of all dted files.
I use osg-version 2.9.5 and virtual-planet-builder-v11.

any help is greatly appreciated..

Thank you!

Cheers,
deniz

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35183#35183









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
denizdiktas
User


Joined: 03 Dec 2010
Posts: 32

PostPosted: Tue Dec 28, 2010 8:10 pm    Post subject:
Reply with quote

Hi Shayne,

thank you for your reply.
but the problem I am facing is related to the transformation.
But I will keep your suggestion in mind when placing the camera, so thanks again Smile

The input to the application will be a flight-path given as a list of consecutive points in geographic coordinates which have to be transformed to geocentric coordinates (I also have orientation information of the airplane) but somehow the ellipsoid model fails to do it appropriately. I found another tool that transforms the coordinates correctly and I could see the terrain: so the problem seems to be solved for now.

But I cannot see how & why osgdem transforms it correctly but the ellipsoid model fails to do it. So I still would be glad if someone could tell me what the problem is..

deniz
Back to top
View user's profile Send private message
S2LR
Appreciator


Joined: 13 Nov 2010
Posts: 208

PostPosted: Tue Dec 28, 2010 9:01 pm    Post subject:
geographic to geocentric coordinatetransformation
Reply with quote

Deniz,

Which method in EllipsoidModel were you using to do the transform from
(lat,lon,alt) to (X,Y,Z)?

Can you provide a code snippet on how you're doing the transform? Also
provide the actual osgdem command you're using to build your database...

-Shayne

-----Original Message-----
From:
[mailto:] On Behalf Of deniz
diktas
Sent: Tuesday, December 28, 2010 1:10 PM
To:
Subject: Re: [vpb] geographic to geocentric
coordinatetransformation

Hi Shayne,

thank you for your reply.
but the problem I am facing is related to the transformation.
But I will keep your suggestion in mind when placing the camera, so thanks
again :)

The input to the application will be a flight-path given as a list of
consecutive points in geographic coordinates which have to be transformed to
geocentric coordinates (I also have orientation information of the airplane)
but somehow the ellipsoid model fails to do it appropriately. I found
another tool that transforms the coordinates correctly and I could see the
terrain: so the problem seems to be solved for now.

But I cannot see how & why osgdem transforms it correctly but the ellipsoid
model fails to do it. So I still would be glad if someone could tell me what
the problem is..

deniz

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35197#35197









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
denizdiktas
User


Joined: 03 Dec 2010
Posts: 32

PostPosted: Tue Dec 28, 2010 9:17 pm    Post subject:
Reply with quote

I am using osg::EllipsoidModel::convertLatLongHeightToXYZ() method to convert the coordinates as such:

osg:::EllipsoidModel em;
em.convertLatLongHeightToXYZ(_lat,_long,_alt, x,y,z);

when building the model I used osgdem with the following parameters:
osgdem --geocentric -d dted_dir -o terrain.ive

dted_dir contains dted files in a certain directory structure defined in dted-standard. I checked the validty of the dted with a commercial software, the geographic ranges are consistent with osgdem without --geocentric parameter (I looked at the contents of the height field of the first subtile: lod=0) so there is no problem with the input file, I am sure of that.

-deniz
Back to top
View user's profile Send private message
S2LR
Appreciator


Joined: 13 Nov 2010
Posts: 208

PostPosted: Tue Dec 28, 2010 9:36 pm    Post subject:
geographic to geocentric coordinatetransformation
Reply with quote

A couple more questions...

1) Are your lat, lon in radians when you call convertLatLongHeightToXYZ?
2) Have you tried viewing your database (terrain.ive) with osgviewer to see
what it looks like (osgviewer terrain.ive)? If you can't see your database
with osgviewer, then there's a problem with your database.

I use the exact same methods and my stuff works fine for viewing the terrain
given a lat,lon,alt with a geocentric database. As for osgdem, the only
difference is that I'm using a pagedLOD database and I'm using osgTerrain...

Here's the osgdem command I use...

osgdem --TERRAIN -PagedLOD --geocentric --whole-globe -t wholeearthtexture
-t texturedir -d elevationdir -l 24 -o geodatabase.ive

-Shayne

-----Original Message-----
From:
[mailto:] On Behalf Of deniz
diktas
Sent: Tuesday, December 28, 2010 2:18 PM
To:
Subject: Re: [vpb] geographic to geocentric
coordinatetransformation

I am using osg::EllipsoidModel::convertLatLongHeightToXYZ() method to
convert the coordinates as such:

osg:::EllipsoidModel em;
em.convertLatLongHeightToXYZ(_lat,_long,_alt, x,y,z);

when building the model I used osgdem with the following parameters:
osgdem --geocentric -d dted_dir -o terrain.ive

dted_dir contains dted files in a certain directory structure defined in
dted-standard. I checked the validty of the dted with a commercial software,
the geographic ranges are consistent with osgdem without --geocentric
parameter (I looked at the contents of the height field of the first
subtile: lod=0) so there is no problem with the input file, I am sure of
that.

-deniz

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35199#35199









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
denizdiktas
User


Joined: 03 Dec 2010
Posts: 32

PostPosted: Tue Dec 28, 2010 11:25 pm    Post subject:
Reply with quote

1) oops.. you are right! I am not passing them in radians Embarassed
ok I feel a little embarassed as of why I could not think of that Mad
I guess because I always tend to think in terms of opengl logic: in opengl you pass angles in degrees.

2) I have been able to see the terrain in osgviewer so no problem there..

Thank you so much Shayne, help greatly appreciated Smile

best wishes!
deniz
Back to top
View user's profile Send private message
S2LR
Appreciator


Joined: 13 Nov 2010
Posts: 208

PostPosted: Tue Dec 28, 2010 11:37 pm    Post subject:
geographic to geocentric coordinatetransformation
Reply with quote

I'm glad things are working for you...

-Shayne

-----Original Message-----
From:
[mailto:] On Behalf Of deniz
diktas
Sent: Tuesday, December 28, 2010 4:25 PM
To:
Subject: Re: [vpb] geographic to geocentric
coordinatetransformation

1) oops.. you are right! I am not passing them in radians Embarassed
ok I feel a little embarassed as of why I could not think of that Mad
I guess because I always tend to think in terms of opengl logic: in opengl
you pass angles in degrees.

2) I have been able to see the terrain in osgviewer so no problem there..

Thank you so much Shayne, help greatly appreciated :)

best wishes!
deniz

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35203#35203









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Elias Tarasov
User


Joined: 20 Apr 2015
Posts: 36

PostPosted: Wed Jun 17, 2015 8:38 am    Post subject:
Reply with quote

Hello!
It seems i have a problem Deniz had faced previously.
My generated terrain viewed from osgviewer is here:
https://drive.google.com/file/d/0ByDDImhSolf6Szh5YW81MDdqV2M/view?usp=sharing

My gdalinfo for dem file used to generate terrain is here:

Driver: GTiff/GeoTIFF
Files: n30_w086_1arc_v3_conv.tif
n30_w086_1arc_v3_conv.tif.aux.xml
Size is 58, 50
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (-85.495972222222221,30.536250000000003)
Pixel Size = (0.000277777777778,-0.000277777777778)
Metadata:
AREA_OR_POINT=Point
DTED_CompilationDate=0002
DTED_DataEdition=02
DTED_DigitizingSystem=SRTM
DTED_HorizontalAccuracy=0013
DTED_HorizontalDatum=WGS84
DTED_MaintenanceDate=0000
DTED_MaintenanceDescription=0000
DTED_MatchMergeDate=0000
DTED_MatchMergeVersion=A
DTED_NimaDesignator=DTED2
DTED_OriginLatitude=0300000N
DTED_OriginLongitude=0860000W
DTED_Producer=USCNIMA
DTED_RelHorizontalAccuracy=NA
DTED_RelVerticalAccuracy=0004
DTED_SecurityCode_DSI=U
DTED_SecurityCode_UHL=U
DTED_UniqueRef_DSI=H24 084
DTED_UniqueRef_UHL=H24 084
DTED_VerticalAccuracy_ACC=0005
DTED_VerticalAccuracy_UHL=0005
DTED_VerticalDatum=E96
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( -85.4959722, 30.5362500) ( 85d29'45.50"W, 30d32'10.50"N)
Lower Left ( -85.4959722, 30.5223611) ( 85d29'45.50"W, 30d31'20.50"N)
Upper Right ( -85.4798611, 30.5362500) ( 85d28'47.50"W, 30d32'10.50"N)
Lower Right ( -85.4798611, 30.5223611) ( 85d28'47.50"W, 30d31'20.50"N)
Center ( -85.4879167, 30.5293056) ( 85d29'16.50"W, 30d31'45.50"N)
Band 1 Block=58x50 Type=Int16, ColorInterp=Gray
Min=31.000 Max=61.000
Minimum=31.000, Maximum=61.000, Mean=49.202, StdDev=6.253
NoData Value=0
Unit Type: m
Metadata:
STATISTICS_MAXIMUM=61
STATISTICS_MEAN=49.202413793103
STATISTICS_MINIMUM=31
STATISTICS_STDDEV=6.2528388891449

Here, center of my terrain is:
Center ( -85.4879167, 30.5293056) ( 85d29'16.50"W, 30d31'45.50"N)

Now i want to place a camera in the center of that terrain to use it from an app:

const double M_PI_2 = 1.57079632679489661923;

int main( int argc, char** argv ) {

osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> cessna = osgDB::readNodeFile("c:/OpenSceneGraph/data/cessnafire.osg");
osg::ref_ptr<osg::Node> map = osgDB::readNodeFile("c:/Terrain/FromUSGS/output/out.osgb");
root->addChild( cessna.get() );
root->addChild( map.get() );

osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setSceneData( root.get() );

osg::Matrixd vm;
osg::EllipsoidModel ellipsoid;
ellipsoid.computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(-85.4877762), osg::DegreesToRadians(30.5292506), 100, vm);
vm.invert(vm);

osg::Matrixd rotation2YUp;
rotation2YUp.makeRotate(-M_PI_2, osg::Vec3f(1.0, 0.0, 0.0));
vm *= rotation2YUp;
viewer->getCamera()->setViewMatrix(vm);

return viewer->run();
}

But i don't see anything. Just empty screen.
Well, since terrain had been built in geocentric mode, i think app somehow moved terrain and cessna to the correct position in ECEF.
So, i just need to move a camera to that position.

I guess camera's position is wrong, but i don't know how to fix it.

Thank you!

Cheers,
Elias
Back to top
View user's profile Send private message
Christian Schulte
Guest





PostPosted: Thu Jun 18, 2015 7:19 am    Post subject:
geographic to geocentric coordinate transformation
Reply with quote

Hello Elias,

since you have created your terrain using --geocentric in osgdem the
terrain is indeed in ECEF coordinates, but there is no reason that your
cessna model is. Looking at your code, the cessna is at the earth centre
(0.0,0.0,0.0). If you want to have your cessna on your terrain you
should load your cessna on a PositionAttitudeTransform and move it
correctly onto earth surface, using the ellipsoid xyzFromLatLonEle. You
should try to place your camera also using this and decomposing your
matrix in order to find where is the problem(
cam->setViewMatrix(translation * toYup * rotation)Wink
Also you should use as much as possible the osg functionalities in order
to use the same math constants (osg::PI_2 instead of _M_PI_2).

Regards,

Christian

Le 17/06/2015 10:39, Elias Tarasov a écrit :
Quote:
Hello!
It seems i have a problem Deniz had faced previously.
My generated terrain viewed from osgviewer is here:
https://drive.google.com/file/d/0ByDDImhSolf6Szh5YW81MDdqV2M/view?usp=sharing

My gdalinfo for dem file used to generate terrain is here:

Driver: GTiff/GeoTIFF
Files: n30_w086_1arc_v3_conv.tif
n30_w086_1arc_v3_conv.tif.aux.xml
Size is 58, 50
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (-85.495972222222221,30.536250000000003)
Pixel Size = (0.000277777777778,-0.000277777777778)
Metadata:
AREA_OR_POINT=Point
DTED_CompilationDate=0002
DTED_DataEdition=02
DTED_DigitizingSystem=SRTM
DTED_HorizontalAccuracy=0013
DTED_HorizontalDatum=WGS84
DTED_MaintenanceDate=0000
DTED_MaintenanceDescription=0000
DTED_MatchMergeDate=0000
DTED_MatchMergeVersion=A
DTED_NimaDesignator=DTED2
DTED_OriginLatitude=0300000N
DTED_OriginLongitude=0860000W
DTED_Producer=USCNIMA
DTED_RelHorizontalAccuracy=NA
DTED_RelVerticalAccuracy=0004
DTED_SecurityCode_DSI=U
DTED_SecurityCode_UHL=U
DTED_UniqueRef_DSI=H24 084
DTED_UniqueRef_UHL=H24 084
DTED_VerticalAccuracy_ACC=0005
DTED_VerticalAccuracy_UHL=0005
DTED_VerticalDatum=E96
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( -85.4959722, 30.5362500) ( 85d29'45.50"W, 30d32'10.50"N)
Lower Left ( -85.4959722, 30.5223611) ( 85d29'45.50"W, 30d31'20.50"N)
Upper Right ( -85.4798611, 30.5362500) ( 85d28'47.50"W, 30d32'10.50"N)
Lower Right ( -85.4798611, 30.5223611) ( 85d28'47.50"W, 30d31'20.50"N)
Center ( -85.4879167, 30.5293056) ( 85d29'16.50"W, 30d31'45.50"N)
Band 1 Block=58x50 Type=Int16, ColorInterp=Gray
Min=31.000 Max=61.000
Minimum=31.000, Maximum=61.000, Mean=49.202, StdDev=6.253
NoData Value=0
Unit Type: m
Metadata:
STATISTICS_MAXIMUM=61
STATISTICS_MEAN=49.202413793103
STATISTICS_MINIMUM=31
STATISTICS_STDDEV=6.2528388891449

Here, center of my terrain is:
Center ( -85.4879167, 30.5293056) ( 85d29'16.50"W, 30d31'45.50"N)

Now i want to place a camera in the center of that terrain to use it from an app:

const double M_PI_2 = 1.57079632679489661923;

int main( int argc, char** argv ) {

osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> cessna = osgDB::readNodeFile("c:/OpenSceneGraph/data/cessnafire.osg");
osg::ref_ptr<osg::Node> map = osgDB::readNodeFile("c:/Terrain/FromUSGS/output/out.osgb");
root->addChild( cessna.get() );
root->addChild( map.get() );

osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setSceneData( root.get() );

osg::Matrixd vm;
osg::EllipsoidModel ellipsoid;
ellipsoid.computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(-85.4877762), osg::DegreesToRadians(30.5292506), 100, vm);
vm.invert(vm);

osg::Matrixd rotation2YUp;
rotation2YUp.makeRotate(-M_PI_2, osg::Vec3f(1.0, 0.0, 0.0));
vm *= rotation2YUp;
viewer->getCamera()->setViewMatrix(vm);

return viewer->run();
}

But i don't see anything. Just empty screen.
Well, since terrain had been built in geocentric mode, i think app somehow moved terrain and cessna to the correct position in ECEF.
So, i just need to move a camera to that position.

I guess camera's position is wrong, but i don't know how to fix it.

Thank you!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64106#64106










--
SCHULTE Christian
Ingénieur Recherche
Responsable du Laboratoire de Simulation
ONERA - DCSD/PSEV
Département Commande des Systèmes et Dynamique du Vol
ONERA - Centre de Salon de Provence
BA 701
13661 SALON AIR Cedex - France
Tel :04.90.17.01.45



------------------
Post generated by Mail2Forum
Back to top
Elias Tarasov
User


Joined: 20 Apr 2015
Posts: 36

PostPosted: Thu Jun 18, 2015 6:23 pm    Post subject:
Reply with quote

Hello, Christian!

Again, your comments helped me:)
And again, i can't understand it from the first time.

The root of the problem here is how to move and rotate camera.
And the root of it is how to calculate needed matrices.

So, i looked for it:

1. Looked into general OSG forum.
2. Looked into vpb forum.
3. Stackoverflow.

There are a lot of info but to indicate what kind of problem i have, here is the pattern of what i found:

Vec3d eye( 1000.0, 1000.0, 0.0 );
Vec3d center( 0.0, 0.0, 0.0 );
Vec3d up( 0.0, 0.0, 1.0 );
viewer.getCamera()->setViewMatrixAsLookAt( eye, center, up );

Assumption:
Vectors must be defined with respect to some choosen coordinate frame.
So, with respect to what frame eye, center, up are defined?
How can i calculate them?
I presume, that without knowing in what frame vectors are expressed, and how to move to that frame from already defined frame (for instance from ECEF),
variables like Vec3d eye( 1000.0, 1000.0, 0.0 ) are useless.

Here is the code i changed according to your recomendations.
In the comments, there are at least three issues:
1. How to correctly define rotation?
2. How to define Up vector.
3. How to correctly add moved camera.

int main( int argc, char** argv ) {

osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> cessna = osgDB::readNodeFile("c:/OpenSceneGraph/data/cessnafire.osg");
osg::ref_ptr<osg::Node> map = osgDB::readNodeFile("c:/Terrain/FromUSGS/output/out.osgb");
osg::ref_ptr<osg::Camera> camera = new osg::Camera;

//Getting XYZ position for cessna
//-85.4877762 is terrain's center lat
//30.5292506 is terrain's center lon
//100 m - height above terrain we want to place the cessna.
osg::Matrix cessnaLocation;
osg::EllipsoidModel ellipsoid;
ellipsoid.computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(-85.4877762), osg::DegreesToRadians(30.5292506), 100, cessnaLocation);
osg::Vec3 positionForCessna = cessnaLocation.getTrans();

//Placing cessna
osg::ref_ptr<osg::PositionAttitudeTransform> moveCessna = new osg::PositionAttitudeTransform;
moveCessna->setPosition(positionForCessna);
moveCessna->addChild(cessna.get());

//Getting XYZ position for camera
//Lat Lon are the same, height is 150
osg::Matrix cameraLocation;
ellipsoid.computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(-85.4877762), osg::DegreesToRadians(30.5292506), 150, cameraLocation);
osg::Vec3 positionForCamera = cameraLocation.getTrans();

//Placing camera
osg::ref_ptr<osg::PositionAttitudeTransform> moveCamera = new osg::PositionAttitudeTransform;
moveCamera->setPosition(positionForCamera);
moveCamera->addChild(camera.get());

//rotation and Y up
//How to setup rotation matrix? with respect to what coordinate frame? I presume View frame with respect to ECEF?
osg::Matrix rotation;
rotation.makeRotate(osg::PI_2, osg::Vec3f(1.0, 0.0, 0.0)); //Here we rotate around X on the angle pi/2.

//How to define that matrix and why does it need?
osg::Matrix ToYUP; //Maybe here we can define a direction around of which we make our rotation?

//View = translation * YUP * rotation;
osg::Matrix viewMatrix;
viewMatrix = cameraLocation * ToYUP * rotation;
camera->setViewMatrix(viewMatrix);

//How to add moved camera?
root->addChild(camera.get() );
//Or maybe even camera->addChild( root.get() ); ?
root->addChild( moveCessna.get() );
root->addChild( map.get() );

osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setCamera( camera.get() );
viewer->setSceneData( root.get() );

return viewer->run();
}


Thank you!

Cheers,
Elias
Back to top
View user's profile Send private message
Christian Schulte
Guest





PostPosted: Fri Jun 19, 2015 3:06 pm    Post subject:
geographic to geocentric coordinate transformation
Reply with quote

Hello Elias,

underneath you will find your corrected and commented example (sorry, I
had to change the lat,lon and models Smile ).

#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>
#include <osg/PositionAttitudeTransform>

int main( int argc, char** argv ) {

osg::ref_ptr<osg::GraphicsContext::Traits> traits;
if(!(traits = new osg::GraphicsContext::Traits()).valid()) {
// print
osg::notify(osg::WARN)
<< " - traits = new osg::GraphicsContext::Traits() ->
invalid : abandon" << std::endl;
// error
return NULL;
}

// set traits properties
traits->screenNum = 0;
traits->x = 40;
traits->y = 40;
traits->width = 1024;
traits->height = 768;
traits->doubleBuffer = true;
traits->windowDecoration = true;
traits->vsync = true;

osg::ref_ptr<osg::GraphicsContext> gc =
osg::GraphicsContext::createGraphicsContext(traits);

osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> cessna = osgDB::readNodeFile("EC225.ive");
osg::ref_ptr<osg::Node> map =
osgDB::readNodeFile("y:/Bdt/Marseille/marseillemipmaphard09dds.ive");
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
osg::Vec3d center, eye, up;

//Getting XYZ position for cessna
osg::Matrix cessnaLocation;
osg::EllipsoidModel ellipsoid;
double x,y,z;
ellipsoid.convertLatLongHeightToXYZ(osg::DegreesToRadians(43.449310),
osg::DegreesToRadians(5.197525), 200.0, x, y, z);
osg::Vec3 positionForCessna = osg::Vec3d(x,y,z);

//Placing cessna
osg::ref_ptr<osg::PositionAttitudeTransform> moveCessna = new
osg::PositionAttitudeTransform;
moveCessna->setPosition(positionForCessna);
// Calculating attitude (heading north)
double phi = 0.0;
double psi = 0.0;
double theta = 0.0;
osg::Matrixd localToWorld;
osg::Matrixd attitude;
ellipsoid.computeLocalToWorldTransformFromXYZ(osg::DegreesToRadians(43.449310),
osg::DegreesToRadians(5.197525), 200.0, localToWorld);
attitude.makeRotate(
osg::DegreesToRadians(phi), osg::Y_AXIS,
osg::DegreesToRadians(theta), osg::X_AXIS,
osg::DegreesToRadians(-psi), osg::Z_AXIS);
attitude *= localToWorld;
osg::Quat quat = attitude.getRotate();
moveCessna->setAttitude(quat);

moveCessna->addChild(cessna.get());

osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();

// Create camera as shallow copy of theo ne of the view
camera =
dynamic_cast<osg::Camera*>(viewer->getCamera()->clone(osg::CopyOp::SHALLOW_COPY));
camera->setGraphicsContext(gc);
camera->setProjectionMatrixAsPerspective(40.0,1.33,0.1,10000.0);
camera->setViewport(new osg::Viewport(0, 0, gc->getTraits()->width,
gc->getTraits()->height));
camera->setClearColor(osg::Vec4f(0.5f,0.5f,0.0f,0.0f));
camera->setCullingActive(false);

//Getting XYZ position for camera
//Lat Lon are the same, height is 500.0
// The eye : position of the camera
ellipsoid.convertLatLongHeightToXYZ(osg::DegreesToRadians(43.449310),
osg::DegreesToRadians(5.197525), 500.0, x, y, z);
eye = osg::Vec3d(x,y,z);
// The center : position where you look at (same position a little
bit underneath...
ellipsoid.convertLatLongHeightToXYZ(osg::DegreesToRadians(43.449310),
osg::DegreesToRadians(5.197525), 499.9, x, y, z);
center = osg::Vec3d(x,y,z);
// The up : a little more tricky...
// It is the up vector of your screen (ie what is the bottom top
axis of your screen)
// If you want it to be north up
up = osg::Vec3d ( -std::cos(osg::DegreesToRadians(43.449310)) *
std::sin( osg::DegreesToRadians(5.197525)),
-std::sin(osg::DegreesToRadians(43.449310)) * std::sin(
osg::DegreesToRadians(5.197525)),
std::cos(osg::DegreesToRadians(5.197525)));
// If you want it to be east up
up = osg::Vec3d ( -std::cos(osg::DegreesToRadians(43.449310)),
std::cos(osg::DegreesToRadians(43.449310)),
0.0);
// Now you can set your view matrix
camera->setViewMatrixAsLookAt(eye,center,up);

// Some light for the scene...
osg::ref_ptr<osg::Light> light = new osg::Light();
light->setLightNum(0);
light->setDataVariance(osg::Object::DYNAMIC);
osg::ref_ptr<osg::LightSource> lightSource = new osg::LightSource;
lightSource->setLight(light);
lightSource->setLocalStateSetModes(osg::StateAttribute:ShockedN);

// Adding the elements
root->addChild( map.get() );
root->addChild( moveCessna.get() );
root->addChild( lightSource.get());

// Setting up the view
viewer->setCamera( camera.get() );
viewer->setSceneData( root.get() );

osg::ref_ptr<osgViewer::StatsHandler> stats = new
osgViewer::StatsHandler();
viewer->addEventHandler(stats.get());

while (!viewer->done())
{
viewer->frame();
}

return 1;
}


Hope it helps out !

Cheers,

Christian

Le 18/06/2015 20:23, Elias Tarasov a écrit :
Quote:
Hello, Christian!

Again, your comments helped me:)
And again, i can't understand it from the first time.

The root of the problem here is how to move and rotate camera.
And the root of it is how to calculate needed matrices.

So, i looked for it:

1. Looked into general OSG forum.
2. Looked into vpb forum.
3. Stackoverflow.

There are a lot of info but to indicate what kind of problem i have, here is the pattern of what i found:

Vec3d eye( 1000.0, 1000.0, 0.0 );
Vec3d center( 0.0, 0.0, 0.0 );
Vec3d up( 0.0, 0.0, 1.0 );
viewer.getCamera()->setViewMatrixAsLookAt( eye, center, up );

Assumption:
Vectors must be defined with respect to some choosen coordinate frame.
So, with respect to what frame eye, center, up are defined?
How can i calculate them?
I presume, that without knowing in what frame vectors are expressed, and how to move to that frame from already defined frame (for instance from ECEF),
variables like Vec3d eye( 1000.0, 1000.0, 0.0 ) are useless.

Here is the code i changed according to your recomendations.
In the comments, there are at least three issues:
1. How to correctly define rotation?
2. How to define Up vector.
3. How to correctly add moved camera.

int main( int argc, char** argv ) {

osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> cessna = osgDB::readNodeFile("c:/OpenSceneGraph/data/cessnafire.osg");
osg::ref_ptr<osg::Node> map = osgDB::readNodeFile("c:/Terrain/FromUSGS/output/out.osgb");
osg::ref_ptr<osg::Camera> camera = new osg::Camera;

//Getting XYZ position for cessna
//-85.4877762 is terrain's center lat
//30.5292506 is terrain's center lon
//100 m - height above terrain we want to place the cessna.
osg::Matrix cessnaLocation;
osg::EllipsoidModel ellipsoid;
ellipsoid.computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(-85.4877762), osg::DegreesToRadians(30.5292506), 100, cessnaLocation);
osg::Vec3 positionForCessna = cessnaLocation.getTrans();

//Placing cessna
osg::ref_ptr<osg::PositionAttitudeTransform> moveCessna = new osg::PositionAttitudeTransform;
moveCessna->setPosition(positionForCessna);
moveCessna->addChild(cessna.get());

//Getting XYZ position for camera
//Lat Lon are the same, height is 150
osg::Matrix cameraLocation;
ellipsoid.computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(-85.4877762), osg::DegreesToRadians(30.5292506), 150, cameraLocation);
osg::Vec3 positionForCamera = cameraLocation.getTrans();

//Placing camera
osg::ref_ptr<osg::PositionAttitudeTransform> moveCamera = new osg::PositionAttitudeTransform;
moveCamera->setPosition(positionForCamera);
moveCamera->addChild(camera.get());

//rotation and Y up
//How to setup rotation matrix? with respect to what coordinate frame? I presume View frame with respect to ECEF?
osg::Matrix rotation;
rotation.makeRotate(osg::PI_2, osg::Vec3f(1.0, 0.0, 0.0)); //Here we rotate around X on the angle pi/2. But rotate around what?

//How to define that matrix and why does it need?
osg::Matrix ToYUP; //Maybe here we can define a direction around of which we make our rotation?

//View = translation * YUP * rotation;
osg::Matrix viewMatrix;
viewMatrix = cameraLocation * ToYUP * rotation;
camera->setViewMatrix(viewMatrix);

//How to add moved camera?
root->addChild(camera.get() );
//Or maybe even camera->addChild( root.get() ); ?
root->addChild( moveCessna.get() );
root->addChild( map.get() );

osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setCamera( camera.get() );
viewer->setSceneData( root.get() );

return viewer->run();
}


Thank you!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64123#64123










--
SCHULTE Christian
Ingénieur Recherche
Responsable du Laboratoire de Simulation
ONERA - DCSD/PSEV
Département Commande des Systèmes et Dynamique du Vol
ONERA - Centre de Salon de Provence
BA 701
13661 SALON AIR Cedex - France
Tel :04.90.17.01.45



------------------
Post generated by Mail2Forum
Back to top
Elias Tarasov
User


Joined: 20 Apr 2015
Posts: 36

PostPosted: Sat Jun 20, 2015 12:54 pm    Post subject:
Reply with quote

Hello, Christian!
Yes, it helped me very much!
The code you posted works, and i also managed to add external FDM engine to calculate and getting data for cessna. Also, i added camera that moved behind cessna and now get a nice view of moving aeroplane, which position and orientation are defined by external physic engine and attached to geocentric coordinates.

Though i still have a problems of how to define the up vector (it seems like eye and center are with respect to ECEF, but the up is somehow with respect to my screen? ).

But anyway, now thanks to you help i have a room for experiments.

Thank you!

Cheers,
Elias
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> VirtualPlanetBuilder [vpb] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Fix FBX conversion to OpenGL coordina... Farshid Lashkari Submission 1 Wed Mar 15, 2017 6:34 pm View latest post
No new posts Geocentric Support cg76 osgOcean [osgOcean] 0 Thu Mar 24, 2016 3:26 am View latest post
No new posts how to use precipitation effect in ge... superlauking General 0 Wed Mar 09, 2016 3:24 pm View latest post
No new posts transforming between coordinate syste... cbuchner1 General 5 Thu Jul 16, 2015 3:24 pm View latest post
No new posts How to rotate node's local coordinate... Elias Tarasov General 5 Tue Jun 23, 2015 3:14 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP