/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Definition of geometric object structure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#ifndef __GEO_GEOOBJ_H
#define __GEO_GEOOBJ_H
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
   
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
/* 
 * For DLLs who are using this module : 
 */
#undef CPA_EXPORT
#if defined(CPA_WANTS_IMPORT)
 #define CPA_EXPORT __declspec(dllimport)
#elif defined(CPA_WANTS_EXPORT)
 #define CPA_EXPORT __declspec(dllexport)
#else
 #define CPA_EXPORT
#endif
 
 
/* 
 * For Global declaration in C files : 
 */
#ifdef GEO_GLOBALS
 #define __GEO_EXTERN extern
#else /* !GEO_GLOBALS */
 #define __GEO_EXTERN
#endif /* !GEO_GLOBALS */
 
/* struct POS_stCompletePosition;*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
#include "ErrGEO.h"
#include "MmgGEO.h"
#include "color.h"
#include "fmd.h"
#include "element.h"
#include "GeoSprit.h"
#include "POS\PosPubSt.h"
 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
/*
 =======================================================================================
    Constants
 =======================================================================================
 */
 
#define C_IndexedTrianglesObject            0xC0DE0001
 
#define C_lDuplicable                       1
#define C_lMobile                           2
#define C_lMorphable                        4
 
#ifdef U64 /* Julien Merceron */
#define C_lMaxVertexPerObject               1000
#else
 
	#ifdef PACKAGE10
	#define C_lMaxVertexPerObject               1000
	#else /* package 1.1 et supérieur */
	#define C_lMaxVertexPerObject               2500
	#endif
#endif
 
#define GEO_C_lDuplicateVertices            1
#define GEO_C_lDuplicateVerticesNormals     2
#define GEO_C_lDuplicateVerticesColors      4
#define GEO_C_lDuplicateColideInformation   8
#define GEO_C_lDuplicateAll                 0xff
 
/*
 * constant for no element parrallel boxes
 */
#define GEO_C_xNoParallelBox	((ACP_tdxIndex)-1)
 
/*
 * Sprite types
 */
#define GEO_C_NotALookAt      0
#define GEO_C_LookAt          1
#define GEO_C_SemiLookAt      2
 
/*
 =======================================================================================
    Structures
 =======================================================================================
 */
 
/*
 * bounding volume : parrallel box and sphere
 */
typedef struct GEO_tdstParallelBox_
{
    MTH3D_tdstVector  stMinPoint;
    MTH3D_tdstVector  stMaxPoint;
} GEO_tdstParallelBox;
 
typedef GEO_tdstParallelBox *GEO_tdxHandleToParallelBox;
 
 
typedef struct GEO_tdstBoundingSphere_
{
	MTH3D_tdstVector	stCenterPoint;
	MTH_tdxReal			xRadius;
} GEO_tdstBoundingSphere;
 
typedef GEO_tdstBoundingSphere	*GEO_tdxHandleToBoundingSphere;
 
 
/*
 * Geometric object  
 */
typedef struct GEO_tdstGeometricObject_
{
    /*
     * for vertices
     */
    MTH3D_tdstVector                *d_stListOfPoints;
    MTH3D_tdstVector                *d_stListOfPointsNormals;
    GMT_tdxHandleToGameMaterial	    *d_hListOfPointsMaterial;
/*XB980825 (unused in N64)*/
#ifndef U64
    GEO_tdstColor					*d_stListOfPointsReceivedLightIntensity;
#endif /* U64 */
/*End XB*/
 
    /* 
     * Elements
     */
    ACP_tdxIndex                    *d_xListOfElementsTypes;
    void                            **d_stListOfElements;
 
    /* 
     * Octree 
     */
    struct COL_tdstOctree_          *p_stOctree;
 
    /* 
     * EDGES 
     */
#if !defined(PRESS_DEMO) /* swap members to make the engine unusable with the binarized data of another engine */
    GEO_tdstDoubledIndex            *d_stListOfEdges;
    GMT_tdxHandleToGameMaterial     *d_hListOfEdgesMaterial;
#else
    GMT_tdxHandleToGameMaterial     *d_hListOfEdgesMaterial;
    GEO_tdstDoubledIndex            *d_stListOfEdges;
#endif /* PRESS_DEMO */
 
    /* 
     * Bounding volume (for element)
     */
    GEO_tdstParallelBox             *d_stListOfParallelBoxes;
 
    /*
     * type
     */
    unsigned long                   ulType ;
 
 
#if defined(U64)
    float           fScale;
    float           fRadius;
    unsigned short  uwSymType;
    unsigned short  uwRliFlag;
#endif /* U64 */
 
    ACP_tdxIndex                    xNbPoints;
    ACP_tdxIndex                    xNbElements;
    ACP_tdxIndex                    xNbEdges;
    ACP_tdxIndex                    xNbParallelBoxes;
    /*VLNEWGLI*/
    /*
     * object bounding sphere
     */
#if !defined(U64)
    float                           xBoudingSphereRadius;
    MTH3D_tdstVector                xBoudingSphereCenter;
#endif
    /*EVL*/
} GEO_tdstGeometricObject ;
 
 
/*
 =======================================================================================
    Functions
 =======================================================================================
 */
 
extern CPA_EXPORT GEO_tdstGeometricObject *
GEO_xDuplicateVisualObject ( GEO_tdstGeometricObject *p_stObj );
 
extern CPA_EXPORT  void
GEO_xDeleteObject ( GEO_tdstGeometricObject *p_stObj );
 
extern CPA_EXPORT  void
GEO_xComputeNormalWeightedBySurf
                         ( MTH3D_tdstVector *p_stPResult,
                           MTH3D_tdstVector *p_stPA,
                           MTH3D_tdstVector *p_stPB,
                           MTH3D_tdstVector *p_stPC ) ;
 
extern CPA_EXPORT  void
GEO_xCreateObjectPointNormals ( GEO_tdstGeometricObject *p_stObj );
 
extern CPA_EXPORT  void
GEO_xComputeObjectNormals ( GEO_tdstGeometricObject *p_stObj );
 
extern CPA_EXPORT  void
GEO_xComputeObjectNormals2 ( GEO_tdstGeometricObject *p_stObj );
 
extern CPA_EXPORT  void
GEO_xComputeObjectSphereBox ( GEO_tdstGeometricObject *p_stObj );
 
/* ********************************************************************************************/
/* NEW FUNCTIONS STARTS HERE*/
/* ********************************************************************************************/
extern CPA_EXPORT  void
GEO_vCreateTMPGeometricObject ( ACP_tdxHandleOfObject *p_hObject ,
                                ACP_tdxIndex xNbPoints ,
                                ACP_tdxIndex xNbElements );
 
extern CPA_EXPORT  void
GEO_vCreateGeometricObject (    ACP_tdxHandleOfObject *p_hObject ,
                                ACP_tdxIndex xNbPoints ,
                                ACP_tdxIndex xNbElements );
 
extern CPA_EXPORT  ACP_tdxIndex
GEO_xGetGeometricObjectNumberOfPoints ( ACP_tdxHandleOfObject hObject );
 
extern CPA_EXPORT  ACP_tdxIndex
GEO_xGetGeometricObjectNumberOfEdges ( ACP_tdxHandleOfObject hObject );
 
 
extern CPA_EXPORT  void
GEO_vSetPointOfObject ( ACP_tdxHandleOfObject hObject ,
                        MTH3D_tdstVector *p_stPoint ,
                        ACP_tdxIndex xIndexOfPoint);
 
extern CPA_EXPORT  void
GEO_vSetListOfPointsOfObject (  ACP_tdxHandleOfObject hObject ,
                                MTH3D_tdstVector *p_stPoint ,
                                ACP_tdxIndex xNbPoints ,
                                ACP_tdxIndex xIndexOfFirstPoint);
 
extern CPA_EXPORT  void
GEO_vGetPointOfObject ( ACP_tdxHandleOfObject hObject ,
                        MTH3D_tdstVector *p_stPoint ,
                        ACP_tdxIndex xIndexOfPoint);
 
extern CPA_EXPORT  void
GEO_vGetListOfPointsOfObject (  ACP_tdxHandleOfObject hObject ,
                                MTH3D_tdstVector *p_stPoint ,
                                ACP_tdxIndex xNbPoints ,
                                ACP_tdxIndex xIndexOfFirstPoint);
 
extern CPA_EXPORT  void
GEO_vSetPointReceivedLightIntensityOfObject (
                              ACP_tdxHandleOfObject hObject ,
                          GEO_tdstColor *p_stColor ,
                              ACP_tdxIndex xIndexOfPoint);
 
extern CPA_EXPORT  void
GEO_vGetPointReceivedLightIntensityOfObject (
                               ACP_tdxHandleOfObject hObject ,
                               GEO_tdstColor *p_xColor ,
                               ACP_tdxIndex xIndexOfPoint);
 
extern CPA_EXPORT  void
GEO_vSetNormalOfPointOfObject (
                               ACP_tdxHandleOfObject hObject ,
                               MTH3D_tdstVector *p_stNormal ,
                               ACP_tdxIndex xIndexOfPoint);
 
extern CPA_EXPORT  void
GEO_vGetNormalOfPointOfObject (
                               ACP_tdxHandleOfObject hObject ,
                               MTH3D_tdstVector *p_stNormal ,
                               ACP_tdxIndex xIndexOfPoint);
 
extern CPA_EXPORT  void
GEO_xCreateObjectListOfEdges ( GEO_tdstGeometricObject *p_stObj );
 
extern CPA_EXPORT  void
GEO_xComputeObjectListOfEdges ( GEO_tdstGeometricObject *p_stObj );
 
extern CPA_EXPORT  long
GEO_lGetGeometricObjectNumberOfElements ( ACP_tdxHandleOfObject hObject );
 
extern CPA_EXPORT  void
GEO_vResetGeometricObjectElements ( ACP_tdxHandleOfObject hObject ,
                                    ACP_tdxHandleOfElement hElement );
 
extern CPA_EXPORT  ACP_tdxHandleOfObject
GEO_xDuplicateGeometricObject( ACP_tdxHandleOfObject hObject ,
                                ACP_tdxIndex xNewNumberOfElement);
 
extern CPA_EXPORT  ACP_tdxIndex
GEO_xGetElementType
(
     ACP_tdxHandleOfObject hObject ,
     ACP_tdxIndex xElement
);
 
extern CPA_EXPORT  ACP_tdxIndex
GEO_xGetGeometricObjectNumberOfElements
(
     ACP_tdxHandleOfObject hObject
);
 
extern CPA_EXPORT  ACP_tdxIndex
GEO_xGetGeometricObjectNumberOfElementsMax
(
     ACP_tdxHandleOfObject hObject
);
 
extern CPA_EXPORT  void
GEO_xDuplicateGeometricObjectCommonData ( ACP_tdxHandleOfObject hObject1 ,
                                          ACP_tdxHandleOfObject hObject2 ,
                                          long lWhatIsDuplicate );
 
extern CPA_EXPORT  long
GEO_bDuplicateGeometricObjectElement ( ACP_tdxHandleOfObject hObject1 ,
                                       ACP_tdxHandleOfObject hObject2 ,
                                       ACP_tdxHandleOfElement hElement ,
									   ACP_tdxHandleOfElement *p_xElementCounter);
 
extern CPA_EXPORT  long
GEO_bCopyingGeometricObjectElement
(
	ACP_tdxHandleOfObject hObject1 ,
	ACP_tdxHandleOfObject hObject2 ,
	ACP_tdxIndex xElementNumberInFirstObject  ,
	ACP_tdxIndex *p_xNewElementNumberInSecondObject
);
 
extern CPA_EXPORT void
GEO_vCreateObjectListOfPointsMaterial
(
        ACP_tdxHandleOfObject hObject
);
 
extern CPA_EXPORT void
GEO_vComputeObjectListOfPointsMaterial
(
        ACP_tdxHandleOfObject hObject
);
 
extern CPA_EXPORT void
GEO_vEndModifyObject(ACP_tdxHandleOfObject hObject);
 
extern CPA_EXPORT void
GEO_vEndCreateObject(ACP_tdxHandleOfObject hObject);
 
extern CPA_EXPORT void
GEO_vEndModifyObject2(ACP_tdxHandleOfObject hObject);
 
extern CPA_EXPORT void
GEO_vEndModifyGoThroughObject(ACP_tdxHandleOfObject hObject);
 
extern CPA_EXPORT void
GEO_vEndModifyObjectWithoutComputingNormal (ACP_tdxHandleOfObject hObject);
 
extern CPA_EXPORT void
GEO_vGetNormalOfGeometricObjectElement
(
        ACP_tdxHandleOfObject hObject,
        ACP_tdxIndex xElementIndex,
        ACP_tdxIndex xDataElementIndex,
        MTH3D_tdstVector *p_stNormal
);
 
extern CPA_EXPORT ACP_tdxHandleOfMaterial
GEO_hGetMaterialOfGeometricObjectElement ( ACP_tdxHandleOfObject hObject,
                                           ACP_tdxIndex xElementIndex,
                                           ACP_tdxIndex xDataElementIndex );
 
extern CPA_EXPORT GMT_tdxHandleToGameMaterial
GEO_fn_hGetGameMaterialOfGeometricObjectElement ( ACP_tdxHandleOfObject hObject,
                                              ACP_tdxIndex xElementIndex,
                                              ACP_tdxIndex xDataElementIndex );
 
 
extern CPA_EXPORT ACP_tdxBool GEO_bEdgePartOfEdge ( ACP_tdxIndex xEdge1,
                                  ACP_tdxIndex xEdge2,
                                  ACP_tdxIndex xPoint1,
                                  ACP_tdxIndex xPoint2 );
 
extern CPA_EXPORT void
GEO_vSetEdgeMaterial
(
        ACP_tdxHandleOfObject hObject,
        ACP_tdxIndex xPoint1,
        ACP_tdxIndex xPoint2,
        GMT_tdxHandleToGameMaterial hMaterial
);
 
extern CPA_EXPORT void
GEO_vComputeElementMaterial
(
        ACP_tdxHandleOfObject hObject,
        ACP_tdxIndex xElementIndex,
        ACP_tdxIndex xDataElementIndex
);
 
extern CPA_EXPORT void
GEO_vDeleteGeometricObject (    ACP_tdxHandleOfObject *p_hObj );
 
 
/* fbolefeysot - 01/10/98*/
/* remove init values in GMT{*/
/*extern CPA_EXPORT void
GEO_vRecursiveReinitGamesMaterials (    ACP_tdxHandleOfObject *p_hObj );
*/
/*END fbolefeysot}*/
 
extern CPA_EXPORT ACP_tdxHandleOfObject GEO_fn_hTransformTableOfObjectInOneObjectForGAM(
   ACP_tdxHandleOfObject _hGeoObj,
   ACP_tdxHandleOfObject * a_hTableOfGeoObj,
   ACP_tdxIndex xNbOfgEOoBJ);
 
extern CPA_EXPORT void GEO_fn_vClearObjectForGAM(ACP_tdxHandleOfObject _hGeoObj);
 
extern CPA_EXPORT void GEO_fn_vMoveFaceToFaceDescriptors( ACP_tdxHandleOfObject p_stObj, ACP_tdxIndex xElementIT, ACP_tdxIndex xFaceIT, ACP_tdxIndex *p_xElementFMD, ACP_tdxIndex *p_xFaceFMD);
extern CPA_EXPORT void GEO_fn_vMoveFaceDescriptorsToFace( ACP_tdxHandleOfObject p_stObj, ACP_tdxIndex xElementFMD, ACP_tdxIndex xFaceFMD, ACP_tdxIndex xElementIT, ACP_tdxIndex xFaceIT);
 
/*ANNECY CT 02/02/98{*/
extern CPA_EXPORT void GEO_vGetFaceSurfaceSpeed(
	ACP_tdxHandleOfObject hObject,
	ACP_tdxIndex xElement,
	ACP_tdxIndex xFace,
	MTH3D_tdstVector * p_vSpeed);
/*ENDANNECY CT}*/
 
 
extern CPA_EXPORT void
GEO_vCreateObjectListOfParallelBox
(
        ACP_tdxHandleOfObject hObject,
		ACP_tdxIndex xNumberOfParallelBoxes
);
 
extern CPA_EXPORT void
GEO_vComputeObjectListOfParallelBox
(
        ACP_tdxHandleOfObject hObject
);
 
extern CPA_EXPORT  ACP_tdxIndex
GEO_xGetGeometricObjectNumberOfParallelBox
(
     ACP_tdxHandleOfObject hObject
);
 
extern CPA_EXPORT GEO_tdxHandleToParallelBox
GEO_hGetParallelBox
(
     ACP_tdxHandleOfObject hObject,
	 ACP_tdxIndex xParallelBox
);
 
extern CPA_EXPORT ACP_tdxIndex
GEO_xGetParallelBoxIndexOfElement
(
	ACP_tdxHandleOfObject hObject,
	ACP_tdxIndex xIndexOfElement
);
 
extern CPA_EXPORT void
GEO_vSetParallelBoxIndexOfElement
(
	ACP_tdxHandleOfObject hObject,
	ACP_tdxIndex xIndexOfElement,
	ACP_tdxIndex xIndexOfParallelBox
);
 
 
 
/*JMD*/
extern CPA_EXPORT void GEO_vTurnLookAt ( GEO_tdstGeometricObject *p_stObj, 
                                         GLD_tdxHandleToViewportAttributes hVpt, 
                                         struct POS_stCompletePosition * p_stCurrentMatrix) ;
extern CPA_EXPORT ACP_tdxBool GEO_bIsLookAt (GEO_tdstGeometricObject *p_stObj) ;
/*JMD*/
 
/*
-----------------------------------------------------------------------------
PRIVATE FUNCTIONS DECLARATION:
Ex :
extern void MODULETAG_fn_vMyPrivateFunction(void);
Note : Private functions MUST appear ONLY in PRIVATE HEADER files (.h) in
your Src directory with source files (.c)
-----------------------------------------------------------------------------
*/
 
/* ANNECY MT 20/02/98 {*/
void
GEO_vComputeObjectParallelBox
(
     ACP_tdxHandleOfObject hObject,
	 ACP_tdxIndex xParallelBox
);
/*ENDANNECY MT }*/
 
#ifdef __cplusplus
};
#endif /* __cplusplus */
 
 
#endif /* __GEO_GEOOBJ_H  */
 
