greenhouse
a creative coding toolkit for spatial interfaces

Respiration

With Greenhouse objects, you can implement certain methods that will be called every frame, or once every “respiration cycle”, as we call it.

Implementing any of these methods in your objects is optional.

All these methods are on the main run loop. (Greenhouse applications are almost always single-threaded.) So if you do a slow computation in one of these methods, it will slow down the whole application’s frame rate.

  • Travail ()
  • PreDraw ()
  • DrawSelf ()
  • PostDraw ()
  • TimeSinceLastTravail ()
  • FPS ()

Example

#include "Greenhouse.h"

class DrawingThing  :  public Thing
{ public:

  Trove <Vect> opengl_lines;

  DrawingThing ()  :  Thing ()
    { SlapOnFeld ();
      for (int i = 0  ;  i < 20  ;  i++)
        opengl_lines . Append (Vect (Random (-50, 50),
                                     Random (-50, 50),
                                     Random (-50, 50)));
    }

  void Travail ()
    { IncRotation (Vect (0, 1, 0), .01);
      INFORM ("Time since last travail = " +
              ToStr (TimeSinceLastTravail ()) + "ms");
      INFORM ("FPS () is " + ToStr (FPS ()));
    }

  virtual void PreDraw ()
    { glLineWidth(2.0); }

  void DrawSelf ()
    { glBegin(GL_LINES);
      for (int i = 0; i < opengl_lines . Count() - 1; i++)
        { Vect line_start = opengl_lines . Nth (i);
          glVertex (line_start);
          Vect line_stop = opengl_lines . Nth (i+1);
          glVertex (line_stop);
        }
      glEnd();
    }

  void PostDraw ()
    { glLineWidth(1.0); }

};

void Setup ()
{ new DrawingThing (); }