如何计算同时旋转和加速的物体的位置?

发布于 2024-11-04 18:10:45 字数 403 浏览 4 评论 0原文

我正在尝试编写一个简单的游戏,但我坚持认为是简单的物理原理。我有一个物体,它位于 0,0,0 点,并且以每秒 1 个单位的速度行进。如果我给出指令,该物体必须每秒转动 15 度,持续 6 秒(因此它最终会在起始位置右侧旋转 90 度),并以每秒 1 个单位的速度加速 4 秒(因此它的最终速度为 5每秒单位),如何计算它的终点?

我想我知道如何回答一个没有加速的物体的问题,因为它只是一个圆圈。在上面的例子中,我知道圆的周长是 4 * 距离(因为它穿过圆的 1/4),由此我可以计算半径和角度,并使用简单的三角函数来求解答案。

然而,因为在任何给定时刻,物体的移动速度都比前一时刻稍快,所以我的最终结果不会是圆,而是某种弧线。我想我可以通过循环每个步骤(例如每秒 60 步)来估计终点,但这听起来容易出错且效率低下。

有人能指出我正确的方向吗?

I am trying to write a simple game, but I'm stuck on what I think is simple physics. I have an object that at point 0,0,0 and is travelling at say 1 unit per second. If I give an instruction, that the object must turn 15 degrees per second , for 6 seconds (so it ends up 90 degrees right of it's starting position), and accelerate at 1 unit per second for 4 seconds (so it's final speed is 5 units per second), how do I calculate it's end point?

I think I know how to answer this for an object that isn't accelerating, because it's just a circle. In the example above, I know that the circumference of the circle is 4 * distance (because it is traversing 1/4 of a circle), and from that I can calculate the radius and angles and use simple trig to solve the answer.

However, because at any given moment in time the object is travelling slightly faster than it was in the previous moment, my end result wouldn't be a circle, it would be some sort of arc. I suppose I could estimate the end point by looping through each step (say 60 steps per second), but this sounds error prone and inefficient.

Could anybody point me in the right direction?

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

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

发布评论

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

评论(2

不念旧人 2024-11-11 18:10:45

你的逐步完成的想法正是你所做的。

几乎所有游戏都在所谓的“游戏滴答”下运行。实际上可能会发生许多不同的情况。

“游戏滴答声” - 每次游戏滴答声,都会触发一组请求,重新评估 AI,并且总体游戏状态会发生变化。

“物理滴答” - 每个物理滴答,每个物理对象都会根据其当前的物理状态发生状态变化。

“图形刻度” - 也称为渲染循环,这只是将游戏状态绘制到屏幕上。

游戏滴答声和物理滴答声经常(但不需要)彼此一致。您可以有一个物理刻度,它以当前速度沿着当前的运动矢量移动物体,并在必要时对其施加重力(改变其速度),同时在完全独立的循环中添加额外的加速度(可能通过火箭助推器?)。通过适当的多线程处理,它可以很好地组合在一起。它们越解耦,以后就越容易用更好的实现替换它们。

通过时间步长进行模拟是实时游戏中几乎所有物理过程的完成方式。我什至曾经为国防部进行热建模,这也是我们在那里进行物理建模的方式(我们只需使用更大的计算机:-))

此外,这允许您在物理引擎中实现复杂的旋转。 物理引擎中的特殊情况越少,发生故障的情况就越少。

Your notion of stepping through is exactly what you do.

Almost all games operate under what's known as a "game tick". There are actually a number of different ticks that could be going on.

"Game tick" - each game tick, a set of requests are fired, AI is re-evaluated, and overall the game state has changed.

"physics tick" - each physics tick, each physical object is subject to a state change based on its current physical state.

"graphics tick" - also known as a rendering loop, this is simply drawing the game state to the screen.

The game tick and physics tick often, but do not need to, coincide with each other. You could have a physics tick that moves objects at their current speed along their current movement vector, and also applied gravity to it if necessary (altering its speed,) while adding additional acceleration (perhaps via rocket boosters?) in a completely separate loop. With proper multi-threading care, it would fit together nicely. The more de-coupled they are, the easier it will be to swap them out with better implementations later anyway.

Simulating via a time-step is how almost all physics are done in real-time gaming. I even used to do thermal modeling for the department of defense, and that's how we did our physics modelling there too (we just got to use bigger computers :-) )

Also, this allows you to implement complex rotations in your physics engine. The less special cases you have in your physics engine, the less things will break.

白日梦 2024-11-11 18:10:45

你问的实际上是一个数学变化率问题。每个运动中的物体都有 (x,y,z) 位置。如果您能够将分量速度和加速度分解到各自的平面中,您的最终终点将是 (x1, y1, z1),这是该平面中方程的相应结果。

希望它有帮助(:

What you're asking is actually a Mathematical Rate of change question. Every object that is in motion has position locations of (x,y,z). If you are able to break down the component velocity and accelerations into their individual planes, your final end point would be (x1, y1, z1) which is the respective outcome of your equations in that plane.

Hope it helps (:

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