Re: hitTest question
Re: hitTest question
- Subject: Re: hitTest question
- From: Erik Buck <email@hidden>
- Date: Fri, 20 Jun 2008 13:12:36 -0700 (PDT)
You are off to a good start by trying to mimic something as well conceived and implemented as Cocoa's -hitTest: approach.
Now, because you want to re-invent the solution, you will need to know a lot of details about graphics programming and associated mathematics. Determining whether a 2D point is inside a co-planar 2D rectangle is easy. I will leave that up to you. Transforming a 2D point from one 2D coordinate system to another is trivial if you have a proper grounding in graphics programming including affine transform matrixes and associated math. I will simply direct you to google with the terms "coordinate system transformation" A standard and popular text book is "Computer Graphics: Principles and Practice in C" (2nd Edition) by James D. Foley (Author), Andries van Dam (Author), Steven K. Feiner (Author), John F. Hughes (Author).
Hint: Bounding rectangles aren't rotated. Coordinate systems are rotated. Transform your hit point into the correct coordinate system and then use the standard rectangle contains point test.
So, now you know whether your 2D point is within a 2D rectangle that might be in a rotated, scaled, skewed, or transformed coordinate system (e.g. affine transforms). That gives you the NSView base class like implementation of -hitTest:. You might want to determine whether the 2D point hits an opaque portion of a 2D drawing. I will leave that as an exercise but caution that it can be quite difficult and actually hasn't been completely solved in a general way other than via rasterization which you will want to avoid in openGL.
Now, since you are using openGL, you might want to test 3D point intersection with 3D volumes. OpenGL provides a "picking" solution that might meet your needs. Other than that, you are going to have to investigate general collision detection algorithms which are fortunately a highly researched area of computer science. Start with wikipedia for that: http://en.wikipedia.org/wiki/Collision_detection
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden