【问题标题】:Inclined rotation between an object in Three.jsThree.js中对象之间的倾斜旋转
【发布时间】:2012-11-30 07:02:08
【问题描述】:

我正在尝试像 Three.js 那样重现太阳系,但我无法让行星围绕恒星倾斜旋转:

这是一个小提琴示例,但旋转错误: http://goo.gl/MzcwI

我试过这个解决方案: How to rotate a 3D object on axis three.js? 没有成功。

如果有人有线索可以帮助我, 谢谢

【问题讨论】:

    标签: javascript 3d webgl three.js orbital-mechanics


    【解决方案1】:

    我必须在枢轴的根位置添加一个元素,它创建了一种可以旋转的新计划。

    解决方案here

    jsfiddle
    

    【讨论】:

      【解决方案2】:

      你试过了吗?

      function animate() {
      
        pivot.rotation.y += 0.01;
        pivot.rotation.x += 0.01;
        requestAnimationFrame(animate);
        render();
      
      }
      

      【讨论】:

      • 不,它在旋转结束时做了一个奇怪的动作我在下一篇文章中链接了解决方案
      【解决方案3】:

      如果您只想使用网格的位置向量进行旋转,您可以简单地执行类似

      的操作
      theta = 0;/* Global variable */
      function render(){ 
      
          orbiter = /* Get the planet you want to rotate*/;
      
          orbiter.mesh.position.x = Math.cos( theta ) *100;
          orbiter.mesh.position.z =  Math.sin( theta ) *25;
          orbiter.mesh.position.y  =  Math.cos( theta ) * -60;
          theta +=.02; 
      
          renderer.render( scene, camera );
      }
      
      function animate(){ animation_id = requestAnimationFrame( animate ); render(); }
      animate();
      

      您将不得不使用这些值来获得所需的旋转角度 - 特别是对于 position.y 值。增加 theta 应该会提高速度。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多