简体   繁体   English

Three.js /绕其Y轴旋转对象以朝特定方向看

[英]Three.js / Rotate object around its' Y-axis to look in particular direction

I tried to wrap my head around it for at least a week, but it's too heavy for me. 我试图将头缠绕至少一周,但对我来说太重了。 The problem is that when I click on particular coordinates on the PLANE, i want my 3d model to rotate to face the new coordinates, and then change it's position to match the new coordinates ( it would be nice if you also explain to me how to declare objects' speed and move it with that speed ). 问题是,当我单击“平面”上的特定坐标时,我希望我的3d模型旋转以面对新坐标,然后更改其位置以匹配新坐标(如果您还向我解释了如何声明对象的速度并以该速度移动)。

I know it has to do something with THREE.Matrix4() function. 我知道它必须与THREE.Matrix4()函数做一些事情。

(If You ever played starcraft or similar game, you'll know what I'm up to ;> ) (如果您曾经玩过星际争霸或类似的游戏,您会知道我在做什么;>)

Here is what I have so far: 这是我到目前为止的内容:

http://f.cl.ly/items/1u2q463D1Y0K3G1W2g3P/bf.jpg http://f.cl.ly/items/1u2q463D1Y0K3G1W2g3P/bf.jpg

And here is what I want to achieve: 这是我想要实现的目标:

http://i.stack.imgur.com/Q2vrs.jpg http://i.stack.imgur.com/Q2vrs.jpg

First, you will need to do raycasting, to calculate the position of the plane that your mouse cursor intersected when you clicked, check out http://stemkoski.github.io/Three.js/Mouse-Over.html for a related example with code. 首先,您需要进行光线投射,以计算单击时鼠标光标相交的平面的位置,请查看http://stemkoski.github.io/Three.js/Mouse-Over.html中的相关示例。与代码。 Then, once you know the position, you can use the lookAt function: see http://mrdoob.github.io/three.js/examples/misc_lookat.html for details. 然后,一旦知道位置,就可以使用lookAt函数:有关详细信息,请参阅http://mrdoob.github.io/three.js/examples/misc_lookat.html

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

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