首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法以所需方式旋转多维数据集- plane和mousemove方法

无法以所需方式旋转多维数据集- plane和mousemove方法
EN

Stack Overflow用户
提问于 2021-07-06 21:48:49
回答 1查看 66关注 0票数 0

立方体应该保持平坦,但朝向光标旋转,只有一种类型的旋转(2d -自上而下)。我现在担心的是,这可能是由于网格对自身的中心?请帮帮我!

点击此处查看:https://thecoop.group/conquest/ground

代码从这里开始:https://github.com/the-coop/coopwebsite/blob/89ca8909ed3fe28afd79b34c5305b63aabba8638/lib/conquest/ground/engine/setupGroundMovement.js#L35

以下是摘录,我尝试了许多不同的方法,一些实验代码可能会保留下来:

代码语言:javascript
复制
    const plane = new Plane(new Vector3(0, 1, 0), 1);
    const raycaster = new Raycaster();
    const mouse = new Vector2();
    const pointOfIntersection = new Vector3();


    document.addEventListener('mousemove', ev => {
        const { camera, me } = window.GROUND_LEVEL;

        mouse.x = ( ev.clientX / window.innerWidth ) * 2 - 1;
        mouse.y = - ( ev.clientY / window.innerHeight ) * 2 + 1;

        raycaster.setFromCamera(mouse, camera);
        raycaster.ray.intersectPlane(plane, pointOfIntersection);
        
        if (me.mesh) {
            // Attempt to make mesh "look at" (rotate) to target position.
            me.mesh.geometry.lookAt(pointOfIntersection);
        }
    });
EN

回答 1

Stack Overflow用户

发布于 2021-07-08 22:05:09

pointOfIntersection有3个维度,对应于立方体的三个轴。

如果只希望立方体在一个轴上旋转,请尝试在Object3D#lookAt中为其他轴指定0

代码语言:javascript
复制
// The cube will rotate on its Y axis when following a point on the X axis
me.mesh.geometry.lookAt(pointOfIntersection.x, 0, 0);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68271790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档