148 lines
4.3 KiB
C
148 lines
4.3 KiB
C
/* Toy Fonction for Game moteur*/
|
|
/*
|
|
#include "ACP_Base.h"
|
|
#include "ToolsCPA.h"
|
|
#include "CPALib.h"
|
|
|
|
#include "ColMotor.h"
|
|
#include "Structur/MemGame.h"
|
|
|
|
#include "GameEng.h"
|
|
#include "ZeMem.h"
|
|
|
|
//a few define
|
|
#define COL_C_NbMaxObjectInCollision 11
|
|
|
|
#define COL_C_InSphere 0
|
|
#define COL_C_OutSphere 1
|
|
#define COL_C_InContact 2
|
|
|
|
//local prototypes
|
|
//char COL_xCollideSphere(HIE_tdxHandleToSuperObject COL_p_stSO1,HIE_tdxHandleToSuperObject COL_p_stSO2);
|
|
long fn_lObjectCollideWithCamera
|
|
(
|
|
HIE_tdxHandleToSuperObject COL_p_stTreeToExplore,
|
|
HIE_tdxHandleToSuperObject COL_p_stCameraToCollide,
|
|
long COL_lTypeToSearch,
|
|
HIE_tdxHandleToSuperObject *COL_d_stArrayOfSOInCollision,
|
|
long COL_lPositionOfStart,
|
|
long COL_lPositionMax
|
|
);
|
|
|
|
|
|
// function COL_xCollideSphere()
|
|
/* This function indicates if SO2 is in,out or in contact with SO1. The test of collision uses
|
|
the sphereBox.*/
|
|
/*char COL_xCollideSphere(HIE_tdxHandleToSuperObject COL_p_stSO1,HIE_tdxHandleToSuperObject COL_p_stSO2)
|
|
{
|
|
MTH3D_tdstVector COL_stCenter1,COL_stCenter2; // The center of each SphereBox in absolue
|
|
MTH_tdxReal COL_xDistanceBetweenCenter; // Distance between the centers
|
|
|
|
//compute the coordinate of the center of SO1
|
|
POS_fn_vGetTranslationVector(HIE_fn_hGetSuperObjectMatrix(COL_p_stSO1),&COL_stCenter1 );
|
|
MTH3D_M_vAddVector(&COL_stCenter1,&COL_stCenter1,&(HIE_fn_hGetSuperObjectSphere(COL_p_stSO1)->stCentre));
|
|
|
|
//compute the coordinate of the center of SO2
|
|
POS_fn_vGetTranslationVector(HIE_fn_hGetSuperObjectMatrix(COL_p_stSO2),&COL_stCenter2);
|
|
MTH3D_M_vAddVector(&COL_stCenter2,&COL_stCenter2,&(HIE_fn_hGetSuperObjectSphere(COL_p_stSO2)->stCentre));
|
|
|
|
//calculate the distance between the centers
|
|
MTH3D_M_vSubVector(&COL_stCenter1,&COL_stCenter1,&COL_stCenter2); // take the vector
|
|
COL_xDistanceBetweenCenter=MTH3D_M_xNormVector(&COL_stCenter1);
|
|
|
|
// determine the output
|
|
if
|
|
(
|
|
COL_xDistanceBetweenCenter
|
|
<
|
|
MTH_M_xSub(HIE_fn_hGetSuperObjectSphere(COL_p_stSO1)->xRadius,HIE_fn_hGetSuperObjectSphere(COL_p_stSO2)->xRadius)
|
|
)
|
|
return COL_C_InSphere; //SO2 in SO1
|
|
|
|
if
|
|
(
|
|
COL_xDistanceBetweenCenter
|
|
<
|
|
MTH_M_xAdd(HIE_fn_hGetSuperObjectSphere(COL_p_stSO1)->xRadius,HIE_fn_hGetSuperObjectSphere(COL_p_stSO2)->xRadius)
|
|
)
|
|
return COL_C_InContact; // SO2 in contact with SO1
|
|
|
|
return COL_C_OutSphere; // no contact
|
|
}
|
|
// end of COL_xCollideSphere
|
|
|
|
// version temp with exploration of the tree
|
|
// function fn_lObjectCollideWithCamera()
|
|
long fn_lObjectCollideWithCamera
|
|
(
|
|
HIE_tdxHandleToSuperObject COL_p_stTreeToExplore,
|
|
HIE_tdxHandleToSuperObject COL_p_stCameraToCollide,
|
|
long COL_lTypeToSearch,
|
|
HIE_tdxHandleToSuperObject *COL_d_stArrayOfSOInCollision,
|
|
long COL_lPositionOfStart,
|
|
long COL_lPositionMax
|
|
)
|
|
{
|
|
long COL_lCounterCollision,COL_lI;
|
|
HIE_tdxHandleToSuperObject COL_p_stpChild;
|
|
|
|
COL_lCounterCollision=COL_lPositionOfStart;
|
|
|
|
if(COL_lCounterCollision<COL_lPositionMax-1)
|
|
{
|
|
HIE_M_ForEachChildOf(COL_p_stTreeToExplore,COL_p_stpChild,COL_lI)
|
|
COL_lCounterCollision=
|
|
fn_lObjectCollideWithCamera(
|
|
COL_p_stpChild,
|
|
COL_p_stCameraToCollide,
|
|
COL_lTypeToSearch,
|
|
COL_d_stArrayOfSOInCollision,
|
|
COL_lCounterCollision,
|
|
COL_C_NbMaxObjectInCollision
|
|
);
|
|
|
|
if(HIE_fn_lGetSuperObjectType(COL_p_stTreeToExplore)==COL_lTypeToSearch)
|
|
if(COL_xCollideSphere(COL_p_stTreeToExplore,COL_p_stCameraToCollide)!=COL_C_OutSphere)
|
|
{
|
|
COL_d_stArrayOfSOInCollision[COL_lCounterCollision]=COL_p_stTreeToExplore;
|
|
COL_lCounterCollision++;
|
|
}
|
|
}
|
|
|
|
return COL_lCounterCollision;
|
|
}
|
|
// End of fn_lObjectCollideWithCamera()
|
|
|
|
|
|
|
|
//Warning the followed function is temp
|
|
// function fn_lObjectActivateByCamera()
|
|
long fn_lObjectActivateByCamera
|
|
(
|
|
HIE_tdxHandleToSuperObject COL_p_stCameraToCollide,
|
|
long COL_lTypeToSearch,
|
|
HIE_tdxHandleToSuperObject **COL_d_stArrayOfSOInCollision
|
|
)
|
|
{
|
|
long COL_lCounterCollision;
|
|
|
|
*COL_d_stArrayOfSOInCollision=
|
|
(HIE_tdxHandleToSuperObject *)M_p_GameMalloc(E_ucGameSuperObjectMemory,sizeof(HIE_tdxHandleToSuperObject)*COL_C_NbMaxObjectInCollision); // version temp
|
|
|
|
COL_lCounterCollision=
|
|
fn_lObjectCollideWithCamera(
|
|
gp_stActualWorld,
|
|
COL_p_stCameraToCollide,
|
|
COL_lTypeToSearch,
|
|
*COL_d_stArrayOfSOInCollision,
|
|
0,
|
|
COL_C_NbMaxObjectInCollision
|
|
);
|
|
|
|
(*COL_d_stArrayOfSOInCollision)[COL_lCounterCollision]=NULL;
|
|
|
|
return COL_lCounterCollision;
|
|
}
|
|
// End of fn_lObjectActivateByCamera()
|
|
*/
|