/*
///////////////////////////////////////////////////////////////////////////////////////////////////
// Description : LinkLine.cpp
//   
//  Definition of the link editors objects            
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// inherit from  :	Link
///////////////////////////////////////////////////////////////////////////////////////////////////
// Creation date: 29 jan 1997                        Author: J Thénoz
///////////////////////////////////////////////////////////////////////////////////////////////////
// Modification date:			                      Author: 
// 
//
// 
//
///////////////////////////////////////////////////////////////////////////////////////////////////
*/
//ANNECY Shaitan Nettoyage (12/05/98) {
/*

#include "stdafx.h"
#include "acp_base.h"
#include "incitf.h"
#include "incgam.h"
#include "incai.h"
#include "WPObj.hpp"
#include "WayObj.hpp"
#include "LinkObj.hpp"
#include "LinkLine.hpp"
#include "Eng_StLi.h"


#include "Inter.hpp"

char LinkLine::ms_cType = WP_ConnType_ucStaticLine;						
char LinkLine::ms_szName [10] = "Line";				

void LinkLine::fn_vRegisterObject (void)
{
	tdst_LinkObject* pstLinkObject = new tdst_LinkObject;
	strcpy ( pstLinkObject->szName, ms_szName );
	pstLinkObject->cType = ms_cType;
	pstLinkObject->fn_pConstruct = fn_pConstruct;
	ms_oListLinkObject.AddTail (pstLinkObject);
}

LinkLine::LinkLine ( CPA_ObjectDLLBase *p_oDLL, CPA_BaseObject *p_oOwner, WP_tdhLink hLink )
	: Link ( p_oDLL, p_oOwner, hLink )
{
	m_xLBeam = 0.034f;
	fn_vSetType ( WP_ConnType_ucStaticLine );
}

LinkLine::LinkLine ( CPA_ObjectDLLBase *p_oDLL, CPA_BaseObject *p_oOwner )
	: Link ( p_oDLL, p_oOwner )
{
	m_xLBeam = 0.034f;
	fn_vSetType ( WP_ConnType_ucStaticLine );
}

	
void LinkLine::fn_vConstructGraphic (void)
{
	CPA_SuperObject* poGraphic = GetInterface()->fn_pGetNewLineGraphicObject();
	poGraphic->SetSuperObjectOwner (GetSuperObject());	
	GetSuperObject()->AddTail (poGraphic);
	GEO_xComputeObjectNormals ( (ACP_tdxHandleOfObject)HIE_fn_hGetSuperObjectObject(poGraphic->GetStruct()));
	poGraphic->SetEditProtected (TRUE); 
}

void LinkLine::fn_vRotationGraphic (BOOL bRotation)
{
	Link::fn_vRotationGraphic (bRotation);
}
	

void LinkLine::fn_vDrawNormal (void)
{
	MTH3D_tdstVector stFirstVertex, stSecondVertex;
	tdeLocalColor tdColor = GetSuperObject()->GetLocalColor ();

	WP_fnv_WayPoint_ComputeLocation ( (WP_tdhWayPoint)(m_poFirstWP->GetEngineStruct()), &stFirstVertex );
	WP_fnv_WayPoint_ComputeLocation ( (WP_tdhWayPoint)(m_poSecondWP->GetEngineStruct()), &stSecondVertex );

	CPA_SuperObject* psoLine = (CPA_SuperObject*)GetSuperObject()->GetHead();
	
	GLI_tdxValue d=(GLI_tdxValue)(m_xLBeam*0.5);
	GLI_tdxValue md=(GLI_tdxValue)(-m_xLBeam*0.5);
	GLI_tdxValue d2=(GLI_tdxValue)(m_xLBeam*2.);
	GLI_tdxValue md2=(GLI_tdxValue)(-m_xLBeam*2.);
	GLI_tdxValue zero=(GLI_tdxValue)0.;
	MTH3D_tdstVector n, u, v;
	MTH3D_tdstVector Ox = { 1., 0., 0. };

	// Version finale 	
	ACP_tdxHandleOfObject hMot = (ACP_tdxHandleOfObject) HIE_fn_hGetSuperObjectObject(psoLine->GetStruct());

	n = stSecondVertex;
	MTH3D_M_vSubVector(&n,&n,&stFirstVertex);
	GLI_tdxValue lenght = MTH3D_M_xNormVector( &n );

	MTH3D_tdstVector a8_stPoint [8];
	
	MTH3D_M_vSetVectorElements (a8_stPoint, md2,md2,zero);
	MTH3D_M_vSetVectorElements (a8_stPoint+1, d2,md2,zero);
	MTH3D_M_vSetVectorElements (a8_stPoint+2, d2,d2,zero);
	MTH3D_M_vSetVectorElements (a8_stPoint+3, md2,d2,zero);
	MTH3D_M_vSetVectorElements (a8_stPoint+4, md,md,lenght);
	MTH3D_M_vSetVectorElements (a8_stPoint+5, d,md,lenght);
	MTH3D_M_vSetVectorElements (a8_stPoint+6, d,d,lenght);
	MTH3D_M_vSetVectorElements (a8_stPoint+7, md,d,lenght);
	
	GEO_vSetListOfPointsOfObject 
	(
		hMot, 
        a8_stPoint, 
        8, 
        0
	);
	GEO_xComputeObjectNormals ( hMot );

	MTH3D_M_vNormalizeVector(&n,&n);
	
	// here : to rotate the beam around its principal axis
	// by defaults find section align with plan z=0
	if (n.xX||n.xY) { MTH3D_M_vSetVectorElements ((&u),(-n.xY),(n.xX),0.); }
	else { MTH3D_M_vSetVectorElements((&u),0.,(-n.xZ),n.xY); } 
	MTH3D_M_vNormalizeVector(&u,&u);
	MTH3D_M_vCrossProductVector((&v),(&n),(&u));

	// change the local matrix
	GEO_tdxHandleToMatrix hAbsoluteLineMatrix = HIE_fn_hGetSuperObjectGlobalMatrix (psoLine->GetStruct());
	POS_fn_vSetIdentityMatrix( hAbsoluteLineMatrix );
	POS_fn_vSetTranslationVector(  hAbsoluteLineMatrix, &stFirstVertex );
	POS_fn_vSetRotationMatrix( hAbsoluteLineMatrix , &u, &v, &n );
	GetInterface()->fn_vComputeNewRelativeMatrix (psoLine->GetStruct());
}


void LinkLine::fn_vGetSaveInfo ( char dszParam [20][20], long& lNbParam )
{
	strcpy ( dszParam [0], "StaticLine" );
	lNbParam = 2;
}

void LinkLine::fn_vSetWaypoints ( WayPoint* poFirstWP, WayPoint* poSecondWP )
{
	Link::fn_vSetWaypoints ( poFirstWP, poSecondWP );
	
	if (poFirstWP && poSecondWP)
		WP_fnv_Link_ChangeConnectionTypeStaticLineObject ((WP_tdhLink)GetData(), (WP_tdhWayPoint)poFirstWP->GetData(), (WP_tdhWayPoint)poSecondWP->GetData() );
}

*/
//ENDANNECY Shaitan Nettoyage }

