box2d中的脉冲有多少像素

发布于 2024-12-05 18:53:11 字数 188 浏览 1 评论 0原文

我有一个球,你可以向它吹气。我希望球离鼓风机较近时吹得较多,离鼓风机较远时则吹得较少。我正在使用 box2d,并且正在使用脉冲函数。“body->ApplyLinearImpulse(force, body->GetPosition())”。我似乎找不到一个公式或方法来实现这一点。如果我想让球向右吹到总距离为 300 像素,我该如何实现呢?请帮忙。

I have a ball that you blow on with air. I want the ball to be blown more if it is close to the blower and blown less if it is farther away from the blower. I am using box2d and I am using the impulse function."body->ApplyLinearImpulse(force, body->GetPosition())". I can't seem to find a formula or a way to accomplish this. If I want the ball to blow to a total distance of 300 pixels right, how could I accomplish this? Please help.

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

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

发布评论

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

评论(3

过去的过去 2024-12-12 18:53:11

如果你想在模拟之前计算距离,你必须看看 box2d 源。当模拟身体的速度时,根据重力、额外施加的力、线性阻尼、角度阻尼以及可能的其他因素来修改。速度也依赖于速度迭代。

但我认为如果你想要一个真正平滑的运动(比如击打),你最好使用 applyForce 函数而不是脉冲。但请确保您在每个模拟步骤中都施加了力。

编辑:

您还可以将空气阻力模拟为:
Fa = -k*V*V。我用这种方式模拟了管道中的运动。效果很好。

所以每一步你都可以做这样的事情:

BlowForce = k1 / distance; // k1 - coefficient
Resistance = -k2 * V * V; //k2 - another coefficient
TotalForce = BlowForce + Resistance;
body->ApplyForce(TotalForce);

If you want to calculate the distance before simulation you have to take a look at box2d sources. When simulating the velocity of the body is modified according to gravity, extra applied forces, linear damping, angular damping and possibly something more. Also velocity relies on velocity iterations.

But I think if you want a really smooth motion (like from a blow) you'd better use applyForce function instead of impulse. But be sure you are applying the force each simulation step.

EDIT:

Also you can simulate the air resistance as:
Fa = -k*V*V. I've simulated movement in the pipe this way. Worked great.

So each step you can make something like this:

BlowForce = k1 / distance; // k1 - coefficient
Resistance = -k2 * V * V; //k2 - another coefficient
TotalForce = BlowForce + Resistance;
body->ApplyForce(TotalForce);
锦上情书 2024-12-12 18:53:11

我不是盒子 2d 专家,但我要做的是创建一个实际上看不见的小盒子,让球击中盒子......如果鼓风机吹得更多,我会给盒子在相反方向上提供更多速度。就 300 像素长度而言,您必须调整力和速度,以使球进入

300/<your_rendering_window_to_physics_world_ratio>

物理世界。

I am not a box 2d expert but what i would do is create a small box which is actually invisible and let the ball hit the box...if the blower is blowing more i would give more speed to the box in opposite direction. As far as 300 pixel length is concerned you have to adjust the forces and velocity such that the ball goes

300/<your_rendering_window_to_physics_world_ratio>

in physical world.

南烟 2024-12-12 18:53:11

力 = 质量 * 加速度,因此采用您为身体设置的质量,计算您想要的加速度(记住将 300px 除以 PTM_RATIO),然后将两者相乘。

Force = mass * acceleration, so take the mass you set your body to, calculate the acceleration you want (remember to divide 300px by PTM_RATIO) and then multiply the two together.

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