//
// Tools_PFX_Vector_Object.cpp
//
// Created by KOR - 25/08/2004
//
// Copyright (C) 2004 Rebellion, All Rights Reserved.
//

#include "Core/Asura.h"

// This file's header.
#include "Objects/Tools_PFX_Vector_Object.h"

// Asura includes
#include "Core/Asura_UserInput.h"
#include "Interface/Asura_Overlay_System.h"
#include "Mesh/Asura_Mesh_System.h"
#include "Rendering/Asura_Render.h"
#include "Rendering/Asura_RenderStates.h"

// Tools includes
//#include "Tools_Overlays.h"
#include "Movement/Tools_Movement.h"
#include "Objects/Tools_Object_System.h"

Tools_PFX_Vector_Object::Tools_PFX_Vector_Object()
: m_bGameEntitiesNeedUpdating(false)
, m_bReadyToDelete(false)
{
	//Get a mesh to represent the vector in the world
	Asura_String xMeshName("ToolsShape_CutsceneTrackPoint");
	Mesh = Asura_Mesh_System::GetMesh(xMeshName);
	Asura_Overlay_System::SetHideOverlays(true);
	Tools_Object_System::SelectObject(this);
	Tools_Movement::SetFlyingObject(this);
}

Tools_PFX_Vector_Object::~Tools_PFX_Vector_Object()
{
	Asura_Overlay_System::SetHideOverlays(false);;
	Tools_Movement::SetFlyingObject(NULL);
}

void Tools_PFX_Vector_Object::UpdateWhileSelected()
{
	if(Asura_UserInput::DebouncedKeyPressed(ASURA_KEYID_SPACE))
	{
		Tools_Object_System::SelectObject(NULL);
	}
}

void Tools_PFX_Vector_Object::Update()
{
	if(!IsGroupSelected())
	{
		//On deselection this object should delete itself
		m_bReadyToDelete = true;
	}
}

void Tools_PFX_Vector_Object::UpdatePositionInAsuraData(bool bUpdateLinkedObjects)
{
	m_bGameEntitiesNeedUpdating = true;
}


/// Tools_PFX_Effect_Collision_Plane //////////////////////////////////////////////////////////////

void Tools_PFX_Effect_Collision_Plane::Render()
{
	Tools_Object::Render();

	static float fDX = .5f;
	static float fDY = .5f;
	static float fWX = 5.f;
	static float fWY = 5.f;
	const Asura_Vector_3 xVectorX = Asura_Vector_3(Orientation.e11, Orientation.e21, Orientation.e31);
	const Asura_Vector_3 xVectorY = Asura_Vector_3(Orientation.e12, Orientation.e22, Orientation.e32);
	for(float fX = -fWX; fX <= fWX; fX += fDX)
	{
		const Asura_Vector_3 xPoint1 = Position + xVectorX * fX + xVectorY * (-fWY);
		const Asura_Vector_3 xPoint2 = Position + xVectorX * fX + xVectorY * ( fWY);
		Asura_Render::RenderLine(xPoint1, xPoint2, 0xff00ff00);
	}
	for(float fY = -fWY; fY <= fWY; fY += fDY)
	{
		const Asura_Vector_3 xPoint1 = Position + xVectorX * (-fWX) + xVectorY * (fY);
		const Asura_Vector_3 xPoint2 = Position + xVectorX * ( fWX) + xVectorY * (fY);
		Asura_Render::RenderLine(xPoint1, xPoint2, 0xff00ff00);
	}
}
