greenhouse
a creative coding toolkit for spatial interfaces

Position methods for Node objects

Setting an object to its 3D spatial location and getting information about on object’s location.

For more explanation of the Greenhouse coordinate system and how translation, rotation, and scaling is managed, see this article in the section on wrangling.

About animation:

Various kinds of animation can be applied to how objects move. First, we set up what kind of animation we would like (linear, quadratic, etc.), and second, we set some endpoint (or goal) to animate towards – typically with a call to, say, SetTranslation().

It’s worth noting that if you plan to update the goal of an animation frequently while the animation is still happening (for instance, if an object needs to appear to “follow” a moving target like the mouse cursor, as in the sample here), you may not always get the behavior you expect. Currently, most of the animation functions reset their internal animation timer back to its starting point when SetTranslation() is called.

The only flavor of animation that’s appropriate for continuously updating the goal (as we do here in the sample) is “Chase”. This may be a direction for future API improvement.

  • Loc ()
  • PhysLoc ()
  • Over ()
  • Up ()
  • Norm ()
  • SetTranslation ()
  • IncTranslation ()
  • TranslationAnimateQuadratic ()
  • TranslationAnimateLinear ()
  • TranslationAnimateAsymp ()
  • TranslationAnimateChase ()
  • TranslationAnimateSine ()
  • TranslationAnimateOrbit ()
  • TranslationIsStatic ()
  • SetAlignment ()
  • ClosestFeldCenter ()

Example

#include "Greenhouse.h"

class FollowText : public Text
{ public:
  Vect goal;
  FollowText (const Str &s) : Text (s)
    { SetFontSize (Feld () -> Height () / 30.0);
      SlapOnFeld ();
      SetAlignmentLeft ();
      //  This is the only flavor of animation that's appropriate
      //  for continuously resetting the goal (as we do here in PointingMove)
      TranslationAnimateChase (0.5);
    }

  void Travail ()
    { if (! TranslationIsStatic ())
        SetString ("Loc: " + ToStr (Loc ()) +
                   "\nOver: " + ToStr (Over ()) +
                   "\nUp: " + ToStr (Up ()) +
                   "\nNorm: " + ToStr (Norm ()) +
                   "\ngoal = " + ToStr (goal));
    }

  void PointingHarden (PointingEvent *e)
    { SetTranslationHard (Intersection (e)); }

  void PointingMove (PointingEvent *e)
    { goal = Intersection (e, Feld () -> Loc ());
      SetTranslation (goal);
    }
};

class Heart  :  public Image
{ public:
  Heart ()  :  Image ("images/heart.png")
    { SlapOnFeld();
      SetSize (15.0);
    }

  void Blurt (BlurtEvent * e)
    { if (Utters (e, "q"))
        { TranslationAnimateQuadratic (1.5);
          IncTranslation (Vect (0, 50, 0));
        }
      else if (Utters (e, "l"))
        { TranslationAnimateLinear (1.5);
          IncTranslation (Vect (0, -50, 0));
        }
      else if (Utters (e, "a"))
        { TranslationAnimateAsymp (1.5);
          IncTranslation (Vect (0, 50, 0));
        }
      else if (Utters (e, "s"))
        { // amount, frequency, and phase
          TranslationAnimateSine (Vect (75, 0, 0), 0.25, 0);
         }
      else if (Utters (e, "o"))
        { // major_axis, minor_axis, and frequency
          TranslationAnimateOrbit (Vect (50, 0, 0), Vect (0, 50, 0), 0.25);
          SetTranslationHard (Feld () -> Loc ());
        }
    }
};

void Setup ()
{ new Heart ();
  new FollowText ("I follow the mouse.");
}