How to rotate the earth inside GE plugin?

685 views
Skip to first unread message

choi2k

unread,
Aug 13, 2008, 11:29:19 PM8/13/08
to KML Developer Support - Google Earth Browser Plugin
Hi all,

I believe it can be done with javascript. However, I find no relate
information from Internet. How to rotate the earth inside GE plugin on
its own axis smoothly?

Thanks

TinyGrasshopper

unread,
Aug 13, 2008, 11:58:48 PM8/13/08
to KML Developer Support - Google Earth Browser Plugin
Hi choi2k,

You can do it with javascript. Rather than rotating the earth, you
move the camera to look a different point on the earth. Have a look at
the "move camera" example here:

http://www.google.com/earth/plugin/examples/samples/index.html

Also:

ge.getOptions().setFlyToSpeed(<number>);

will allow you to set how fast the plugin animates the transition from
where the camera currently is to where you've asked it to be.

Cheers,
Chris

choi2k

unread,
Aug 14, 2008, 1:26:52 AM8/14/08
to KML Developer Support - Google Earth Browser Plugin
Thanks, Chris. It works.
I have tried to move the camera before. However, the zoom in and zoom
out effect by using setAbstractView made the rotation not smooth..
If I set the FlytoSpeed, it is much better!

Here is my code, is there any better way to do it?
//=============================
function startRotate(){

if(!rotateInterval){
rotateInterval = setInterval("setRotation()", 100);
}else{
clearInterval(rotateInterval);
}
DS_ge.getOptions().setFlyToSpeed(500);
}

function setRotation(){
if(count != 360){
var lookAt =
DS_ge.getView().copyAsLookAt(DS_ge.ALTITUDE_RELATIVE_TO_GROUND);
lookAt.setLongitude(lookAt.getLongitude() + 5);
DS_ge.getView().setAbstractView(lookAt);
count += 5;
}else{
clearInterval(rotateInterval);
}
}
//=============================

TinyGrasshopper

unread,
Aug 14, 2008, 2:00:08 AM8/14/08
to KML Developer Support - Google Earth Browser Plugin
You could set the fly to speed to just teleport straight to the new
location (no animation) and then use very small increments so it still
looks smooth.

From this thread: http://groups.google.com/group/google-earth-browser-plugin/browse_thread/thread/05443c674953612b#
you can set the fly to speed to teleport using:

ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);

Cheers,
Chris

choi2k

unread,
Aug 14, 2008, 2:22:37 AM8/14/08
to KML Developer Support - Google Earth Browser Plugin
Great! Thank you very much !

On 8月14日, 下午2時00分, TinyGrasshopper wrote:
> You could set the fly to speed to just teleport straight to the new
> location (no animation) and then use very small increments so it still
> looks smooth.
>
> From this thread:http://groups.google.com/group/google-earth-browser-plugin/browse_thr...

cjorba

unread,
Aug 17, 2008, 7:07:17 AM8/17/08
to KML Developer Support - Google Earth Browser Plugin
if you want an even smoother animation you can use the ge "frameend"
event instead of the setInterval javascript funciton. This way your
funcion will be called every time a frame is drawn. Then you'll need
to calculate the number of degrees to rotate the earth between each
frame based on a speed you define (speed variable) and the time
elapsed since the last frame (you'll need to keep a last timestamp
variable from the last call to your function). This way you'll get the
best fps you can get, and therefore an animation that is as fluid as
it can be.

If you need a code snippet just ask for it and I'll post it.
> > > > > Thanks- Hide quoted text -
>
> - Show quoted text -

Yannoooo

unread,
Sep 4, 2008, 1:46:46 PM9/4/08
to KML Developer Support - Google Earth Browser Plugin
Yep your snippet is welcome if you're still ok :)
Thx a lot

Yann

On Aug 17, 1:07 pm, cjorba wrote:
> if you want an even smoother animation you can use the ge "frameend"
> event instead of the setInterval javascript funciton. This way your
> funcion will be called every time a frame is drawn. Then you'll need
> to calculate the number of degrees to rotate theearthbetween each
> frame based on a speed you define (speed variable) and the time
> elapsed since the last frame (you'll need to keep a last timestamp
> variable from the last call to your function). This way you'll get the
> best fps you can get, and therefore an animation that is as fluid as
> it can be.
>
> If you need a code snippet just ask for it and I'll post it.
>
> On Aug 14, 8:22 am, choi2k wrote:
>
>
>
> > Great! Thank you very much !
>
> > On 8月14日, 下午2時00分, TinyGrasshopper wrote:
>
> > > You could set the fly to speed to just teleport straight to the new
> > > location (no animation) and then use very small increments so it still
> > > looks smooth.
>
> > > From this thread:http://groups.google.com/group/google-earth-browser-plugin/browse_thr...
> > > you can set the fly to speed to teleport using:
>
> > > ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
>
> > > Cheers,
> > > Chris
>
> > > On Aug 14, 3:26 pm, choi2k wrote:
>
> > > > Thanks, Chris. It works.
> > > > I have tried to move the camera before. However, the zoom in and zoom
> > > > out effect by using setAbstractView made therotationnot smooth..
> > > > If I set the FlytoSpeed, it is much better!
>
> > > > Here is my code, is there any better way to do it?
> > > > //=============================
> > > > function startRotate(){
>
> > > > if(!rotateInterval){
> > > > rotateInterval = setInterval("setRotation()", 100);
> > > > }else{
> > > > clearInterval(rotateInterval);
> > > > }
> > > > DS_ge.getOptions().setFlyToSpeed(500);
>
> > > > }
>
> > > > function setRotation(){
> > > > if(count != 360){
> > > > var lookAt =
> > > > DS_ge.getView().copyAsLookAt(DS_ge.ALTITUDE_RELATIVE_TO_GROUND);
> > > > lookAt.setLongitude(lookAt.getLongitude() + 5);
> > > > DS_ge.getView().setAbstractView(lookAt);
> > > > count += 5;
> > > > }else{
> > > > clearInterval(rotateInterval);
> > > > }}
>
> > > > //=============================
>
> > > > On 8月14日, 上午11時58分, TinyGrasshopper wrote:
>
> > > > > Hi choi2k,
>
> > > > > You can do it with javascript. Rather than rotating theearth, you
> > > > > move the camera to look a different point on theearth. Have a look at
> > > > > the "move camera" example here:
>
> > > > >http://www.google.com/earth/plugin/examples/samples/index.html
>
> > > > > Also:
>
> > > > > ge.getOptions().setFlyToSpeed(<number>);
>
> > > > > will allow you to set how fast the plugin animates the transition from
> > > > > where the camera currently is to where you've asked it to be.
>
> > > > > Cheers,
> > > > > Chris
>
> > > > > On Aug 14, 1:29 pm, choi2k wrote:
>
> > > > > > Hi all,
>
> > > > > > I believe it can be done with javascript. However, I find no relate
> > > > > > information from Internet. How to rotate theearthinside GE plugin on
> > > > > > its own axis smoothly?
>
> > > > > > Thanks- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -

cjorba

unread,
Sep 8, 2008, 6:43:11 AM9/8/08
to KML Developer Support - Google Earth Browser Plugin
As smooth as it can be earth rotation:


//=============================
speed = 4; // degrees/second
lastFrameTs = (new Date()).getTime(); //last frame's timestamp

ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
google.earth.addEventListener(ge, "frameend", spin);

function spin() {
var nowTs = (new Date()).getTime(); //currrent timestamp
var dt = nowTs - lastFrameTs ; //delta time
lastFrameTs = nowTs;
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
var distance = dt * (speed/1000); //distance to rotate
var newLongitude = lookAt.getLongitude() - distance;
lookAt.setLongitude(newLongitude);
ge.getView().setAbstractView(lookAt);
}
//=============================

greets,

Carlos


On Sep 4, 7:46 pm, Yannoooo wrote:
> Yep your snippet is welcome if you're still ok :)
> Thx a lot
>
> Yann
>
> On Aug 17, 1:07 pm, cjorba wrote:
>
> > if you want an even smoother animation you can use the ge "frameend"
> > event instead of the setInterval javascript funciton. This way your
> > funcion will be called every time a frame is drawn. Then you'll need
> > to calculate the number of degrees torotatetheearthbetween each
> > > > > > > information from Internet. How torotatetheearthinside GE plugin on
Reply all
Reply to author
Forward
0 new messages