Re: Select a NSBezierPath
Re: Select a NSBezierPath
- Subject: Re: Select a NSBezierPath
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 21 Sep 2004 10:58:45 -0700
On Sep 20, 2004, at 7:04 PM, Robert Clair wrote:
There is a much simpler way to do this, which Michael Johnson at Pixar
explained to me a couple of years ago. The approach he described is to
use an off-screen drawing destination, and draw each object that you
want to check for hits in a distinct color. Then, given a location,
look at the color at that point, and use the color as an index to the
object that you've hit. This technique has been used for many
years in the 3D animation industry.
This is the best way to go for a general drawing program - if for no
other reason
than it will account for line-width and for non-Bezier objects (images
with or without alpha if you
draw them as an image mask for picking purposes).
There is a caveat - if you have _lots_ of objects your colors might be
very close together in
which case you must be careful to turn off anti-aliasing and
interpolation - or else
you can wind up picking the wrong object. (Not a problem if you check
one object at a time
and clear the view each time, but I want to pick the object that is
the one visible to the user
in the view as it is drawn so I render the whole display list and then
check.)
There is a much simpler way to do this, which Michael Johnson at Pixar
explained to me a couple of years ago. The approach he described is
to
use an off-screen drawing destination, and draw each object that you
want to check for hits in a distinct color. Then, given a location,
look at the color at that point, and use the color as an index to the
object that you've hit. This technique has been used for many
years in the 3D animation industry.
This is the best way to go for a general drawing program - if for no
other reason
than it will account for line-width and for non-Bezier objects (images
with or without alpha if you
draw them as an image mask for picking purposes).
There is a caveat - if you have _lots_ of objects your colors might be
very close together in
which case you must be careful to turn off anti-aliasing and
interpolation - or else
you can wind up picking the wrong object. (Not a problem if you check
one object at a time
and clear the view each time, but I want to pick the object that is
the one visible to the user
in the view as it is drawn so I render the whole display list and then
check.)
Yes, you would of course turn off anti-aliasing in the offscreen
buffer. You'd also use the device RGB color space.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden