简体   繁体   English

Cesium WebGL相机旋转,如何停止旋转

[英]Cesium WebGL Camera Rotate, How to Stop the Rotation

OK, first time using Cesium. 好的,第一次使用Cesium。 I have a simple, non-advanced question that I posted a couple times on their forms but no one is responding. 我有一个简单的,非高级的问题,我在他们的表单上发布了几次,但没有人回应。 So I thought I'd try here. 所以我想我会在这里试试。

All I need to do is figure out how to stop an event before invoking another. 我需要做的就是弄清楚如何在调用另一个事件之前停止一个事件。 Here's an example of what's happening. 这是一个正在发生的事情的例子。 The globe spins on user-connect, but I need it to stop if they then click on "fly me home", etc. 地球在用户连接上旋转,但如果他们点击“飞回家”等我需要它停止。

Code below. 代码如下。

So the arg in spinGlobe is the spinRate. 所以spinGlobe中的arg是spinRate。 If I pass in 0.0 on the inital connect, it won't rotate. 如果我在初始连接上传入0.0,它将不会旋转。 Perfect. 完善。 So I though that if a click event ( user clicks fly me home ) then invoked spinGlobe(0.0) that the globe would stop rotating. 所以我觉得如果点击事件(用户点击飞回家),则调用spinGlobe(0.0)表示地球将停止旋转。 But it doesn't. 但事实并非如此。 Can I not dynamically change the spinRate? 我可以不动态更改spinRate吗? Or am I going about this all wrong? 或者我这样做是错的?

spinGlobe( 0.5 )

 function spinGlobe( dynamicRate )
 var previousTime = Date.now();

 viewer.clock.onTick.addEventListener(function( clock ) {
 var spinRate = dynamicRate;
 var currentTime = Date.now();
 var delta = ( currentTime - previousTime ) / 1000;
 previousTime = currentTime;
 viewer.scene.camera.rotate(Cesium.Cartesian3.UNIT_Z, -spinRate * delta);
 });
 }
spinGlobe( dynamicRate ){
    var previousTime = Date.now();

    this.viewer.scene.postRender.addEventListener(function (scene, time){
        var spinRate = dynamicRate;
        var currentTime = Date.now();
        var delta = ( currentTime - previousTime ) / 1000;
        previousTime = currentTime;
        this.viewer.scene.camera.rotate(Cesium.Cartesian3.UNIT_Z, -spinRate * delta);
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM