//===========================================================================//
// File:	EyePointManager.hpp                                                 
// Project: MechWarrior 4
// Contents: 
//			
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 03/20/00  JSE  Initial coding, 
//---------------------------------------------------------------------------//
// Copyright (C) 2000, Microsoft Corp.
// All Rights reserved worldwide
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL
//===========================================================================//


#pragma once

#include "MW4.hpp"

namespace MechWarrior4
{

	class Mech;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// EyePointManager
	//
	typedef Adept::Receiver__ClassData			EyePointManager__ClassData;
	typedef Adept::Receiver__Message			EyePointManager__Message;

	class EyePointManager:
		public Adept::Receiver
	{
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Inheritance Support
	//
	public:
		typedef EyePointManager__ClassData			ClassData;
		typedef EyePointManager__Message			Message;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Construction, Destruction, Testing
	//
	public:
		static void
			InitializeClass();
		static void
			TerminateClass();

		EyePointManager(Mech *parent);
		~EyePointManager();

		void 
			Reuse();
		void
      		TestInstance();
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Class Data support
	//
	public:
		static ClassData 
			*DefaultData;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Simulation support
	//
	public:
	
		enum {
			StabalizedMode,
			FollowMode,
			ToFollowMode,
			ToStabalizedMode
		};

		int 
			eyeState;

		
		Stuff::LinearMatrix4D
			m_originalEyeToParent;

		Stuff::LinearMatrix4D
			m_originalEyeToTorso;

		Stuff::LinearMatrix4D
			m_originalTorsoToRoot;

		Stuff::LinearMatrix4D
			m_springOffset;

		Stuff::LinearMatrix4D
			m_eyeDirection;

		Stuff::LinearMatrix4D
			m_torsoRotation;

		bool initilized;


		Stuff::Scalar
			transitionTimer;
		Stuff::Scalar
			transitionTime;

		void Stabalize(Stuff::Scalar time);
		void Follow(Stuff::Scalar time);

		void 
			SetEyeDirection(const Stuff::LinearMatrix4D& direction)
		{
			Check_Object(this);
			m_eyeDirection = direction;
		}

		void
			SetSpringOffset(const Stuff::LinearMatrix4D& spring)
		{
			Check_Object(this);
			m_springOffset = spring;
		}

		void
			SetTorsoRotation(const Stuff::LinearMatrix4D& torso_rotation)
		{
			Check_Object(this);
			m_torsoRotation = torso_rotation;
		}


		void
			PostCollisionExecute(Stuff::Scalar time_slice);
		void 
			CalculateStabalizedEye(LinearMatrix4D &eye_to_parent);
		void 
			CalculateFollowEye(LinearMatrix4D &eye_to_parent);

	protected:
		Mech
			*m_parentMech;
		MWMover
			*m_eyeJoint;
		MWMover
			*m_eyeParent;
		MWMover
			*m_jointWorld;


	};
}