468,753 Members | 1,131 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,753 developers. It's quick & easy.

Mouse hit testing and graphical objects

What is the general procedure to optimize hit tests on objects with a mouse
cursor? Just loop through all the objects and check for intersection and
break when found or is there something better?

I'm just curious if there is an issue with performance when having many
objects and hit testing on them all?

Thanks,
Jon
Dec 3 '07 #1
3 3576
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:hd*******************@newssvr29.news.prodigy. net...
What is the general procedure to optimize hit tests on objects with a
mouse cursor? Just loop through all the objects and check for intersection
and break when found or is there something better?

I'm just curious if there is an issue with performance when having many
objects and hit testing on them all?
I asume you mean 3d objects?
thats the way I do it with a 3d model/wire mesh editor im making,
but I have small models for now at least,
but a way to reduce procesing drastically is to
have bounding boxes around logically grouped objects.

I actually had to do it diferently than the sample I
copied to start with, so that I could select objects
based on how far away they were from the cursor on the screen,
rather than in 3d dimensions becuase if something was very far
away it was hard to select if something close was nearer in 3d space.
wich means I project the object onto 2d screen space,
rather than project the mouse into a 3d line,
its almost like drawing everything twice,
although I just cheat and use a central point.

Colin =^.^=
Dec 3 '07 #2

"colin" <co*********@ntworld.NOSPAM.comwrote in message
news:0o****************@newsfe3-gui.ntli.net...
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:hd*******************@newssvr29.news.prodigy. net...
>What is the general procedure to optimize hit tests on objects with a
mouse cursor? Just loop through all the objects and check for
intersection and break when found or is there something better?

I'm just curious if there is an issue with performance when having many
objects and hit testing on them all?

I asume you mean 3d objects?
thats the way I do it with a 3d model/wire mesh editor im making,
but I have small models for now at least,
but a way to reduce procesing drastically is to
have bounding boxes around logically grouped objects.

I actually had to do it diferently than the sample I
copied to start with, so that I could select objects
based on how far away they were from the cursor on the screen,
rather than in 3d dimensions becuase if something was very far
away it was hard to select if something close was nearer in 3d space.
wich means I project the object onto 2d screen space,
rather than project the mouse into a 3d line,
its almost like drawing everything twice,
although I just cheat and use a central point.
No, not really for 3D although I imagine I might need it later. Although if
you use 2D projection then I imagine that its the same issue.

I mean just for 2d like for buttons in a UI. What I'm trying to avoid, if
its necessary, is looping through all the possible objects each time the
mouse moves. Although I suppose this might be necessary for rollover like
effects.

I was thinking that would could create a quad tree like structure and only
process those objects within the same quadrant as the mouse.

The main thing I'm trying to avoid is extra processing when its not really
needed. If the mouse does not change much then chances are that reprocessing
every single object is not necessary. I'm thinking that there should be
someway to avoid it.

Jon
Dec 4 '07 #3
yeah but with my 2d projection I also still get a depth too lol
I would imagine its quick enough to loop through all the controls on a form
to not worry about it unless you have an extrodinary number of controls
or limited cpu cycles. you only need to check more or less 10 times a second
anyway.

If you wanted to do it realy quick you could have a per pixel array of
control pointers lol.

"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:0W*******************@newssvr23.news.prodigy. net...
>
"colin" <co*********@ntworld.NOSPAM.comwrote in message
news:0o****************@newsfe3-gui.ntli.net...
>"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:hd*******************@newssvr29.news.prodigy .net...
>>What is the general procedure to optimize hit tests on objects with a
mouse cursor? Just loop through all the objects and check for
intersection and break when found or is there something better?

I'm just curious if there is an issue with performance when having many
objects and hit testing on them all?

I asume you mean 3d objects?
thats the way I do it with a 3d model/wire mesh editor im making,
but I have small models for now at least,
but a way to reduce procesing drastically is to
have bounding boxes around logically grouped objects.

I actually had to do it diferently than the sample I
copied to start with, so that I could select objects
based on how far away they were from the cursor on the screen,
rather than in 3d dimensions becuase if something was very far
away it was hard to select if something close was nearer in 3d space.
wich means I project the object onto 2d screen space,
rather than project the mouse into a 3d line,
its almost like drawing everything twice,
although I just cheat and use a central point.

No, not really for 3D although I imagine I might need it later. Although
if you use 2D projection then I imagine that its the same issue.

I mean just for 2d like for buttons in a UI. What I'm trying to avoid, if
its necessary, is looping through all the possible objects each time the
mouse moves. Although I suppose this might be necessary for rollover like
effects.

I was thinking that would could create a quad tree like structure and only
process those objects within the same quadrant as the mouse.

The main thing I'm trying to avoid is extra processing when its not really
needed. If the mouse does not change much then chances are that
reprocessing every single object is not necessary. I'm thinking that
there should be someway to avoid it.

Jon

Dec 4 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by punkin | last post: by
10 posts views Thread by Danny | last post: by
1 post views Thread by =?Utf-8?B?TWFyaw==?= | last post: by
reply views Thread by Matthew Fitzgibbons | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.