通过旋转从边缘确定点

发布于 2024-11-03 10:57:33 字数 525 浏览 1 评论 0原文

我正在使用 OpenGL 在 C++ 中编写一个带有弹跳球(x 和 y,不在 Z 中弹跳)的屏幕保护程序。当这个球接触到屏幕边缘时,球上会出现一小块损坏。 (当球损坏到一定程度时,它就会爆炸。)当球不旋转时,找到球损坏的部分是很容易的。

我为此决定的算法是保持最左、最右、最顶部和最底部顶点的位置。对于每次碰撞,我显然需要知道它击中了哪个屏幕边缘。在球滚动之前,当它接触屏幕边缘时,如果它击中屏幕左侧边缘,我知道最左边的顶点是球上被击中的点。从那里,我得到了距该点 d 距离内的所有顶点。我不需要被击中的实际顶点,只需要球表面的点。

这样做,我不需要读取所有顶点,通过球的 x,y 位置平移它们并查看哪些顶点在屏幕外。这样做可以解决我所有的问题,但速度会很慢。

目前,球的旋转由俯仰、偏航和滚动控制。问题是,根据我的偏航角、俯仰角和滚动角,球外表面的哪一点接触了屏幕边缘?我已经考虑过保持向上、向右和方向向量,但我对此完全陌生,正如有人可能注意到的那样,我完全迷失了。我已经在维基百科上阅读了多次关于旋转矩阵的文章,但仍然一片空白。如果我去掉一个旋转角度,事情会简单得多,但我不想这样做。

I'm writing a screensaver with a bouncing ball (x and y, does not bounce in Z) in C++ using OpenGL. When this ball touches the edges of the screen, a small patch of damage will appear on the ball. (When the ball is damaged enough, it will explode.) Finding the part of the ball to damage is the easy part when the ball isn't rotating.

The algorithm I decided for this is that I'm keeping the position left most, right most, top most and bottom most vertex. For every collision, I obviously need to know which screen edge it hit. Before the ball could roll, when it touches a screen edge, if it hit the left screen edge, I know the left-most vertex is the point on the ball that took a hit. From there, I get all vertices that are within d distance from that point. I don't need the actual vertex that was hit, just the point on the ball's surface.

Doing this, I don't need to read all vertices, translate them by the x,y position of the ball and see which are off-screen. Doing this would solve all my problems but would be slow as hell.

Currently, the ball's rotation is controlled by pitch, yaw and roll. The problem is, what point on the ball's outer surface has touched the edge of the screen given my yaw, pitch and roll angles? I've looked into keeping an up, right and direction vector but I'm totally new to this and as someone might notice, totally lost. I've read the rotation matrix article on Wikipedia several times and still drawing a blank. If I got rid of one rotation angle it would be much simpler but I would prefer not to.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天荒地未老 2024-11-10 10:57:33

如果您有旋转角度,那么您可以在代码中重新创建模型视图矩阵。使用该矩阵,您可以将旋转应用于网格的顶点(只需通过乘法),然后像之前一样找到最左边(或其他)顶点。

本文解释了如何使用您拥有的角度构建旋转矩阵。

If you have your rotation angles then you can recreate the model view matrix in your code. With that matrix you can apply the rotation to the vertices of the mesh (simply by multiplication) and then find the left most (or whatever) vertex as you did before.

This article explains how to construct the rotation matrix with the angles you have.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文