#ifndef LTURTLE_H
#define LTURTLE_H

#include "vect3.h"
#include "LgraphicsBaseClass.h"
#include "Lstring.h"

typedef vector<vect3<float> > p_rec;

/* Settings stack used for solving [] references */
typedef struct s_rec {
    vect3<float>	pos;            /* position in 3space of turtle origin */
    vect3<float>	fow;            /* forward direction */
    vect3<float>	lef;            /* left direction */
    vect3<float>	upp;            /* up direction */
    vect3<float>	last;           /* last position used for connecting cylinders */
    vect3<float>	last_v[9];      /* last vertices of object used for
				 * connecting cylinders */
    r32		dis;            /* value of F distance */
    r32		ang;            /* value of basic angle */
    r32		thick;          /* value of thickness */
    r32		dis2;           /* value of Z distance */
    r32		tr;             /* trope value */
    u16		col;            /* current color */
    u16		last_col;       /* color of last object */
} s_rec;

class Lturtle
{
 public:
  Lturtle(UIClass *ptr);
  ~Lturtle();

  bool  set_Lgraphics(Lgraphics *TheAssociatedLgraphicsClass); //true if graphics could be initialised
  bool  set_Lstring(Lstring *TheAssociatedLstringClass);
  Lstring *get_Lstring();
  bool  InitDraw(double &centre_x, double &centre_y, double &centre_z, double &scale);
  bool  Draw();
  void  SetRandSeed(int i);

 private:
  bool  CheckSetup();
  void  PlotLstring(vect3<float> &centre, double &max_length);
  void  Define_block(vect3<float> p1, vect3<float> p2, vect3<float> up, r32 thick, r32 min_thick, u16 c); //draws a cuboid
  void  Define_form(vect3<float> p1, vect3<float> p2, vect3<float> up, u16 c); //draws a cuboid
  void  Define_closed(vect3<float> p1, vect3<float> p2, vect3<float> up, u16 c); //draws a cuboid
  void  Define_triangles(p_rec *ver, u16 c); //draws a triangle strip
  void  Set_rot(r32 a, vect3<float> n);

  // variables kept
  
  Lstring*	LstringClassPtr;
  Lgraphics*	LgraphicsClassPtr;
  
  int           RandSeed;
  r32		rand_amount;
  r32		trope_amount;
  vect3<float>  trope, C1, C2, C3;
  r32           zmin;

  UIClass*	const	UIClassPtr;
  vect3<float>  sky;
};


#endif
