greenhouse
a creative coding toolkit for spatial interfaces

Rotation methods for Node objects

Rotating an object in 3D space.

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 rotate. 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, SetRotation().

It’s worth noting that if you plan to update the goal of an animation frequently while the animation is still happening, 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 SetRotation() is called.

The only flavor of animation that’s appropriate for continuously updating the goal is “Chase”. This may be a direction for future API improvement.

  • SetRotation ()
  • SetRotationHard ()
  • IncRotation ()
  • IncRotationHard ()
  • RotateLike ()
  • RotateLikeHard ()
  • RotationAnimateLinear ()
  • RotationAnimateQuadratic ()
  • RotationAnimateAsymp ()
  • RotationAnimateChase ()
  • RotationAnimateSine ()
  • Angle ()
  • AngleGoal ()
  • Rad ()
  • Deg ()
  • Rotation ()
  • RotationGoal ()
  • RotationIsStatic ()
  • Axis ()
  • AxisGoal ()

Example

#include "Greenhouse.h"

class CustomText  :  public Text
{ public:
  float64 desired_rotation;
  CustomText (const Str &s)  :
    Text (s),
    desired_rotation (Random (PI * 2))  // random value from 0 to 2 PI
    { }

  void Travail ()
    { if (! RotationIsStatic ())
      { INFORM ("Angle () = " + ToStr (Angle ())
                + ", AngleGoal () = " + ToStr (AngleGoal ()));
        INFORM ("AngleGoal () in degrees = " + ToStr (Deg (AngleGoal ())));
        INFORM ("Rad (180) + AngleGoal () = " +
                ToStr (Rad (180) + AngleGoal ()));
      }
    }

  void PointingHarden (PointingEvent *e)
    { desired_rotation = Random (PI * 2, PI * 6);
      //SetRotation (Vect (0, 0, 1), desired_rotation);
      IncRotation (Vect (0, 0, 1), desired_rotation);
      //IncRotationHard (Vect (0, 0, 1), desired_rotation);
    }

};

void Setup ()
{ CustomText *ct = new CustomText ("Hello, Rotation!");
  // Initially put the object at the center of the main feld
  ct -> SlapOnFeld ();

  ct -> RotationAnimateQuadratic (0.5); //seconds
  //ct -> RotationAnimateLinear (0.5); //seconds
  //ct -> RotationAnimateAsymp (0.5); //seconds
  //ct -> RotationAnimateChase (0.1); //seconds
  // axis, angle, frequency, and phase
  //ct -> RotationAnimateSine (Vect (0, 0, 1), M_PI / 2, 1, 0);

  ct -> SetRotationHard (Vect (0, 0, 1), ct -> desired_rotation);
}