**Feld ClosestHitFeld (PointingEvent *e)**

Determine what (if any) is the first feld along this ray’s path, which is hit within the bounds of the feld rectangle.

If there’s no hit, returns NULL.

**Feld FrontmostHitFeld (PointingEvent *e)**

Determine what (if any) is the frontmost feld intersected by this ray – treats felds as planes that extend forever. So finds the “frontmost” along the ray’s path, even if that frontmost feld is not directly hit and the ray would have directly hit another feld later on in its path.

If no intersection (such as pointing away from all felds), returns NULL.

**Feld ClosestOrFrontmostHitFeld (PointingEvent *e)**

Checks for a ClosestHitFeld; if that returns NULL, returns the result of FrontmostHitFeld.

**Vect Intersection
(PointingEvent *e,
const Vect &point_on_plane = Vect::Invalid (),
const Vect &plane_normal = Vect::Invalid ())**

**Vect Intersection
(const Vect &from, const Vect &to,
const Vect &point_on_plane = Vect::Invalid (),
const Vect &plane_normal = Vect::Invalid ())**

Computes the intersection (if any) of a pointing ray with a plane in absolute space.
The pointing ray can be defined by a pointing event or any pair of points.

If the point_on_plane and plane_normal arguments aren’t supplied, the location
of the main feld (i.e. the result of calling Feld()) is used as the point,
and its normal vector (i.e. Feld () -> Norm ()) is used as the normal.

If no intersection is found, return a Vect which is marked as invalid.
(v.Invalid() == true, v.Valid() == false)
*/

**IntersectionDiff (PointingEvent *e,
const Vect &point_on_plane = Vect::Invalid (),
const Vect &plane_normal = Vect::Invalid ())**

IntersectionDiff tells us how far between
(a) the place where this pointing event intersects a plane
(b) the place where the pointing event intersected last frame

If the point_on_plane and plane_normal arguments aren’t supplied, the location
of the main feld (i.e. the result of calling Feld()) is used as the point,
and its normal vector (i.e. Feld () -> Norm ()) is used as the normal.

If no intersection is found, return a Vect which is marked as invalid.
(v.Invalid() == true, v.Valid() == false)

**Vect SphereIntersection (const Vect &from, const Vect &to,
const Vect ¢er, float64 radius)**

**Vect SphereIntersection (PointingEvent *e, const Vect ¢er,
float64 radius)**

Computes the intersection (if any) of a pointing ray with a sphere in absolute
space. The pointing ray can be defined by a pointing event or any pair of points.
The sphere is defined by its center and radius.

### Example

#include "Greenhouse.h"
#include "Sphere.h"
class DragSphere : public Sphere
{
public:
DragSphere (float64 rad) : Sphere (rad * 2.0)
{ SlapOnFeld ();
SetAdjColor (Color (0.6, 0.8, 0.6, 0.7));
}
// Override the base class' HitCheck method with our own logic
bool HitCheck (PointingEvent *e)
{ Vect intersect = SphereIntersection (e -> PhysOrigin (),
e -> PhysThrough (),
Loc (),
Size () / 2.0);
return intersect . IsValid ();
}
void PointingHarden (PointingEvent *e)
{ INFORM ("Closest hit feld is " +
(ClosestHitFeld (e) ? ClosestHitFeld (e) -> Name () : "[NULL]"));
INFORM ("Frontmost hit feld (plane) is " +
(FrontmostHitFeld (e) ? FrontmostHitFeld (e) -> Name () : "[NULL]"));
Vect intersect = Intersection (e, Feld () -> Loc ());
if (intersect . IsValid ())
INFORM ("Pointing event intersects the main Feld at " + ToStr (intersect));
else
INFORM ("Pointing event does not "
"intersect any feld or the plane of any feld");
}
void PointingMove (PointingEvent *e)
{ if (HitCheck (e))
{ INFORM ("Sphere is hit");
float64 angle = IntersectionDiff (e) . Dot (Feld () -> Over ()) /
(16.0 * PI);
IncRotation (Up (), angle);
}
}
};
void Setup ()
{ DragSphere * s = new DragSphere (50.0);
s -> AppendKid (new Text ("the wheels on the bus"));
}