/*=========================================================================================
File:			CirclWay.c
Prupose:		Handle a CircleArc curve
Author:			Yann Le Tensorer
Creation Date:	3 february 1997
Version:		1.1
Revision:		
===========================================================================================
Revisions:		Version		Date				Author
                ----------------------------------------------------------------
				1.1			6 february 1997		Yann Le Tensorer
							Added function "fn_vCircle_FindCenter"
=========================================================================================*/

#ifndef __CircleArc_H__
#define __CircleArc_H__


#ifdef _AI_LIB_
#include "AIUseCPA.h"
#include "dynamic.h"
#else /* _AI_LIB_ */
#include "mth3d.h"
#include "acp_base.h"
#include "gld.h"
#include "dynamic.h"
#endif /* _AI_LIB_ */

/* Object creation modes */
#define C_ucModeNoObject	0								/* no geometric object created */ 
#define C_ucModeRealObject	1								/* a geometric object is created */


/* Main CircleArc structure */
typedef struct _CircleArcObject
{
	unsigned char 				ucSamplingRate;				/* sampling rate of curve */
	MTH3D_tdstVector			stStartPoint;				/* first point of curve */
	MTH3D_tdstVector			stEndPoint;					/* last point of curve */
	MTH3D_tdstVector			stCenter;					/* center of the circle */
	MTH3D_tdstMatrix			stLocalRepere;				/* local repère of plan in which is the circle */
	ACP_tdxHandleOfObject		hObject;					/* handle of géométric object*/
	ACP_tdxHandleOfElement		hElement;					/* handle of "line" element*/
	long						color;						/* color of the curve (24 bits)*/
	GLD_tdstViewportAttributes	*p_ViewPortAttributes;		/* pointeur sur les attributs du viewport*/
	unsigned char				ucObjectMode;				/* object mode C_ucModeNoObject or C_ucModeRealObject*/
	MTH3D_tdstVector			*d_stListOfPoints;			/* List of CircleArc Points, in case mode=C_ucModeNoObject*/
	ACP_tdstDynaParam			*p_stDynaParams;			/* Pointer to dynamic parameters of curve */
	MTH3D_tdstVector			stLocalStartPoint;			/* first point of curve in local repere*/
	MTH3D_tdstVector			stLocalEndPoint;			/* last point of curve in local repere*/
	MTH3D_tdstMatrix			stInvLocalRepere;			/* Inverse matrix of local repère of plan in which is the circle */
	MTH_tdxReal					xMainAngle;
	MTH3D_tdstVector			stTmpVector0;				/* internal use */				
	MTH3D_tdstVector			stTmpVector1;				/* internal use */				

} tdstCircleArcObject;

#ifdef __cplusplus
extern "C" {
#endif

/*==========================================================
Function name:	fn_vCircleArcObject_Calculate
Description:	Calculates the points of the bézier curve according to the 
				parameters specified when creating the object.
Input:			p_CircleArcObject:	Pointer to a pre-created CircleArc object
Output:			none
Author:			Yann Le Tensorer
Date:			23 january 1997
Revision:
==========================================================*/
void fn_vCircleArcObject_Calculate(tdstCircleArcObject *p_CircleArcObject);

/*==========================================================
Function name:	fn_vCircleArcObject_Create
Description:	Create CircleArc curve (in ram only) between two points
Input:			p_CircleArcObject:	pointer to a preallocated tdstCircleArcObject
				ucSamplingRate:	number of segment to define the curve) 
				stStartPoint:	First vertex of the curve
				stEndPoint:		Last vertex of the curve
				stCenter:		center of the circle
				ucObjectMode:	Creation mode (C_ucModeNoObject ou C_ucModeRealObject)
								C_ucModeNoObject does not create a geometric object 
								whereas C_ucModeRealObject does.
Output:			none
Author:			Yann Le Tensorer
Date:			23 january 1997
Revision:		YLT - 03 february 1997
==========================================================*/
void fn_vCircleArcObject_Create(tdstCircleArcObject	*p_CircleArcObject,
								unsigned char		ucSamplingRate,		
								MTH3D_tdstVector*	p_stStartPoint,
								MTH3D_tdstVector*	p_stEndPoint,
								MTH3D_tdstVector*	p_stCenter,
								unsigned char		ucObjectMode,
								ACP_tdstDynaParam*	p_stDynaParams);

/*==========================================================
Function name:	fn_vCircleArcObject_SetColor
Description:	Set the color of a CircleArc object.
Input:			p_CircleArcObject:	pointer to a pre-created tdstCircleArcObject
				color:			24 bit color of object. (0->7=B;  8->15=G; 16->23=R ; 24->32=Unused) 
Output:			none
Author:			Yann Le Tensorer
Date:			24 january 1997
Revision:
==========================================================*/
void fn_vCircleArcObject_SetColor(tdstCircleArcObject *p_CircleArcObject,long color);


/*==========================================================
Function name:	fn_vCircleArcObject_SetViewPortAttributes
Description:	Set the viewportattributes for drawing.
Input:			p_CircleArcObject:			pointer to a pre-created tdstCircleArcObject
				p_ViewPortAttributes:	pointer to  pre-defined viewport attributes
Output:			none
Author:			Yann Le Tensorer
Date:			24 january 1997
Revision:
==========================================================*/
void fn_vCircleArcObject_SetViewPortAttributes(tdstCircleArcObject *p_CircleArcObject,GLD_tdstViewportAttributes *p_ViewPortAttributes);

/*==========================================================
Function name:	fn_vCircleArcObject_Draw
Description:	Draw CircleArc object on screen
Input:			p_CircleArcObject:	pointer to a pre-created tdstCircleArcObject
Output:			none
Author:			Yann Le Tensorer
Date:			24 january 1997
Revision:
==========================================================*/
void fn_vCircleArcObject_Draw(tdstCircleArcObject *p_CircleArcObject);

/*==========================================================
Function name:	fn_vCircleArcObject_Free
Description:	Free memory allocated by the CircleArc objet
Input:			p_CircleArcObject:	pointer to a tdstCircleArcObject
Output:			none
Author:			Yann Le Tensorer
Date:			29 january 1997
Revision:
==========================================================*/
void fn_vCircleArcObject_Free(tdstCircleArcObject	*p_CircleArcObject);


/*==========================================================
Function name:	fn_vCircleArcObject_ChangeParams
Description:	Changes the parameters of a CircleArc objet and recalculates the coordinates
				of the points.
Input:			p_CircleArcObject:	Pointer to a pre-created CircleArc object
				p_stStartPoint:		Pointer to the start point 
				p_stEndPoint:		Pointer to the end Point	
				p_stCenter:			Pointer to the center of the circle
Output:			none
Author:			Yann Le Tensorer
Date:			6 february 1997
Revision:

Notes:			If an input parameter is 0, this parameter is simply not
				affected. This enables to change easily only one parameter
==========================================================*/
void fn_vCircleArcObject_ChangeParams(tdstCircleArcObject	*p_CircleArcObject,
									  MTH3D_tdstVector		*p_stStartPoint,
									  MTH3D_tdstVector		*p_stEndPoint,
									  MTH3D_tdstVector		*p_stCenter);

/*==========================================================
Function name:	fn_xCircleArcObject_GetSpeed
Description:	returns the speed at a given sample (n° of the point) of a CircleArc object
Input:			p_stDynaParam:	pointer to a pre-created tdstDynaParam structure
				ucSampleNo:		n° of the point to get the speed from.
Output:			return value is the speed.
Author:			Yann Le Tensorer
Date:			03 february 1997
Revision:
==========================================================*/
MTH_tdxReal fn_xCircleArcObject_GetSpeed(tdstCircleArcObject	*p_CircleArcObject,unsigned char ucSampleNo);

/*==========================================================
Function name:	fn_xCircleArcObject_GetPoint
Description:	returns the coordinates in the global repère of the point at a 
				given sample (n° of the point) of a CircleArc object.
Input:			p_stDynaParam:	pointer to a pre-created tdstDynaParam structure
				ucSampleNo:		n° of the point to get the coordinates from.
				p_ReturnVector: pointer to a vector to be returned.
Output:			*p_ReturnVector is a vector countaining the.coordinates of the point.
Author:			Yann Le Tensorer
Date:			03 february 1997
Revision:
==========================================================*/
void fn_vCircleArcObject_GetPoint(tdstCircleArcObject	*p_CircleArcObject,unsigned char ucSampleNo,MTH3D_tdstVector* p_ReturnVector);


/*==========================================================
Function name:	fn_vCircleArcObject_GlobalToLocal
Description:	Changes coordinates of a point from global coordinates to local.
Input:			p_CircleArcObject:	pointer to the circle arc object
				p_stDestVector:		pointer to the destination vector
				p_stSourceVector:	pointer to the source vector
Output:			*p_stDestVector is a vector countaining the.coordinates in the local
				repere of the plan.
Author:			Yann Le Tensorer
Date:			4 february 1997
Revision:
==========================================================*/
void fn_vCircleArcObject_GlobalToLocal(	tdstCircleArcObject	*p_CircleArcObject,
										MTH3D_tdstVector	*p_stDestVector,
										MTH3D_tdstVector	*p_stSourceVector);

/*==========================================================
Function name:	fn_vCircleArcObject_LocalToGlobal
Description:	Changes coordinates of a point from local coordinates to global
Input:			p_CircleArcObject:	pointer to the circle arc object
				p_stDestVector:		pointer to the destination vector
				p_stSourceVector:	pointer to the source vector
Output:			*p_stDestVector is a vector countaining the.coordinates in the global
				repere of the plan.
Author:			Yann Le Tensorer
Date:			4 february 1997
Revision:
==========================================================*/
void fn_vCircleArcObject_LocalToGlobal(	tdstCircleArcObject	*p_CircleArcObject,
										MTH3D_tdstVector	*p_stDestVector,
										MTH3D_tdstVector	*p_stSourceVector);

/*==========================================================
Function name:	fn_ucCircleArcObject_GetSamplingRate
Description:	Gets the sampling rate of a CircleArcObject objet
Input:			p_CircleArcObject:	Pointer to a pre-created CircleArc object
Output:			return value is the sampling rate of the circle arc object
Author:			Yann Le Tensorer
Date:			5 february 1997
Revision:
==========================================================*/
unsigned char fn_ucCircleArcObject_GetSamplingRate(tdstCircleArcObject	*p_CircleArcObject);

/*===============================================================================
Function name:	fn_bCircleArcObject_SetSamplingRate
Description:	Modifies the sampling rate of a CircleArc object, and changes all
				the depending parameters (including dynamic sampling rate)
Input:			p_CircleArcObject:	pointer to a preallocated tdstCircleArcObject
				ucSamplingRate:	New sampling rate
Output:			return value is true if sampling rate could be modified,
				false if not.
Author:			Yann Le Tensorer
Date:			5 february 1997
Revision:		
Note:			The sampling rate can only be modified for objects that have been
				created using C_ucModeNoObject at their creation.
================================================================================*/
ACP_tdxBool fn_bCircleArcObject_SetSamplingRate(tdstCircleArcObject	*p_CircleArcObject,
											 unsigned char		ucSamplingRate);
/*==========================================================
Function name:	fn_vCircle_FindCenter
Description:	Finds the 3D coordinate of the center of the circle on which are 3 points.
Input:			p_FirstPoint:	pointer to the first point
				p_SecondPoint:	pointer to the second point
				p_ThirdPoint:	pointer to the third point
				p_ReturnCenter: pointer to a point to be returned.
Output:			*p_ReturnCenter is a vector countaining the.coordinates of the center.
Author:			Yann Le Tensorer
Date:			6 february 1997
Revision:
==========================================================*/
void fn_vCircle_FindCenter(	MTH3D_tdstVector *p_FirstPoint,
							MTH3D_tdstVector *p_SecondPoint,
							MTH3D_tdstVector *p_ThirdPoint,
							MTH3D_tdstVector *p_ReturnCenter);


#ifdef __cplusplus
}
#endif

#endif

