Javascript 和 html5 中包含 GPS 数据的 3D 世界

发布于 2024-12-23 01:47:39 字数 216 浏览 1 评论 0原文

我想用 javascript 创建一个 3D 旋转世界,动态定位 json 中的点以显示文本或图片等数据,并随机从一个点旋转到另一个点。

我希望在开始开发之前收到示例和建议。您会使用哪些库?您将使用哪种算法根据 GPS 数据旋转世界?

编辑:再次阅读我的问题,我想我应该说得更清楚。我想做一个类似谷歌地球的东西,但没有变焦功能。地球的 3D 模型上会有点,并且从一个点到另一个点的旋转。

I would like to create a 3D rotating world in javascript, dynamically positioning points from a json to display data such as text or pictures, and randomly rotating from a point to another.

I would like to receive examples and suggestions before beginning to develop. Which libraries would you use? Which algorythm would you use to rotate the world accordingly to the gps data?

Edit: Reading again my question I think I should make it more clear. I want to make something like Google Earth, without the zoom. There will be points on a 3d model of the earth, and a rotation from a point to another.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄离 2024-12-30 01:47:39

实际上我只是构建了这样的东西,除了 CSS3 和 CSS3 之外什么也没用。 JS。这是我为处理设备方向编写的代码。这个位置需要平滑,但它应该对你有帮助。它不断地触发事件,给出“标题”和“标题”。 “倾斜角度”。它绑定到一个更大的框架中,因此您需要将其拉出并以不同的方式触发事件,但这很容易做到。

( function( $ ){
    // interface to the compass that gets normalized
    $.Klass.add( 'HTML5.Orientation', $.Klass.Observable, {
        init : function( config ){
            this._super();

            $( window ).bind( 'deviceorientation', this.bindMethod( 'orientationChange' ) );
            this.degrees = 0;
            this.config  = config;
        }

        , orientationChange : function( ev ){
            /**
             * beta  = angle that top of device is pointing
             * gamma = angle that side of device is pointing
             * 
             * In portrait only: if gamma closer to 0, pointing back.  If closer to +- 180, pointing forward
             **/
            var     oEv = ev.originalEvent
              , heading = oEv.webkitCompassHeading - ( this.config.zeroDeg || 0 )
              ,    beta = oEv.beta
              ,   gamma = oEv.gamma
              ,  orient = window.orientation
              , aOrient = window.orientation % 180
              ,   angle = ( aOrient ? gamma : beta );

            // ignore bad data
            if( oEv.webkitCompassAccuracy == -1 ){ this.trigger( 'bad-compass' ); return; }
//          if( oEv.webkitCompassAccuracy >= 30 ){ this.trigger( 'inaccurate-compass' ); return; }

            // I think this means it's warming up :)
            if( oEv.webkitCompassAccuracy == 0  ){ return; }

            // normalize left or bottom being up
            if( ( 90 === orient ) || ( 180 === orient ) ){
                angle = -angle;
            }

            // if in portrait and leaning forward, flip the angle around 90deg
            if( !aOrient ){
                if( Math.abs( gamma ) > 90 ){
                    angle = 180 - angle;
                }
            }

            // normalize compass fliping from 0-->359 or visa-versa
            if( this.lastHeading && ( Math.abs( heading - this.lastHeading ) > 180 ) ){
                this.lastHeading = 360-this.lastHeading;
            }

            if( !this.heading ){ this.heading = heading; }

            this.trigger( 'heading', this.heading = this.heading + heading - this.lastHeading );
            this.trigger( 'angle', this.angle = angle );

            this.lastHeading = heading;
        }
    } );
}( jQuery ) );

I actually just built something like this, using nothing but CSS3 & JS. Here's the code I wrote for handling the device orientation. The position needs to be smoothed out, but it should help you. It fires events constantly giving the "heading" & "tilt angle". It's tied in to a much larger framework, so you're going to need to pull it out and trigger the events differently, but that's easy to do.

( function( $ ){
    // interface to the compass that gets normalized
    $.Klass.add( 'HTML5.Orientation', $.Klass.Observable, {
        init : function( config ){
            this._super();

            $( window ).bind( 'deviceorientation', this.bindMethod( 'orientationChange' ) );
            this.degrees = 0;
            this.config  = config;
        }

        , orientationChange : function( ev ){
            /**
             * beta  = angle that top of device is pointing
             * gamma = angle that side of device is pointing
             * 
             * In portrait only: if gamma closer to 0, pointing back.  If closer to +- 180, pointing forward
             **/
            var     oEv = ev.originalEvent
              , heading = oEv.webkitCompassHeading - ( this.config.zeroDeg || 0 )
              ,    beta = oEv.beta
              ,   gamma = oEv.gamma
              ,  orient = window.orientation
              , aOrient = window.orientation % 180
              ,   angle = ( aOrient ? gamma : beta );

            // ignore bad data
            if( oEv.webkitCompassAccuracy == -1 ){ this.trigger( 'bad-compass' ); return; }
//          if( oEv.webkitCompassAccuracy >= 30 ){ this.trigger( 'inaccurate-compass' ); return; }

            // I think this means it's warming up :)
            if( oEv.webkitCompassAccuracy == 0  ){ return; }

            // normalize left or bottom being up
            if( ( 90 === orient ) || ( 180 === orient ) ){
                angle = -angle;
            }

            // if in portrait and leaning forward, flip the angle around 90deg
            if( !aOrient ){
                if( Math.abs( gamma ) > 90 ){
                    angle = 180 - angle;
                }
            }

            // normalize compass fliping from 0-->359 or visa-versa
            if( this.lastHeading && ( Math.abs( heading - this.lastHeading ) > 180 ) ){
                this.lastHeading = 360-this.lastHeading;
            }

            if( !this.heading ){ this.heading = heading; }

            this.trigger( 'heading', this.heading = this.heading + heading - this.lastHeading );
            this.trigger( 'angle', this.angle = angle );

            this.lastHeading = heading;
        }
    } );
}( jQuery ) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文