Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Picking



I've found that the OpenGL pick method works quickly and accurately for distance picking.

I use a 45 deg fov perspective view and a 1x1 gluPickMatrix for my pick projection at the mouseloc. I've precalculated the perspective equation parameters a & b and calculate the distance to the picked point on the primitive directly using the minimum zmin returned from GL_SELECTION pick. zdist (in model units) = -b/(zmin+a). It's accurate to a fraction of a percent, probably to the accuracy of a projected pixel.

At first I believed the red book which said that the buffer values are the min and max z values for the picked primitive itself. After experimentation, I've proved (to myself anyway) that, using a 1x1 pick matrix, the minimum zmin returned is an accurate z/w for the picked point within a primitive.

E.g., by the perspective formula, parameter a should be = 2*(zfront+zback)/(zfront-zback) and b = 2*(zfront*zback)/(zfront-zback). These are off by a percent or two so I've done 2 picks at each frustum I use (zfront and zback pairs) and solved for a & b rather than using the calculated values. E.g., for zfront=0.1 and zback=200.1, the calculated a=-2.002 and b=0.2001. I use a=-2.0009999267 and b = 0.2001006334 (that I pre-calculated) and the pick distances are accurate to about 3 decimal places (model units) across a triangle rotated at angles up to 85 degs (or so) at any distance up to zback. I.e., a triangle 2 units on the long side, initially at a distance of (say) 10 units, rotated close to 90 degrees shows distances of 9 to 11 units across the face.

That doesn't address the problem of getting uv coords, of course.

Bruce
email@hidden
http://veazie.org
_______________________________________________
mac-opengl mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/mac-opengl
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.