在 Java 2d 中挑选 [英] Picking in java 2d

查看:37
本文介绍了在 Java 2d 中挑选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 java2d 绘制一个简单的图形,我通过为每个对象/形状调用 contains(MousePoint) 来实现拾取,这有效但线性缩放.

I am using java2d to draw a simple graph at the moment I have implemented picking by calling contains(MousePoint) for each object/shape, this works but scales linearly.

在java2d中是否有更高效的采摘方法?

Is there a more efficient method for picking in java2d?

推荐答案

是的,虽然完整的答案对于这个空间来说太长了.

Yes, although the full answer would be too long for this space.

首先,除非你有 lot 节点,那么线性很可能没问题,你不应该改变任何东西除非性能已经看到受苦.

First of all, unless you have a lot of nodes, then linear will most likely be fine, and you shouldn't change anything unless performance is already seen to suffer.

第二,一般来说,您想要的是应用某种层次分解,例如 四叉树.这是一种使用更多内存(和更多时间,在搜索期间分摊)以在所谓的广泛阶段"中排除考虑项目的方法.在网络上进行一些努力会有所帮助,Christer Ericson 所著的实时碰撞检测"一书也将有所帮助.

Second, what you want, in general, is to apply some sort of hierarchical decomposition, such as a quadtree. This is a way of using more memory (and more time up front, amortized during searches) to eliminate items from consideration in a so-called "broad phase". Some diligence on the web will help, as will the book "Real-Time Collision Detection", by Christer Ericson.

这篇关于在 Java 2d 中挑选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆