greenhouse
a creative coding toolkit for spatial interfaces

Intersections

Helper functions for finding intersections of directional events with Felds.

All of these functions take a PointingEvent or DisplacementEvent as the argument. A PointingEvent can be generated by the Mouse, Gloves, Wands, iOS ‘Pointer’ app, and Hantenna.

  • ClosestHitFeld ()
  • FrontmostHitFeld ()
  • ClosestOrFrontmostHitFeld ()
  • Intersection ()
  • IntersectionDiff ()
  • SphereIntersection ()

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"));
}