Re: [Plib-users] Selecting with mouse
Brought to you by:
sjbaker
From: Andy R. <an...@ne...> - 2002-10-01 02:59:24
|
Curtis L. Olson wrote: > I think step one would be to get a general purpose vector/scene-graph > intersection routine in plib. Plib does have something that will > intersect a z=up vector with the geometry (for use in finding ground > height in a z=up game.) But, there needs to be a more general purpose > routine that can find intersections with any arbitrary vector. This shouldn't be too terribly difficult. The mouse vector can be gotten from the modelview/projection matrices. Either invert them yourself or use gluUnproject(). Transform the near and far plane and you'll get two world-space points to define your line. Then recurse into the scene graph, testing the bounding sphere's against the line*. When you find a leaf whose sphere matches, test each triangle** for intersection. If the bounding spheres are sane, it works in log time in the geometry complexity. And I agree -- vector intersection should be a core plib feature. The landing gear code wants it too. Andy * This test is pretty easy -- just project the sphere centroid onto any 2D space perpendicular to the line and take the 2D distance along the plane. That sounds harder than it is: pick any vector and cross it with the line direction to get a perpendicular vector. Cross that with the line again and normalize all three. These three vectors are the columns of your rotation matrix. Just run any vector from the line to the sphere centroid through this matrix, and ignore the coordinate along the line direction. The remaining 2D distance is the distance to the line. ** This one is harder. I'd have to look it up. You could do it with the projection above -- the problem then becomes a 2D point-in-polygon test, which is reasonably easy. There might be a better way, though. -- Andrew J. Ross NextBus Information Systems Senior Software Engineer Emeryville, CA an...@ne... http://www.nextbus.com "Men go crazy in conflagrations. They only get better one by one." - Sting (misquoted) |