Objective C 游戏几何问题
我正在创建简单的游戏,并达到了我感到无助的地步。我的几何学很好,但回到学校已经很长时间了,现在我正在努力刷新我的想法。
假设我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我们假设
v1
和v2
是代表两个点的向量。令t0
为两点之间的时间。令t
为当前时间。那么我们的位置向量
v3
由下式给出:v3 = v1 + (v2 - v1)t/t0
Let us have that
v1
andv2
are the vectors representing the two points. Lett0
be the time between the two points. Lett
be the current time.Then our location vector
v3
is given byv3 = v1 + (v2 - v1)t/t0
如果物体沿相同方向移动并且有一条水平线,则给定 x 和 y 的下一个位置将为
如果物体沿垂直线沿相同方向移动,则为
如果物体沿对角线向上移动-右
对角线下-右
对角线下-左
对角线上-左
所以一般情况是:
如果对象向前移动,则上述所有情况都有效,如果向后移动,只需将 + 更改为 - 。基本上可以将对象视为在笛卡尔坐标系中移动,其中 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
If the object is moving in the same direction in a vertical line it would be
If the object is moving in a diagonal up-right
diagonal down-right
diagonal down-left
diagonal up-left
So something general would be :
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 ;)