This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Rotate World Around Vehicle

Tags: rotate rotate rotate
(comma "," separated)
Beacon11
Registered Member
Posts
35
Karma
0

Rotate World Around Vehicle

Wed May 23, 2012 5:30 pm
Hello. I've seen one mailing list post regarding this, but it flew a bit over my head.

I center the MarbleWidget on a vehicle image that I paint on the map that is updating live. Rather than rotate the vehicle image as its heading changes, I'd like to rotate the map around the vehicle so the vehicle is constantly pointing upwards.

I'm zoomed in far enough that the projection doesn't matter.

I did notice the MarbleWidget::rotateBy() method, but of the two that are defined, I assume I'll need to use the one with quaternions. I have a very limited understanding of quats (i.e. I read the wikipedia article) and can't quite reason out what to do.

Any help would be greatly appreciated!

Thank you.
Beacon11
Registered Member
Posts
35
Karma
0

Re: Rotate World Around Vehicle

Wed May 23, 2012 6:56 pm
The more I read up, the less it sounds like I should be using MarbleWidget::rotateBy(). Perhaps a better solution is to change the MarbleWidget::viewPort()->planetAxis(). But that still involves quats and every time I try playing with it I get a garbage result.
User avatar
tackat
KDE Developer
Posts
131
Karma
0
OS

Re: Rotate World Around Vehicle

Thu May 24, 2012 6:28 am
Hi,

Yes the proper way would be to adjust the planetAxis (since the extra parameter in the old rotateBy API got removed),
In ViewportParams there is the implementation of centerOn() which has this snippet:

Quaternion axis = Quaternion::fromEuler( -lat, lon, 0.0 );
axis.normalize();

d->setPlanetAxis( axis );

IIRC You just need to replace "0.0" by the value you want to get the proper axis.
Beacon11
Registered Member
Posts
35
Karma
0

Re: Rotate World Around Vehicle

Thu May 24, 2012 4:18 pm
UPDATE: Previous edit used lat and lon in wrong order. It is correct here.

tackat wrote:Quaternion axis = Quaternion::fromEuler( -lat, lon, 0.0 );
axis.normalize();
d->setPlanetAxis( axis );

IIRC You just need to replace "0.0" by the value you want to get the proper axis.

Thank you Tackat-- the people in IRC said you'd be able to help me :) .

However, while this method is rotating the world, it's not quite the way I would like. The first thing to note is that we seem to be referring to slightly different versions-- I'm using the packaged source from the website, 1.2.0. The first question is, should I instead be using the trunk from git?

Knowing that I'm using that version, I can still work with what you said. I think it would be easiest if I supplied a few screenshots of what's happening.

I'm in the U.S.A., say the middle of Kansas (in radians, lat = 0.664366428, lon = -1.74950509).

I have the following program:

Code: Select all
#include <QtGui/QApplication>

#include <marble/MarbleWidget.h>
#include <marble/ViewportParams.h>

int main(int argc, char *argv[])
{
   QApplication application(argc, argv);

   Marble::MarbleWidget *mapWidget = new Marble::MarbleWidget();

   qreal latitude = 0.664366428;
   qreal longitude = -1.74950509;

   mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
   mapWidget->centerOn(Marble::GeoDataCoordinates(longitude, latitude));
   mapWidget->zoomView(1200);

   mapWidget->show();

   return application.exec();
}


That results in a picture like this (which obviously looks fine):
Image

Now I change the code to this:

Code: Select all
#include <QtGui/QApplication>

#include <marble/MarbleWidget.h>
#include <marble/ViewportParams.h>

int main(int argc, char *argv[])
{
   QApplication application(argc, argv);

   Marble::MarbleWidget *mapWidget = new Marble::MarbleWidget();

   qreal latitude = 0.664366428;
   qreal longitude = -1.74950509;

   mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
   mapWidget->centerOn(Marble::GeoDataCoordinates(longitude, latitude));
   mapWidget->zoomView(1200);

   Marble::Quaternion newPlanetAxis;
   newPlanetAxis.createFromEuler(-latitude, longitude, 0.0);
   newPlanetAxis.normalize();
   mapWidget->viewport()->setPlanetAxis(newPlanetAxis);

   mapWidget->show();

   return application.exec();
}


and nothing changed (which was what I expected with 0.0).

Getting excited, I changed the 0.0 to M_PI/2.0 and got this:
Image

What I really wanted with M_PI/2.0 was the world to rotate as in this image (ignore the fact that the compass etc. is also rotated :P ):
Image

I have a feeling this will need some quat math... what do you think?
Beacon11
Registered Member
Posts
35
Karma
0

Re: Rotate World Around Vehicle

Fri May 25, 2012 11:06 am
Sorry, I realized that my previous post had some errors (I flipped lat and lon around in the call to createFromEuler()). It has been updated.
kreuzberger
Registered Member
Posts
4
Karma
0

Re: Rotate World Around Vehicle

Thu Oct 11, 2012 10:30 am
Hi!

Wanted to do the same thing, but it seems that the methods you used (specially setPlanetAxis) are not usable any more (changed from public to private in 1.3).
How do you solve the problem now? I didnt find any replacement?
kreuzberger
Registered Member
Posts
4
Karma
0

Re: Rotate World Around Vehicle

Thu Oct 11, 2012 12:25 pm
Ok, as far as i have seen this feature as been removed completly, cause rotation around z-axis should is not supported (yet)
Beacon11
Registered Member
Posts
35
Karma
0

Re: Rotate World Around Vehicle

Fri Oct 12, 2012 10:58 am
kreuzberger wrote:Hi!

Wanted to do the same thing, but it seems that the methods you used (specially setPlanetAxis) are not usable any more (changed from public to private in 1.3).
How do you solve the problem now? I didnt find any replacement?

kreuzberger: I'm sorry to say I never did solve this problem; I would have marked it as such. setPlanetAxis() never worked the way I hoped anyway.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell