//********************************************
// CCamera.cpp
//********************************************
//********************************************
//********************************************
#include "stdafx.h"
#include "Camera.h"
#include "helpers/Helper.h"
//********************************************
// Constructor
//********************************************
CCamera::CCamera()
{
	Reset();
}

//********************************************
// Destructor
//********************************************
CCamera::~CCamera()
{
}
/*********Get Translations**************/
double CCamera::GetNextXTranslation()
{
	return m_dNextCameraPositionArray[3];
}

double CCamera::GetNextYTranslation()
{
	return m_dNextCameraPositionArray[4];
}

double CCamera::GetNextZTranslation()
{
	return m_dNextCameraPositionArray[5];
}
/*********Set Translations**************/
void CCamera::SetNextXTranslation(double dX)
{
	m_dNextCameraPositionArray[3] = dX;
}

void CCamera::SetNextYTranslation(double dY)
{
	m_dNextCameraPositionArray[4] = dY;
}

void CCamera::SetNextZTranslation(double dZ)
{
	m_dNextCameraPositionArray[5] = dZ;
}
/************Get Rotations**************/
double CCamera::GetNextXRotation()
{
	return m_dNextCameraPositionArray[0];
}

double CCamera::GetNextYRotation()
{
	return m_dNextCameraPositionArray[1];
}

double CCamera::GetNextZRotation()
{
	return m_dNextCameraPositionArray[2];
}
/************Set Rotations**************/
void CCamera::SetNextXRotation(double dX)
{
	m_dNextCameraPositionArray[0] = dX;
}

void CCamera::SetNextYRotation(double dY)
{
	m_dNextCameraPositionArray[1] = dY;
}

void CCamera::SetNextZRotation(double dZ)
{
	m_dNextCameraPositionArray[2] = dZ;
}

//save and load the current camera matrix
void CCamera::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		for (int i = 0; i < 16; i++)
		{
			ar << m_dCameraPositionMatrix[i];
		}
	}
	else
	{
		for (int i = 0; i < 16; i++)
		{
			ar >> m_dCameraPositionMatrix[i];
		}
	}
	
}

//Reset the next camera translations
void CCamera::ResetNextTranslations(void)
{
	ZeroMemory(
    &m_dNextCameraPositionArray, 	 
    sizeof(m_dNextCameraPositionArray)   
   );
}

double* CCamera::GetCameraMatrix(void)
{
	return m_dCameraPositionMatrix;
}

void CCamera::SetCameraMatrix(double *matrix)
{
	for (int i = 0; i < 16; i++)
		m_dCameraPositionMatrix[i] = matrix[i];
}



void CCamera::Reset()
{
	ZeroMemory(
    &m_dNextCameraPositionArray, 	 
    sizeof(m_dNextCameraPositionArray)   
   );

	ZeroMemory(
    &m_dCameraPositionMatrix, 	 
    sizeof(m_dCameraPositionMatrix)   
   );
	//make it the identity
	m_dCameraPositionMatrix[0] = 1;
	m_dCameraPositionMatrix[5] = 1;
	m_dCameraPositionMatrix[10] = 1;
	m_dCameraPositionMatrix[15] = 1;
}

void CCamera::SetInitialPosition(double x, double y, double z)
{
	m_dCameraPositionMatrix[12] = x;
	m_dCameraPositionMatrix[13] = y;
	m_dCameraPositionMatrix[14] = z;
}

//set our height to be height
void CCamera::SetHeight(double dHeight)
{
	m_dCameraPositionMatrix[13] = -(dHeight);
}
