#include "DCameraManager.h"

#include "VectorTool.h"

namespace HPL {
namespace DirectX {
using namespace VectorTool;

static const D3DXVECTOR3 DEFAULT_NORMALIZED_OBJECT_POSITION(0,0,1);
//////////////////////////////////////////////////////////////
DCameraManager::DCameraManager( float fDistance) {
	this->set_Distance( fDistance );

	this->m_vNormalizedQuatanionDireciton = DEFAULT_NORMALIZED_OBJECT_POSITION;

}
DCameraManager::~DCameraManager() {
}


//////////////////////////////////////////////////////////////
// Getter/Setter
HRESULT DCameraManager::set_Distance( float fDistance ) {
	this->m_fDistance = fDistance;
	return S_OK;
}
float DCameraManager::get_Distance() {
	return this->m_fDistance;
}
HRESULT DCameraManager::set_NormalizedQuatanionDirection( D3DXVECTOR3& vNormalizedQuatanionDirection ) {
	D3DXVec3Normalize( &vNormalizedQuatanionDirection, &vNormalizedQuatanionDirection );
	this->m_vNormalizedQuatanionDireciton = vNormalizedQuatanionDirection;
	return S_OK;
}
D3DXVECTOR3 DCameraManager::get_NormalizedQuatanionDirection()  {
	return this->m_vNormalizedQuatanionDireciton;
}

//////////////////////////////////////////////////////////////
// inner operations
/** ビューを更新
  * @param[in]	vCorePosition			衛星位置の中心座標
  * @param[out]	vSatellitePosition		衛星の位置
  * @retval 更新時に異常発生（行列計算等）
  */
HRESULT DCameraManager::get_SatellitePosition(
	D3DXVECTOR3& vCorePosition,
	D3DXVECTOR3* vSatellitePosition)
{
	
	//! カメラ〜ターゲットの距離だけ離す
	D3DXVec3Scale( vSatellitePosition, &this->m_vNormalizedQuatanionDireciton, this->m_fDistance );

	//! 相対位置→絶対位置
	D3DXVec3Add( vSatellitePosition, vSatellitePosition, &vCorePosition );

	return S_OK;
}

/////////////////////////////////////////////////////////////
// Operations
/** 横回転現在の視線方向を基準に緯度回転
  * @param[in]	fRotateHorizontalDegree
  * @retval		HRESULT					TRUE 回転＆視点変換成功
  */
HRESULT DCameraManager::rotateHorizontalDegree( float fRotateHorizontalDegree ) {
	return rotateHorizontal( &this->m_vNormalizedQuatanionDireciton, &m_vNormalizedQuatanionDireciton, fRotateHorizontalDegree );
}

//! 縦回転（現在の視線方向を基準に経度回転
//! Longitudinal
HRESULT DCameraManager::rotateVerticalDegree( float fRotateVerticalDegree ) {
	return rotateVertical( &this->m_vNormalizedQuatanionDireciton, &m_vNormalizedQuatanionDireciton,
		fRotateVerticalDegree );
	
}


}
}
