如何在 Windows C++ 中跟踪数千个绘制的形状CLR

发布于 2024-10-01 10:24:59 字数 136 浏览 5 评论 0原文

我希望面板上可能有数千个绘制的形状,并且当我将鼠标悬停或单击它们时能够识别它们。最好的方法是什么?

我的猜测是我必须在表格中包含一些形状区域。当我将鼠标悬停在页面上时,有一些巧妙的方法来查找匹配项。看起来计算量很大。有没有可以提供帮助的方法?

I want to have potentially thousands of painted shapes on a panel and be able to identify them when I mouseover or click on them. What is the best way to do this?

My guess is I have to have some shape regions in a table. And have some clever way of looking up matches when I hover across page. Seems computationally intensive. Are there methods out there that can help?

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

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

发布评论

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

评论(2

帅的被狗咬 2024-10-08 10:24:59

当您在面板中绘制时,还将形状绘制到未显示的位图中,并使用形状 ID 作为颜色。当您需要查找形状时,只需检查位图中适当坐标处的像素即可。确保在绘制位图时关闭所有线条平滑或抗锯齿功能!

When you paint into your panel, also paint the shapes into a bitmap that isn't displayed and use the shape ID as the color. When you need to look up a shape, just check the pixel at the appropriate coordinates in your bitmap. Make sure you turn off any line smoothing or antialiasing when drawing the bitmap!

铜锣湾横着走 2024-10-08 10:24:59

您想要的是类似 四叉树二进制空间分区(BSP)。

四叉树相当简单。 BSP 的速度非常快,但不能处理移动的形状并且难以构建。

空间哈希非常容易编码并在运行时自行构建。它的主要缺点是最坏情况下查找时间会退化O(n)(如果大多数形状位于水平或垂直线上)。

Box2D 使用它自己的 空间分区。我不太确定底层算法是什么以及它是新颖的还是派生的。但艾琳写道 Box2D 的 Broadphase 使其可以在物理引擎之外使用。该代码已获得 zlib 许可,因此您只需复制所需的几个文件即可。

What you want is something like a Quad Tree or Binary Space Partitioning(BSP).

Quad Tree is fairly simple. BSP's are insanely fast, but do not handle moving shapes and are difficult to build.

A Spatial Hash is really easy to code and builds itself at runtime. Its primary disadvantage is its worse case look up time degenerates O(n) (if most of the shapes in horizontal or vertical line).

Box2D uses it own breed of space partitioning. I'm not really sure what the underlying algorithm is and whether it's novel or derived. But Erin wrote Box2D's broadphase so that it can be used outside of the physics engine. The code is zlib licenced, so you can just copy out the few files you need.

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