greenhouse
a creative coding toolkit for spatial interfaces

Draw Order

By default, Greenhouse has a depth-sorting graphical scene. This means that objects will be drawn from back to front, in order of their depth in the scene. Following the spatial nature of the Greenhouse SDK, this depth is determined by their real physical location, rather than by some abstract notion of z-depth.

(To be more precise, the ‘depth’ of an object is how far it is along the normal vector pointing out of the main feld. See the Spatial Consideration Tutorial for more information.)

Depth sorting can also be turned off. In this case, objects will be drawn in the order in which they were created (the object created last will be drawn on top).

There are also two more layers in the scene which are treated specially: the windshield and the cursor layer. These layers are only logically ordered; they are not depth-sorted. The windshield is always in front of the main scene; the cursor layer is always in front of that.

  • SetDepthSorting ()
  • BringToFront ()
  • SendToBack ()
  • SetOnWindshield ()
  • QueryOnWindshield ()
  • SetIsCursor ()
  • QueryIsCursor ()
  • ResetApplication ()
  • CameraLoc ()

Example

#include "Greenhouse.h"

class DraggableImage  :  public Image
{
public:
  DraggableImage (Str i)  :  Image (i) { SlapOnFeld (); }

  void PointingInsideHarden (PointingEvent *e)
    { if (IsHeedless ())
        { Heed (e);
          if (QueryIsCursor ())
            Heartbeat ();
          else
            BringToFront ();
        }
    }

  void PointingMove (PointingEvent *e)
    { if (IsHeeding (e))  // drag the object
        IncTranslation (IntersectionDiff (e, Loc ()));
    }

  void PointingSoften (PointingEvent *e)
    { if (IsHeeding (e))
       StopHeeding ();
    }
};

void Setup ()
{ //  Use logical ordering, where the object created last goes on top
  SetDepthSorting (false);

  Text *t = new Text ("I'M ON THE WINDSHIELD");
  t -> SlapOnFeld ();
  t -> SetTextColor(Color (1, 1, 0));

  DraggableImage *kid = new DraggableImage ("images/blue.jpg");
  kid -> SetHeightUniformly (t -> Height ());
  kid -> SetTranslation (t -> Loc () - t -> Height () * t -> Up ());
  t -> AppendKid (kid);

  t -> SetOnWindshield (true);
  if (kid -> QueryOnWindshield ())
    INFORM ("I'M ON THE WINDSHIELD TOO");

  for (int i = 0; i < 6; i++)
    { Str img_name = "images/" + ToStr (i + 1) + ".jpg";
      DraggableImage *img = new DraggableImage (img_name);
      img -> SetAlpha (0.9);
      img -> SetDiagonal (50);
      float64 over = Random (-Feld () -> Width ()/2, Feld () -> Width ()/2);
      float64 up = Random (-Feld () -> Height ()/2, Feld () -> Height ()/2);
      img -> IncTranslation (over * Feld () -> Over () +
                             up * Feld () -> Up ());
    }

  DraggableImage *cursor_level = new DraggableImage ("images/heart.png");
  cursor_level -> SetDiagonal (7);
  cursor_level -> SetIsCursor (true);
  cursor_level -> SlapOnFeld ();
  cursor_level -> SendToBack (); // draw behind the needlepoints
}