关于鼠标选取算法的问题 谢了先!!

sunpc9999 2005-09-09 11:58:17
One very common operation in the graphical user interface of a computer
program is “picking” ? point the cursor at the item you want and click a
mouse button. But usually there are many items on the screen, and the
program has to decide which has been pointed to. For simplicity, assume
that you only want to pick a point.
i) Design an efficient data structure with the supporting algorithm(s) for
picking a point in a user interface. (Potentially, there can be thousands
of points on the screen, your computer can be slow and your user doesn’t
want to wait. That is, you want the fastest algorithm possible.) State the
assumptions and/or trade-offs, if any, that you have to make in your
design.
(ii) How would you approach the problem of picking a straight line? (Just
discuss the answer conceptually. You don’t have to come up with another
data structure and algorithm.)
...全文
203 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
It is not difficult about your question.

Because I am not sure your graphic engine(base on OpenGL/Directx), anyway, I presume your point is 3D point.

a>Project your 3d point onto screen coordinate system(glProject, etc).
b>Find min distance between cursor position and points(projected).

This method is fast enough on the current pc (1,000,000).
sun4444 2005-09-11
  • 打赏
  • 举报
回复
支持一下!!
学习
sunpc9999 2005-09-09
  • 打赏
  • 举报
回复
现在只要自己写一个数据结构,实现:当鼠标选中对象后,便将对象选中即可。(其中要解决一个层次问题,两个对象重叠时,选中上层对象。) ^-^个人理解^-^
那位仁兄有代码能发来参考一下吗?
快乐鹦鹉 2005-09-09
  • 打赏
  • 举报
回复
能不能用中文把你需求描述一遍?
alphapaopao 2005-09-09
  • 打赏
  • 举报
回复
就是捕捉的问题。
要计算鼠标点位置和曲线之间的距离。直线、圆弧都比较好办,复杂曲线比如 B样条线 就比较难办了。
xiaocai0001 2005-09-09
  • 打赏
  • 举报
回复
呵呵,对不起了,我只是有这方面的想法,没有亲手编写过~~
sunpc9999 2005-09-09
  • 打赏
  • 举报
回复
仁兄,很急用,能否将代码发过来参考一下啊!!
sunpengcheng@126.com
xiaocai0001 2005-09-09
  • 打赏
  • 举报
回复
这个和CAD做的点选有点相似哦

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧