简体   繁体   English

绕边缘而不是中心旋转

[英]Rotate around edge instead of center

Note I'm using ThreeJS Library with the possibility to use Tween as well 注意我正在使用ThreeJS库,也可以使用Tween

Currently I have a pole which is rotation around it's center. 目前,我有一杆绕其中心旋转的杆。 I want it to rotate around the center of the world(In this case 0, 0, 0), but I'm currently completely stuck on how to do this properly. 我希望它绕世界中心旋转(在本例中为0、0、0),但是我目前完全局限于如何正确执行此操作。 Imagine it as a pool stick rotating around the white ball. 想象一下,它像一个台球杆绕着白球旋转。 If someone can help me that would be appreciated. 如果有人可以帮助我,将不胜感激。

I suppose I have to change it's position based on the angle it is currently at, but have no clue how exactly that would be done. 我想我必须根据它当前所处的角度来更改它的位置,但是不知道该怎么做。 Maybe there's an overall easier way to get the same result, but I couldn't find any. 也许有一种总体上更容易获得相同结果的方法,但我找不到任何方法。

I'm animating my rotation currently using the following in my render loop: 我正在使用渲染循环中的以下内容为我的旋转动画:

//Animation
pole.rotateOnAxis(getAxis(angle), -Math.PI/2 - 0.1);
angle += 0.025;
pole.rotateOnAxis(getAxis(angle), Math.PI/2 + 0.1);

function getAxis(angle) {
 return new THREE. Vector3(-Math.sin(angle), 0, Math.cos(angle));
}

Since it's quite a bit of code I put it on JSFiddle https://jsfiddle.net/1swsh0v5/1/ 由于有很多代码,因此将其放在JSFiddle https://jsfiddle.net/1swsh0v5/1/

var render = function () {
    requestAnimationFrame( render );

    angle += 0.025;
    pole.position.x = 4 * Math.sin(angle);
    pole.position.z = 4 * Math.cos(angle);
    pole.rotation.y = angle - Math.PI/2;

    renderer.render(scene, camera);
};

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

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