/*
	Wheels Of Steel
	Copyright (c) 2006, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef TRACK_H
#define TRACK_H

//##############################################################################
// Forward declarations
//##############################################################################

class Window;
class Camera;
class TrackSection;

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   Track
// Purpose:      Track generation, organisation of track sections and drawing.
//               Management and moving of track entities.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class Track
{
 /*-----------------------------------------------------------------------------
 Public functions and data
 -----------------------------------------------------------------------------*/

 public:

        //----------------------------------------------------------------------
        // Constants
        //----------------------------------------------------------------------

        static const float SECTION_SIZE_X;			// X size of each section (normally)
        static const float SECTION_SIZE_Z;			// Z size of each section
        static const float SECTION_LINE_SIZE_X;		// X size of the road lines
        static const float VIEW_PLANE_NEAR;         // view volume plane z distance from camera: near
        static const float VIEW_PLANE_FAR;			// view volume plane z distance from camera: far
        static const float LINE_CULL_DISTANCE;		// Distance to avoid drawing lines at

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // track constructor:

        Track
        (
            unsigned    lenght,             // lenght of the track (in sections)
            float       minHillHeight,      // minimum height of a hill
            float       maxHillHeight,      // maximum height of a hill
            float       minTurnAmount,      // minimum turn amount
            float       maxTurnAmount       // maximum turn amount
        );

        // track destructor: free track resources

        ~Track();

        // Draw the track

        void draw ( Window & window, Camera * viewpoint);

        // The the number of sections and a pointer to the sections array

        inline unsigned int    getSections_count(){ return sections_count; }
        inline TrackSection ** getSections_array(){ return sections_array; }

        // Info about the layout of the track at a particular z value

        float getY  (float z);   // get the y value at a particular z
        float getLX (float z);   // get the left  x value of the tarmac part of the section at a particular z
        float getRX (float z);   // get the right x value of the tarmac part of the section at a particular z

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

 /*-----------------------------------------------------------------------------
 Private functions and data
 -----------------------------------------------------------------------------*/

 private:

        //----------------------------------------------------------------------
        // Variables
        //----------------------------------------------------------------------

        unsigned int    sections_count;     // number of sections in the track
        TrackSection ** sections_array;     // array of pointers to the track sections

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // generate hills along a part of the track

        void generateHills
        (
            float *             track_y,           // array holding y coordinates for each section of the track
            const unsigned int  HILLS_START,       // section number: where to start generating hills
            const unsigned int  HILLS_END,         // section number: where to end   generating hills
            const unsigned int  HILL_LENGHT_MIN,   // minimum lenght of one particular stretch of a hill (in track sections)
            const unsigned int  HILL_LENGHT_MAX,   // maximum lenght of one particular stretch of a hill (in track sections)
            const float         HILL_HEIGHT_MIN,   // minimum positive/negative height of one particular stretch of a hill
            const float         HILL_HEIGHT_MAX    // maximum positive/negative height of one particular stretch of a hill
        );

        // generate turns along a part of the track

        void generateTurns
        (
            float * track_l_x,                     // array holding left  x coordinates for each section of the track
            float * track_r_x,                     // array holding right x coordinates for each section of the track
            const unsigned int  TURNS_START,       // section number: where to start generating turns
            const unsigned int  TURNS_END,         // section number: where to end   generating turns
            const unsigned int  TURN_LENGHT_MIN,   // minimum lenght of one particular stretch of a turn (in track sections)
            const unsigned int  TURN_LENGHT_MAX,   // maximum lenght of one particular stretch of a turn (in track sections)
            const float         TURN_AMOUNT_MIN,   // minimum positive/negative amount along x axis a turn must go
            const float         TURN_AMOUNT_MAX    // maximum positive/negative amount along x axis a turn must go
        );

}; // end of: class Track{}

//##############################################################################
// C++ Includes
//##############################################################################

#include "Window.h"
#include "Camera.h"
#include "TrackSection.h"

#endif // end of: ifndef TRACK_H
