//  Gl_Car.h - a car that handles graphics, sound and input devices.
//
//  Copyright (C) 2001--2002 Sam Varner
//
//  This file is part of Vamos Automotive Simulator.
//
//  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 _GL_CAR_H_
#define _GL_CAR_H_

#include <vamos/body/Car.h>

#include <GL/glu.h>
#include <plib/sl.h>

#include <string>

namespace Vamos_Body
{
  //* An exception thrown when a sound file can't be found.
  class Missing_Sound_File
  {
	// The requested file.
	std::string m_file;

  public:
	//** Constructor
	Missing_Sound_File (std::string file) : m_file (file) {};

	// Return the requested file.
	std::string file () const { return m_file; }
  };


  //* A car that handles graphics, sound and input devices.
  class Gl_Car : public Car
  {
	// The position of the driver's eyes.
	Vamos_Geometry::Three_Vector m_driver_view;

	//** Plib sound objects.

	// The engine sound.
	slSample* mp_sl_engine;


	// Load the sounds from the specifies files.
	void load_sounds (std::string engine_sound_file, 
					  std::string squeal_sound_file);

  protected:
	// The ID number of the OpenGL display list for the car.
	GLuint m_car_graphics_id;

	// Draw the string STR on the screen at position (X, Y).  X and Y
	// set the position of lower-left corner of the text
	void draw_string (const std::string& str, double x, double y);

  public:
	//** Constructor
	Gl_Car (const Vamos_Geometry::Three_Vector& pos,
			std::string engine_sound_file = "");

	//** Destructor
	virtual ~Gl_Car ();

	// Set the position of the driver's eyes relative to the origin.
	void view (const Vamos_Geometry::Three_Vector& driver_view) 
	{ m_driver_view = driver_view; }

	// Render the car according to its current position and
	// orientation.
	virtual void draw ();

	// Perform the transformations for the driver's view.
	virtual void view ();

	// Return the PLIB sound object for the engine.  Can't be const.
	slSample* engine_sound () { return mp_sl_engine; }

	//** Methods defined in derived classes.

	// Make the display list for the car.
	virtual void build () = 0;

	// Draw the gauges and readouts.
	virtual void draw_dashboard () = 0;

	// Return the sound parameters.
	virtual double engine_pitch ();
	virtual double engine_volume ();
  };
}

#endif // not _GL_CAR_H_
