//  Track.h - the interface for tracks
//
//	Vamos Automotive Simulator
//  Copyright (C) 2003 Sam Varner
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#ifndef _TRACK_H_
#define _TRACK_H_

#include <vamos/geometry/Material.h>
#include <vamos/geometry/Three_Vector.h>
#include <vamos/geometry/Three_Matrix.h>

#include <string>

namespace Vamos_Track
{
  struct Track_Contact_Info
  {
	Track_Contact_Info (bool contact, double depth,
						Vamos_Geometry::Three_Vector normal,
						Vamos_Geometry::Material_Handle material) :
	  m_contact (contact),
	  m_depth (depth),
	  m_normal (normal),
	  m_material (material)
	{};

	bool m_contact;
	double m_depth;
	Vamos_Geometry::Three_Vector m_normal;
	Vamos_Geometry::Material_Handle m_material;
  };

  class Track
  {
  public:
	// Read the track definition file.
	virtual void read (std::string data_dir = "", 
					   std::string track_file = "") = 0;

	// Draw the track.
	virtual void draw () const = 0;

	// Make the track.
	virtual void build () = 0;

	// Add a sector timing line.
	virtual void timing_line (double dist) = 0;

	// Return the number of timing lines.
	virtual size_t timing_lines () const = 0;

	// Add a speed trap.
	virtual void speed_trap (double start, double end) = 0;

	// Return the bounds of the track.
	virtual double min_x () const = 0;
	virtual double max_x () const = 0;
	virtual double min_y () const = 0;
	virtual double max_y () const = 0;

	// Scale the track to a particular length.
	virtual void length (double len) = 0;

	// Reset the track to its initial state.
	virtual void reset () = 0;

	//!! Most of the rest should be const.

	// Return the new position for a vehicle at POS when a reset is
	// performed. 
	virtual Vamos_Geometry::Three_Vector 
	reset_position (const Vamos_Geometry::Three_Vector& pos) = 0;

	// Return the new orientation for a vehicle at POS when a reset is
	// performed. 
	virtual Vamos_Geometry::Three_Matrix
	reset_orientation (const Vamos_Geometry::Three_Vector& pos) = 0;

	// Return the elevation of the track at the x and y components of
	// POS.
	virtual double elevation (const Vamos_Geometry::Three_Vector& pos,
							  double bump_parameter) = 0;

	virtual Track_Contact_Info 
	test_for_contact (const Vamos_Geometry::Three_Vector& pos,
					  double bump_parameter) = 0;

	// Return the distance along the track for the given position.
	virtual double distance (const Vamos_Geometry::Three_Vector& pos) = 0;

	// Return the timing sector at the given distance.
	virtual int sector (double distance) = 0;
  };
}

#endif
