/////////////////////////////////////////////////////////////
// CINEMA 4D SDK                                           //
/////////////////////////////////////////////////////////////
// (c) 1989-2006 MAXON Computer GmbH, all rights reserved  //
/////////////////////////////////////////////////////////////

//---------------------------------------------------
//Spline Helper Class :: Header
//Routines to generate a full set of spline matrices
//incorporating a correct normal
//and accurate spline length to realworld length controls
//---------------------------------------------------
#ifndef _C4D_SPLINEHELP_H_
#define _C4D_SPLINEHELP_H_

#include "c4d.h"

#define C4D_SPLINEHELP_LIBRARY_ID		1019534

class SplineHelp
{
private:
	SplineHelp();
	~SplineHelp();
public:
	// autoalloc
	static SplineHelp *Alloc(void);
	static void				Free(SplineHelp *&node);

	Bool							InitSpline(SplineObject *op, Vector upvector=0.0); //must be called before any other command, optional up-vector
	void							FreeSpline(void); //must be called afterwards to free data
	//-----------------------------------------------------
	//helper routines
	Bool							Exists(void);
	LONG							GetSegmentCount(void);
	Real							GetSplineLength(void);
	Real							GetSegmentLength(LONG segment);
	Matrix						GetVertexMatrix(LONG index);
	Real							GetPointValue(Real offset, LONG segment);
	LONG							GetPointIndex(Real offset, LONG segment);
	Vector						GetPosition(Real offset, LONG segment = 0, Bool smooth = TRUE);
	Vector						GetTangent(Real offset, LONG segment = 0, Bool smooth = TRUE);
	Vector						GetNormal(Real offset, LONG segment = 0, Bool smooth = TRUE);
	Vector						GetCrossNormal(Real offset, LONG segment = 0, Bool smooth = TRUE);
	Real							GetOffsetFromUnit(Real unitoffset, LONG segment = 0);
	Real							GetOffsetFromReal(Real offset, LONG segment = 0);
	Matrix						GetMatrix(Real offset, LONG segment = 0, Bool smooth = TRUE, Bool realoffset = FALSE);
	void							GetLinePointSegment(LONG index, Real *offset, LONG *ind, LONG *segment);
	void							GetSplinePointSegment(LONG index, Real *offset, LONG *ind, LONG *segment);
	void							GlobalToLocal(Real offset, Real *off, LONG *segment, Bool realoffset = FALSE);
	LONG							SplineToLineIndex(LONG index);
};


//---------------------------------------------------
//	---INTERNAL STUFF
class iSplineHelp;

struct SplineHelpLibrary : public C4DLibrary
{
	iSplineHelp*			(*Alloc)();
	void							(*Free)(iSplineHelp *&node);

	Bool							(iSplineHelp::*InitSpline)(SplineObject *op, Vector upvector);
	void							(iSplineHelp::*FreeSpline)();
	Bool							(iSplineHelp::*Exists)();
	LONG							(iSplineHelp::*GetSegmentCount)();
	Real							(iSplineHelp::*GetSplineLength)();
	Real							(iSplineHelp::*GetSegmentLength)(LONG segment);
	Real							(iSplineHelp::*GetPointValue)(Real offset, LONG segment);
	LONG							(iSplineHelp::*GetPointIndex)(Real offset, LONG segment);
	Vector						(iSplineHelp::*GetPosition)(Real offset, LONG segment, Bool smooth);
	Vector						(iSplineHelp::*GetTangent)(Real offset, LONG segment, Bool smooth);
	Vector						(iSplineHelp::*GetNormal)(Real offset, LONG segment, Bool smooth);
	Vector						(iSplineHelp::*GetCrossNormal)(Real offset, LONG segment, Bool smooth);
	Real							(iSplineHelp::*GetOffsetFromUnit)(Real unitoffset, LONG segment);
	Real							(iSplineHelp::*GetOffsetFromReal)(Real offset, LONG segment);
	Matrix						(iSplineHelp::*GetMatrix)(Real offset, LONG segment, Bool smooth, Bool realoffset);
	void							(iSplineHelp::*GetLinePointSegment)(LONG index, Real *offset, LONG *ind, LONG *segment);
	void							(iSplineHelp::*GetSplinePointSegment)(LONG index, Real *offset, LONG *ind, LONG *segment);
	void							(iSplineHelp::*GlobalToLocal)(Real offset, Real *off, LONG *segment, Bool realoffset);
	Matrix						(iSplineHelp::*GetVertexMatrix)(LONG index);
	LONG							(iSplineHelp::*SplineToLineIndex)(LONG index);
};

//	---INTERNAL STUFF
//---------------------------------------------------


#endif
 
 