在 Flash 中使用鼠标轻松进行 3D 旋转 XYZ 向 2 个方向旋转
我有一个立方体,我想使用鼠标运动来旋转它。因此,如果我将鼠标向左移动,它就会旋转,就好像旋转X增加了一样。当我向右移动时,rotationX 会增加。向上和向下移动会改变旋转 Y。
只要您只修改一个维度(旋转 X 或旋转 Y),这看起来就很好。但如果我已经更改了rotationX,然后尝试修改rotationY,结果会很奇怪。如果 X 轴旋转为 180 度,Y 轴旋转效果相反。它基本上是不可预测的,当然不适合用户。
我尝试环顾四周(失败),阅读有关四元数的内容(无法理解),尝试了一些出乎意料且非常复杂的三角计算(让自己出丑),所以我现在陷入困境。我发现了这个问题 将鼠标拖动运动转换为对象的 3d 旋转的最佳方法,但它对我没有一点帮助,我真的无法理解任何答案。
AS3 中完整的、可行的解决方案/算法将是最好的,但一些伪代码或只是清晰的解释将非常感激。
I have a Cube which I want to rotate using mouse motion. So if I move my mouse to the left it rotates as if rotationX was increased. When I move right rotationX is increased. Moving Up and Down alters rotationY.
This looks fine as long as you modify only one dimension (either rotationX or rotationY). But if I have already changed rotationX and then try to modify rotationY the results are weird. If rotationX is 180 rotationY effects are reversed. It basically is quite unpredictable and certainly not suitable for user.
I have tried to look around (failed), read about quaternions (couldn't understand), tried some out of blue and very complex trigonometric calculations (made a fool out of myself) and so I am stuck now. I've found this SO question Best way to translate mouse drag motion into 3d rotation of an object but it doesn't help me a bit, I can't understand any of the answers, really.
A complete, working solution/algorithm in AS3 would be the best, but some pseudo-code or just clear explanation will be really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在将旋转 Y 应用于已旋转的对象。因此,如果将旋转 X 设置为 180,然后设置旋转 Y,则实际上是在“倒立”地旋转对象。如果您想同时应用 x 和 y 旋转,最好使用 矩阵。您提供的链接很有用:一旦您理解了矩阵的概念,它就会解释一切。您应该阅读本文,特别是如果您打算将来制作更多 3D 作品。
现在,只需查看 Flash 手册Matrix3D 页面。它应该提供您开始操作所需的所有信息和示例。
You are applying the rotationY to an already rotated object. So if you set rotationX to 180, and THEN set rotationY, you are really rotating the object standing "on its head". If you want to apply both the x and y rotation at the same time, it is best to use a matrix. The link you provided is useful: it explains everything once you understand the concept of matrices. You should read up on this, especially if you intend to do more 3D in the future.
For now, just have a look at the Flash manual page for Matrix3D. It should provide all the information and examples you need to get going.