Objective C 游戏几何问题

发布于 2024-10-23 18:17:33 字数 210 浏览 0 评论 0原文

我正在创建简单的游戏,并达到了我感到无助的地步。我的几何学很好,但回到学校已经很长时间了,现在我正在努力刷新我的想法。

假设我有 iPad 屏幕。对象在一个给定时间点的 xy 位置和另一时间点的 xy 位置存储在 2 个变量中。

问题: 考虑到对象从点 1 到点 2 以相同方向(线)移动,如何在给定前 2 个位置的屏幕末尾找到对象的第三个位置。

提前致谢。

I'm creating simple game and reached the point where I feel helpless. I was good in geometry but it was long time back in school, now trying to refresh my mind.

Let's say i have iPad screen. Object's xy position at one given point of time and xy position at another point of time stored in 2 variables .

Question:
how to find the third position of the object at the end of the screen being given previous 2 position, considering the object moves in the same direction (line) from point 1 to point 2.

Thanks in advance.

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

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

发布评论

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

评论(2

離殇 2024-10-30 18:17:33

让我们假设 v1v2 是代表两个点的向量。令t0 为两点之间的时间。令 t 为当前时间。

那么我们的位置向量v3由下式给出:v3 = v1 + (v2 - v1)t/t0

Let us have that v1 and v2 are the vectors representing the two points. Let t0 be the time between the two points. Let t be the current time.

Then our location vector v3 is given by v3 = v1 + (v2 - v1)t/t0

乖乖兔^ω^ 2024-10-30 18:17:33

如果物体沿相同方向移动并且有一条水平线,则给定 x 和 y 的下一个位置将为

x+1, y

如果物体沿垂直线沿相同方向移动,则为

x, y+1

如果物体沿对角线向上移动-右

x+1,y+1

对角线下-右

x+1, y+1

对角线下-左

x-1, y-1

对角线上-左

x-1, y+1

所以一般情况是:

newPosition = (x+1,y) //if you wish to move forward to the right, try to handle all    
                        cases

如果对象向前移动,则上述所有情况都有效,如果向后移动,只需将 + 更改为 - 。基本上可以将对象视为在笛卡尔坐标系中移动,其中 x 是水平的,y 是垂直的。

我想你可以从这三个案例中得到这个想法;)

If the object is moving in the same direction and you have an horizontal line, the next position given x and y would be

x+1, y

If the object is moving in the same direction in a vertical line it would be

x, y+1

If the object is moving in a diagonal up-right

x+1,y+1

diagonal down-right

x+1, y+1

diagonal down-left

x-1, y-1

diagonal up-left

x-1, y+1

So something general would be :

newPosition = (x+1,y) //if you wish to move forward to the right, try to handle all    
                        cases

All the cases above work if the object is moving forward, if it is moving backwards just change the + by - . Basically think of the object as moving in a cartesian coordinate system, where x is horizontal and y is vertical.

I think you can get the idea out of this three cases ;)

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