//	World3.cpp - One of the worlds.
//  ----------------------------------------------------------------------------
//	This file is part of 'NiallsAVLib', base code for any kind of audiovisual
//	apps.
//	Copyright (C) 2012  Niall Moody
//	
//	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 3 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, see <http://www.gnu.org/licenses/>.
//	----------------------------------------------------------------------------

#include "MiscHelper.h"
#include "World3.h"

//------------------------------------------------------------------------------
World3::World3():
World(ThreeFloats(233.0f/255.0f, 250.0f/255.0f, 185.0f/255.0f),
	  ThreeFloats(253.0f/255.0f, 149.0f/255.0f, 0.0f/255.0f),
	  ThreeFloats(4.0f/255.0f, 7.0f/255.0f, 61.0f/255.0f),
	  ThreeFloats(163.0f/255.0f, 159.0f/255.0f, 255.0f/255.0f),
	  ThreeFloats(1.0f, 0.94f, 0.8f),
	  TwoFloats(3920.0f, 640.0f)),
pulseCount(1),
pulse(0.0f),
done(false)
{
	ringCols[0] = getRing1Col();
	ringCols[1] = getRing2Col();
	ringCols[2] = getRing3Col();
}

//------------------------------------------------------------------------------
World3::~World3()
{

}

//------------------------------------------------------------------------------
void World3::mouseMove(const TwoFloats& pos)
{
	float tempf;

	if(pulse > 0.0f)
	{
		if(pos.getDistance(lastPos) > 64.0f)
		{
			tempf = getOverallScale();

			if(tempf < 0.66f)
			{
				tempf += 0.04f;
				setOverallScale(tempf);
			}

			if(getOverallScale() >= 0.66f)
				done = true;
		}
	}
	else if(pos.getDistance(lastPos) > 64.0f)
	{
		tempf = getOverallScale();

		if(tempf < 0.66f)
		{
			tempf -= 0.02f;
			setOverallScale(tempf);
		}
	}

	lastPos = pos;
}

//------------------------------------------------------------------------------
void World3::subclassTick()
{
	/*--pulseCount;
	if(pulseCount <= 0)
	{
		pulse = 0.02f;
		pulseCount = 120;
	}*/

	if(pulse > 0.0f)
	{
		float tempf;
		ThreeFloats tempCols[3];
		const ThreeFloats white(1.0f, 0.0f, 0.0f);

		pulse += 0.02f;
		if(pulse >= 1.0f)
		{
			pulse = 0.0f;
			tempCols[0] = ringCols[0];
			tempCols[1] = ringCols[1];
			tempCols[2] = ringCols[2];
		}
		else
		{
			tempf = (cosf(pulse * 2.0f * NIALL_PI)*0.5f)+0.5f;

			tempCols[0] = ringCols[0] * tempf;
			tempCols[0] += white * (1.0f-tempf);

			tempCols[1] = ringCols[1] * tempf;
			tempCols[1] += white * (1.0f-tempf);

			tempCols[2] = ringCols[2] * tempf;
			tempCols[2] += white * (1.0f-tempf);
		}
		setRingColours(tempCols);
	}
}

//------------------------------------------------------------------------------
void World3::barStart()
{
	pulse = 0.02f;
}
