帮助在 WPF 中进行物理模拟

发布于 2024-11-01 08:39:41 字数 1475 浏览 4 评论 0 原文

我正在研究 2d 游戏的简单物理原理,我希望获得有关我正在尝试进行的模拟的帮助。

我有一个酒吧会落在地上的固定球上,xaml如下:

<Canvas Background="CornflowerBlue">
    <Rectangle Name="bar" Width="200" Height="20" Fill="Cornsilk" Canvas.Left="250" Canvas.Top="50" />
    <Ellipse Name="ball" Height="50" Width="50" Fill="PaleGreen" Canvas.Left="380" Canvas.Top="250" />
</Canvas>

我拥有所有进行的计算是为了模拟酒吧因重力而下落,但我真正需要帮助的是,一旦酒吧击中球,它的一侧将在地面上,另一侧将在球上方,这几乎可以用xaml:

<Canvas Background="CornflowerBlue">
    <Rectangle Name="bar" Width="200" Height="20" Fill="Cornsilk" Canvas.Left="250" Canvas.Top="246.675" RenderTransformOrigin="0.5,0.5" >
        <Rectangle.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform Angle="-18.897"/>
                <TranslateTransform/>
            </TransformGroup>
        </Rectangle.RenderTransform>
    </Rectangle>
    <Ellipse Name="ball" Height="50" Width="50" Fill="PaleGreen" Canvas.Left="380" Canvas.Top="250" />
</Canvas>

Bar is on the ground

​​ 我不知道如何让栏的左侧接触地面从物理学角度来说,左侧将在球上方。

我知道有像 Farseen 这样很棒的物理引擎,但我只是想了解它在这种情况下如何工作。

我知道如何根据时间获取酒吧的 Y 值,所以我不断检查它,直到它与球碰撞,但之后呢?

谢谢!

I'm studying simple physics for 2d games and I would like a help with a simulation I'm trying to do.

I have a bar that will fall over a fixed ball in the ground, xaml below:

<Canvas Background="CornflowerBlue">
    <Rectangle Name="bar" Width="200" Height="20" Fill="Cornsilk" Canvas.Left="250" Canvas.Top="50" />
    <Ellipse Name="ball" Height="50" Width="50" Fill="PaleGreen" Canvas.Left="380" Canvas.Top="250" />
</Canvas>

Before bar starts falling

I have all the calculations done to simulate the bar falling due to gravity but what I really need help with is, once the bar hits the ball, it's gonna have one side in the ground and the other side over the ball, which could be pretty much represented with the xaml:

<Canvas Background="CornflowerBlue">
    <Rectangle Name="bar" Width="200" Height="20" Fill="Cornsilk" Canvas.Left="250" Canvas.Top="246.675" RenderTransformOrigin="0.5,0.5" >
        <Rectangle.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform Angle="-18.897"/>
                <TranslateTransform/>
            </TransformGroup>
        </Rectangle.RenderTransform>
    </Rectangle>
    <Ellipse Name="ball" Height="50" Width="50" Fill="PaleGreen" Canvas.Left="380" Canvas.Top="250" />
</Canvas>

Bar is on the ground

And I don't know how to make the left side of the bar hit the ground while the left side will be over the ball in phisics terms.

I know there are awesome physics engine available like Farseen but I just want to understand how it would work in this case.

I know how to get the bar's Y based on time, so I keep checking it until it colides with the ball, but then what after that?

Thanks!

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

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

发布评论

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

评论(1

丢了幸福的猪 2024-11-08 08:39:41

刚体物理模拟不是一项简单的任务,除非您对该主题非常感兴趣,否则我建议使用物理库。但如果您有兴趣这样做,我建议您查看 基于物理的建模 SIGGRAPH 课程笔记,Brian Mirtich 的论文关于基于脉冲的动力学,也许还有Kenny Erleben 的论文< /a> 多体动力学。

这些提供了如何实现刚体动力学的非常深入的描述。

Rigid Body physical simulation is not a simple task Unless you are very interested in the topic I would recommend using a physics library. But if you are interested in doing this I would recommend looking at the Physically Based Modeling SIGGRAPH course notes, Brian Mirtich's thesis on impulse based dynamics and perhaps also Kenny Erleben's thesis on multibody dynamics.

These provide a very in depth description of how rigid body dynamics can be implemented.

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