Original Post
I''m just starting to add weapons and enemies and all that neat stuff to my game. So I''d like to start off with a workable collision detection system.
I just need to know if a ray intersects a sphere. I don''t care what the specific point of intersection is.
From reading about it, it sounds like the following method can be used to determine if the ray intersects the sphere, reasonably quickly, without being too complicated:
1- Find if the ray''s origin is outside the sphere.
2- Find the closest approach, tca, of the ray with the sphere
If the ray is outside and points away from the sphere, the ray must miss the sphere.
3- Find the squared distance from the closest approach, t2hc, to the sphere surface.
If the value is negative the ray misses
4- Using tca & t2hc calculate the time, t, of intersection with the sphere
t = tca - sqrt(t2hc), origin outside sphere
t = tca + sqrt(t2hc), origin inside sphere
So, my questions are:
1) Does this method sound like it would work?
2) Is it correct to assume that it can be determined if "the ray points away from the sphere" by seeing if the angle between the ray''s direction and a "perfect" vector towards the sphere (sphere''s center - ray''s origin) is greater than 180 degrees?
3) This is going to sound silly, but... What is the "closest approach", and how is it calculated?
Thanks in advance for any answers - I appreciate it!