//ROMTEAM WorldEditor
////////////////////////////////////////////////////////////////////////////////////////
// File        : Line3D.cpp: implementation file for the Line3D, Arc3D and Bezier3D classes
// Author      : Viorel Preoteasa
// Date        : 97.11
// Description :
////////////////////////////////////////////////////////////////////////////////////////
//
//	The code for this classes come from the files Edi_Bez.cpp and Edi_Arc.cpp (OWP project)
//	which implement global functions on structures which contain Bezier and Arc lines. I
//	have writen 3 classes. The Line3D class implements the common things for Bezier
//	Arc courves.
//
////////////////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ACP_Base.h"

#include "ITF.h"
#include "incGAM.h"
#include "GLI.h"
#include "DPT.h"


#include "geo.h"
#include "gli.h"


#undef CPA_WANTS_IMPORT
#undef CPA_EXPORT
#define CPA_WANTS_EXPORT
    #include "OGD.h"
#undef CPA_WANTS_EXPORT
#define CPA_WANTS_IMPORT

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Line3D::Line3D ()
{
}

Line3D::~Line3D()
{
	if(m_dstListOfPoints)
	{
		free(*m_dstListOfPoints);
		m_dstListOfPoints = NULL;
	}
	/* I disagree with following line, but since it was in the previous version :*/
	if(m_pstDynaParams)
	{
		free(m_pstDynaParams);
		m_pstDynaParams = NULL;
	}
}

MTH3D_tdstVector *Line3D::GetListOfPoints()
{
	if(m_ucObjectMode==EDWAY_C_ucModeNoObject)
		return *m_dstListOfPoints;
	else
		return m_hGeometricObject->d_stListOfPoints;
}

void Line3D::Draw()
{
	POS_tdstCompletePosition stMatrix;
	GEO_tdstColor		ColBidon;
	MTH3D_tdstVector	*p_stPointList;
	MTH3D_tdstVector    *p_stPointListEnd;
	unsigned char ucSamplingRate;
	POS_fn_vSetIdentityMatrix(&stMatrix);
	
	/* unsigned long color; */
	ColBidon.xR=(float)0.5;
	ColBidon.xG=(float)0.5;
	ColBidon.xB=(float)0.5;
	ColBidon.xA=(float)0.5;

	p_stPointList = GetListOfPoints();
	if (!p_stPointList) return;

	GLI_xGetCameraMatrix(((GLI_tdstSpecificAttributesFor3D*)(m_pstViewPortAttributes->p_vSpecificToXD))->p_stCam,&stMatrix);
	ucSamplingRate = GetSamplingRate();
	GLI_xLoadMatrix(&stMatrix);
	GLI_vSetFog(100,100,200,&ColBidon);
	p_stPointListEnd=p_stPointList+ucSamplingRate;
	for (;p_stPointList<p_stPointListEnd;p_stPointList++)
	{
		GLI_xDraw3DLine16
		(
			(struct GLD_tdstViewportAttributes_*)(m_pstViewPortAttributes),
			p_stPointList,
			p_stPointList+1,
			m_lColor
		);
	}	
	GLI_xPopMatrix();
}

void Line3D::GetPoint(unsigned char _ucSamplingNumber, MTH3D_tdstVector*_pstSampledPoint)
{
	MTH3D_tdstVector	*p_stPointList;
	if(_pstSampledPoint == NULL ) return;
	if(_ucSamplingNumber>GetSamplingRate())_ucSamplingNumber = GetSamplingRate();
	p_stPointList = GetListOfPoints();
	if(p_stPointList) *_pstSampledPoint = p_stPointList[_ucSamplingNumber];
}
