http://openig.compro.net

A Opensource Image generator for the masses !
It is currently Thu Sep 23, 2021 4:08 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed Aug 05, 2015 3:02 pm 
Offline

Joined: Tue May 26, 2015 5:46 am
Posts: 21
Hi, how are you?

We are trying to extend OpenIG functionality by reading latitude, longitude, altitude, head, pitch, and roll values from ethernet and applying them to OpenIG camera.
We got the following code in main.cpp, which is found in IG\main.cpp


Code:
 while (!viewer->done())
    {
...


      //remove camera bind
/*
        if (cm.valid() && ig->isCameraBoundToEntity())
        {
            ig->bindCameraUpdate(cm->getMatrix());
        }
      */

//we retrieve info from a thread

      double latitudeDegrees, longitudeDegrees;
      float altitudeMeters;

      float headingDegrees, pitchDegrees, rollDegrees;
      mutex.lock();      

      latitudeDegrees = thread->getLatitudeDegrees();
      longitudeDegrees = thread->getLongitudeDegrees();
      altitudeMeters = thread->getAltitudeMeters();

      headingDegrees = thread->getHeadingDegrees();
      pitchDegrees = thread->getPitchDegrees();
      rollDegrees = thread->getRollDegrees();

      mutex.unlock();

//and then we build a matrix and set it to the camera View Matrix

      osg::Matrix xyzhprMat = createMatrix( longitudeDegrees, latitudeDegrees, altitudeMeters, headingDegrees, pitchDegrees, rollDegrees);
      view->getCamera()->setViewMatrix(xyzhprMat);

}


Now, the createMatrix code:

Code:
 
osg::Matrixd createMatrix(double x, double y, double z, double h, double p, double r)
{

    osg::Matrixd myCameraMatrix;

     osg::Matrixd cameraRotation;
     osg::Matrixd cameraTrans;

    // Create a quaternion using yaw/pitch/roll angles.
   osg::Vec3 yawAxis( 0.f, 0.f, 1.f );
   osg::Vec3 pitchAxis( 1.f, 0.f, 0.f );
   osg::Vec3 rollAxis( 0.f, 1.f, 0.f );

   osg::Quat q1(  osg::DegreesToRadians(h), yawAxis, osg::DegreesToRadians(p), pitchAxis,
   osg::DegreesToRadians(r), rollAxis );



   cameraRotation.makeRotate(q1);
     
    cameraTrans.makeTranslate( osg::Vec3(x,y,z) );



     myCameraMatrix = cameraRotation * cameraTrans;

    return myCameraMatrix;
}


This code sort of works, but pitch and roll angles are retrieved weirdly, as well as, when we sometimes change the attitude, we also get a change in the position, which surely does not make sense.
Do you guys have an idea of what could be going on?

Thanks in advance,
Daniel

ps. by the way, I know we need to make some transforms to get from geocentric to geodetic coordinates, but I am assuming lat, lon, and alt could be x,y,z, which are geocentric...


Top
 Profile  
 
PostPosted: Thu Aug 06, 2015 12:05 pm 
Offline

Joined: Tue May 12, 2015 6:11 pm
Posts: 16
Hi Mr. Baggio,

I spotted two issues:

- One is in createMatrix. You are using Geodetic coordinates for the translate, which are Degrees. The proper way is to use the osg::Ellipsoid (from CoordinateSystemNode header) to convert them to Cartesian. Something like this:

osg::EllipsoidModel emodel;
double x, y, z;
emodel.convertLatLongHeightToXYZ(latitude,longitude,altitude,x,y,z);

now the x,y,z are in ECEF (Earth Centered Earth Fixed) coordinate frame and ready to use for translation

- The other is the setting of the View Matrix directly. view->getCamera()->setViewMatrix(xyzhprMat); I would use for this one the OpenIG Interface -> OpenIG::setCameraPosition(matrix). Or if you still want to use your way, then set the inverse matrix of the created one: view->getCamera()->setViewMatrix(osg::Matrixd::inverse(xyzhprMat)).

Can you give these hints a shot and see if it solves the problem?

Thank you,

Kind Regards,
Nick


Top
 Profile  
 
PostPosted: Thu Aug 06, 2015 1:28 pm 
Offline

Joined: Tue May 26, 2015 5:46 am
Posts: 21
Hi Nick,


thanks for your feedback. Regarding the Ellipsoid conversion, it will be very useful.

Now, changing the view->getCamera()->setViewMatrix(xyzhprMat); to view->getCamera()->setViewMatrix(osg::Matrixd::inverse(xyzhprMat); did make x,y,z work correctly, as well as heading and pitch. But roll is not working.

I have also used setCameraPosition(matrix), which gives the same error.
I have also checked the rotation matrixes.
For instance, if I make heading = -60 degrees, pitch = 0, roll=0, I get this rotation matrix:
0.5 -0.86 0 0
0.86 0.5 0 0
0 0 1 0
0 0 0 1
Now, if I make heading = 0, pitch = 0, roll = -60 degrees, I get this rotation matrix:
0.5 0 0.866 0
0 1 0 0
-0.866 0 0.5 0
0 0 0 1

But both these rotations matrix will take the camera to the same orientation, which is quite weird.

Also, I haven't been able to test it in OpenIG using the command setcameraposition, which seems to be overriden by some camera manipulator.

Have you got x, y, z, head, pitch and roll working correctly? Do you have a sample code?

Thanks in advance,
Daniel Baggio


Top
 Profile  
 
PostPosted: Fri Aug 07, 2015 2:09 am 
Offline

Joined: Tue May 12, 2015 6:11 pm
Posts: 16
Hi Mr. Baggio,

glad we move forward with this. I don't have anything written yet to test the code, my suggestions were just by looking at your code. Please give me some time so I can test it here on some sample. I have a question: Are your rotation in NED (North,East,Down) ?

I will get back to you shortly !

Nick


Top
 Profile  
 
PostPosted: Fri Aug 07, 2015 2:22 am 
Offline

Joined: Tue May 12, 2015 6:11 pm
Posts: 16
Hi Mr. Baggio,

before starting some sample app I just took a look at some of the core functions you can try, since the Quaternion for the rotation is composed from separate Quats in igcore::Math::instance()->toMatrix(x,y,z,h,p,r) (NOTE: h,p,r are Degrees) - in IgCore/mathematics.h. Can you give this a try and let me know if any better?

Kind Regards,
Nick


Top
 Profile  
 
PostPosted: Fri Aug 07, 2015 6:45 am 
Offline

Joined: Tue May 26, 2015 5:46 am
Posts: 21
Hi Nick,

Regarding your questions:

>I have a question: Are your rotation in NED (North,East,Down) ?

Well, if we put heading=0, pitch =0, roll = 0, we would get an airplane pointing north, with the airplane landing gear touching the ground.

>before starting some sample app I just took a look at some of the core functions you can try, since the Quaternion for the rotation is composed from separate Quats in igcore::Math::instance()->toMatrix(x,y,z,h,p,r) (NOTE: h,p,r are Degrees) - in IgCore/mathematics.h. Can you give this a try and let me know if any better?

I did try that as well, and the results are the same. What I found weird is that putting
heading=-60, pitch =0, roll = 0
and
heading=0, pitch =0, roll = -60
do yield different matrixes, but when assigning them to the ViewMatrix by means of setViewMatrix(xyzhprMat), they result in the same orientation.

I think you don't need to touch any code, I believe that only using the setcameraposition command should work, but I can't get this command to work here, since it looks as if some manipulator overrides the behaviour, even if I unbindcamera.

Also, if you want to give a try on the code, simply open main.cpp, which is found in IG\main.cpp, and then comment

Code:
      //remove camera bind
/*
        if (cm.valid() && ig->isCameraBoundToEntity())
        {
            ig->bindCameraUpdate(cm->getMatrix());
        }
      */


Also, in the end of the rendering loop:

Code:
osg::Matrixd mx = Math::instance()->toMatrix(longitudeDegrees, latitudeDegrees, altitudeMeters,headingDegrees,pitchDegrees+90,rollDegrees);
ig->setCameraPosition(mx);


And then try
double longitudeDegrees = 0;
double latitudeDegrees = 0;
double altitudeMeters = 0;
double headingDegrees = -60;
double pitchDegrees = 0;
double rollDegrees = 0;

Check the position, and then try:
double longitudeDegrees = 0;
double latitudeDegrees = 0;
double altitudeMeters = 0;
double headingDegrees = 0;
double pitchDegrees = 0;
double rollDegrees = -60;

This should give you the behaviour I see here.

Kind regards,
Daniel


Top
 Profile  
 
PostPosted: Fri Aug 07, 2015 11:09 am 
Offline

Joined: Tue May 12, 2015 6:11 pm
Posts: 16
Hi Mr. Baggio,

thanks for the clarification.

Re: binding camera and overrididing setcamerapos, you should find and put into comment the following call

virtual void bindCameraToEntity(unsigned int id, const osg::Matrixd& mx); or
igcore::Commands::instance()->exec("manip 0 trackball");

If you started started with the IG sample from the repo, it is in the manip custom command.

From what you are describing, the expected behavior, it seams like you need your orientation to work in NED (North, East, Down), like CIGI. At the moment we are discussing this inhouse to make support for Geodetic and NED coordinates, but will take a while. At the moment I can take a look what is going on with these matrices to work right at least for ECEF - which will be a good start, and will left you to do conversion

Kind Regards,
Nick


Top
 Profile  
 
PostPosted: Sat Aug 08, 2015 11:56 am 
Offline

Joined: Tue May 12, 2015 6:11 pm
Posts: 16
Hi Mr. Baggio,

I come up with some conversion math, not NED, but it works in the tangent space, so you can define local heading/pitch/roll and then convert to ECEF for use with Geocentric visual database.

Attached is the code, I have tested all the rotational combination and seam to work. I don't have Geocentric database so I used the osgEarth sample and the osgEarth sample database.

Please let me know if this can be of any help to you.

Kind Regards,
Nick

p.s. As I mentioned, for one of the next release we are preparing some subset of CIGI. We have already in place protocol independent networking library (good for any protocol, like CIGI or proprietary, cross-platform boost based), also some simple network synchronization between channels. My point here is with CIGI inplace we will have a standard for HOST-IG communication that will have all of these in place, but again, it will take a while, so please bear with us :-) - and thank you !


Attachments:
main.zip [3.73 KiB]
Downloaded 849 times
Top
 Profile  
 
PostPosted: Mon Aug 10, 2015 1:20 pm 
Offline

Joined: Tue May 26, 2015 5:46 am
Posts: 21
Hi Nick, how are you?

Thank you a lot for your work.

I just need to get a Geocentric database (proxy forbids osgearth here) to make some tests.

Anyway, I see there are several details to be watched.

Kind regards,
Daniel


Top
 Profile  
 
PostPosted: Thu Aug 13, 2015 7:14 pm 
Offline

Joined: Tue May 12, 2015 6:11 pm
Posts: 16
Hi Mr. Baggio,

I just spoke to Keith and he told me about your talk for the visual database you have. I must apologize for misleading this whole thread into something different than your needs.

When I originally saw your code, I assumed you are working with geocentric database, by the geodetic coordinates used. But Keith told me that you actually have flat UTM which might do it lots of simplier. My question now is about your idea of controlling the camera, with what kind of coordinates.

Let do this off-forum, over email and re-post the final solution if you are ok with. You should have my email, so please contact me directly

Also, the work so far is not wasted, it will be used for the CIGI implementation.

Kind Regards and with hope to hear from you,
Nick


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group