#include "stdafx.h"
#include "LineOfSightChasing.h"

const float LineOfSightChasing::TOLERANCE = 0.1f;       // tolerance range for the calculation of the target vector


LineOfSightChasing::LineOfSightChasing()
{
}

LineOfSightChasing::LineOfSightChasing(GameObject3D* pHostCraft, const GameObject3D* preyObject)
{
    m_pHostObject = pHostCraft;
    m_pPrey     = preyObject;
}

LineOfSightChasing::~LineOfSightChasing(void)
{
}

void LineOfSightChasing::SetPreyObject(const GameObject3D& preyObject)
{
    m_pPrey = &preyObject;
}


void LineOfSightChasing::Cycle(float deltaMs)
{
    if (m_pPrey)
    {
        CVector u;
        u = m_pPrey->m_Position - m_pHostObject->m_Position;
        u.rotate2D(- m_pHostObject->m_RotZ);      
        u.normalize();

        if(u.x < - LineOfSightChasing::TOLERANCE)
        {
            this->m_pHostObject->m_RotZ -= m_pHostObject->m_RotationSpeed * deltaMs;
            //DxWrapper::Instance()->WriteLog("DoLineOfSightChase() ROTATE LEFT");
        }
        else if (u.x > LineOfSightChasing::TOLERANCE)
        {
            this->m_pHostObject->m_RotZ += m_pHostObject->m_RotationSpeed * deltaMs;
            //DxWrapper::Instance()->WriteLog("DoLineOfSightChase() ROTATE RIGHT");
        }
    }
}

void LineOfSightChasing::Draw()
{
    
}