[SDL] Example Of "Ray Casting" With SDL1.2+OpenGL?
mordred at icculus.org
Sun May 1 13:11:15 PDT 2011
On 4/30/2011 4:22 PM, Bob Pendleton wrote:
> No, no they are really not much use at all. They take too long.
> Object picking is best done using the clipping hardware. Every 3D API
> has a clipping API that uses the clipping hardware to do picking.
> Lighting is best done using the rendering hardware to do the lighting
> based on the surface normal of the thing being lighted.
Incorrect. In fact, the selection and feedback API has been removed from
OpenGL as of version 3.0, and hasn't been updated since OpenGL 1.0 or
so. Even on those platforms where it is still supported, It runs on
software, and in most cases it runs slowly on software because nobody
uses it any more and there's no support for it in hardware. So, no, this
is not an appropriate choice.
The traditional method for doing this in a modern application is,
indeed, ray casting, and Brian Hook has kindly posted a very good
explanation of the technique here:
http://bookofhook.com/phpBB/viewtopic.php?t=485 (Obligatory Disclaimer:
I checked the math, but I am credited as Nichola Vining for some
reason.) If you're worried about speed, then yes, you use bounding
primitives and an acceleration structure. Bounding primitives are a good
idea; an acceleration structure may be overkill depending on how few
things you have on the screen.
> The question of whether there is line segment that connects to points
> without passing through another object is also best done by clipping
> to volume that contains the two points and all points in between.
> Anything that isn't clipped out is possibly in the way.
It is unclear what you're talking about here, but I certainly wouldn't
use a clipping approach (at least in the sense of the Sutherland-Hodgman
algorithm, which is the standard algorithm for clipping things (lines?
polygons?)) I would just shoot a ray through the world, see what it
intersects, and then see if the point of intersection that occurs with
anything in the world appears between the two points on the line that we
are concerned with. If you want a line segment, remember from high
school mathematics that a line in space is defined by the equation L = o
+ td where t is a scalar, bounded between two values t0 and t1, and o
and d are vectors. Simply do your line/everything intersection as per
normal, and then see if your intersection point falls between the values
of t0 and t1 for your line segment.
David Eberly's book "Geometric Tools for Computer Graphics" is an
extremely good reference for intersection tests. Another useful resource
is the complete guide to How To Intersect Anything With Anything Else
More information about the SDL