Mouse hit testing and graphical objects

J

Jon Slaughter

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
 
C

colin

Jon Slaughter said:
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 =^.^=
 
J

Jon Slaughter

colin said:
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
 
C

colin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top