#ifndef _TUNEL_H
#define _TUNEL_H

#include "turtle.h"
#include "objgl2.h"

#define TRLEN 20 //najvacsi pocet obruci
#define MAXEN 20  //najvacsi mozny n-uholnik, ktory je prierezom tunela 
#define MAXEN1 (MAXEN+1)

struct INFO3D
  {
  Vector3f pos,u,v,n;
  };
/*
typedef struct
{
    GLfloat s, t;
    GLfloat r, g, b, a;
    GLfloat i, j, k;
    GLfloat x, y, z;
} vtx;
*/
typedef Vertex3DS vtx;

struct OBRUCE
  {
  float polomerx[TRLEN];        //polomer obruce -> prenasobi sa nim sc
  float polomery[TRLEN];        //polomer obruce -> prenasobi sa nim sc
  int en[TRLEN];               //kolkouholnikom je kazda obruc
  float sc[TRLEN];             //scale

  Vector3f u[TRLEN];           //info potrebne na rebuild (to iste co v tracku)
  Vector3f v[TRLEN];           //info potrebne na rebuild (to iste co v tracku)
  Vector3f n[TRLEN];           //info potrebne na rebuild (to iste co v tracku)
  Vector3f pos[TRLEN];         //info potrebne na rebuild (to iste co v tracku)

  int to_use;                  //ktora sa najblizsie prepise
  vtx vx[MAXEN1*TRLEN];        //vertexy
  int quads[TRLEN*MAXEN*4];    //indexy na robenie quadov
  int triangle[TRLEN*3];       //pre triangle
  int q_array[TRLEN*MAXEN*4];  
  int q_a;
  int t_array[TRLEN*MAXEN*3];
  int t_a;
  };

class TUNEL
{
    public:
        TUNEL(int n,float sc);
        TUNEL(); //tunel()+reset(x,y)=tunel(x,y);
        ~TUNEL();

        void reset(int n,float sc);
        void render();

        void posun_t(float how_much);
        void pridaj_obruc();             
        void pridaj_obruc(float how_much);             
        void konvert_quads();
        void rebuild();
        void rgb(float er,float ge,float be )
          {
          r=er;
          g=ge;
          b=be;
          };
	INFO3D getinfo(float p);
        INFO3D track[TRLEN]; //ulozena draha pre kameru
        int tr_pos;

        OBRUCE *data;
        TURTLE t;
        int en;
        int inverse;   //ak je jedna je to tube, inac tunel

        float r,g,b;
        float tex_x;   //suradnica na texture
        float scale; 
        float step;
};

#endif