797 lines
29 KiB
C
797 lines
29 KiB
C
#include <assert.h> /* for "assert" : to be removed */
|
|
#include "cpa_std.h" /* for "memcpy" and NULL : to be removed */
|
|
|
|
#include "acp_base.h"
|
|
|
|
#include "MTH.h"
|
|
#include "POS.h"
|
|
#include "GEO.h"
|
|
#include "GMT.h"
|
|
#include "MEC.h"
|
|
#include "GLI.h"
|
|
|
|
/*--------------------------------------------------------------------------------------*/
|
|
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
|
|
GMT_tdxHandleToGameMaterial gs_hMaterial=NULL;
|
|
#endif /* _FIRE_DEADCODE_U64 */ /* Added by RUC */
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* We will need a default game material to draw the structures that are defined*/
|
|
/* in this file*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
|
|
void GEO_fn_vInitBoundingVolumeMaterial
|
|
(
|
|
void
|
|
)
|
|
{
|
|
gs_hMaterial = GMT_fn_hCreateGameMaterial();
|
|
}
|
|
#endif /* _FIRE_DEADCODE_U64 */ /* Added by RUC */
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create a box that include a geometric object*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
|
|
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
|
|
void GEO_fn_vAddObjectToBox
|
|
(
|
|
ACP_tdxHandleOfObject _hGeometricObject,
|
|
struct POS_stCompletePosition *_p_stGlobalMatrix,
|
|
MTH3D_tdstVector *_p_stMax,
|
|
MTH3D_tdstVector *_p_stMin
|
|
)
|
|
{
|
|
MTH3D_tdstVector* p_stVertex;
|
|
MTH3D_tdstVector stVertex;
|
|
long i;
|
|
|
|
assert(_hGeometricObject != NULL);
|
|
|
|
#ifdef USE_ALTIMAPS
|
|
/*--- We need to know if it is an Altimap or not ---*/
|
|
if( _hGeometricObject->d_xListOfElementsTypes[0] == GEO_C_xElementAltimap )
|
|
{
|
|
/*--- It is an Altimap ! ---*/
|
|
MTH3D_tdstVector stVRef[3], stOrig;
|
|
MTH3D_tdstVector aDEF_stVertex[ C_lMaxVertexPerObject ];
|
|
MTH3D_tdstVector * p_stAVectCurr, * p_stAVectNext, * p_stEndLoop;
|
|
MTH3D_tdstVector stAVRef[3];
|
|
ACP_tdxIndex cWidth, cDepth, xNbAltimapVertex;
|
|
MTH_tdxReal * p_xHeight;
|
|
GEO_tdstElementAltimap * p_stLocalElementAltimap;
|
|
|
|
p_stLocalElementAltimap = (GEO_tdstElementAltimap *) _hGeometricObject->d_stListOfElements[ 0 ];
|
|
|
|
/*--- Seeting some Geo Obj attributes for further computations ---*/
|
|
xNbAltimapVertex = (p_stLocalElementAltimap->xWidth + 1) * (p_stLocalElementAltimap->xDepth + 1);
|
|
_hGeometricObject->xNbPoints = xNbAltimapVertex;
|
|
|
|
/*--- We need to get the origin without its height ---*/
|
|
stOrig = p_stLocalElementAltimap->stOrigin;
|
|
stOrig.xZ = MTH_C_ZERO;
|
|
|
|
/*--- Projection of the Origin point ---*/
|
|
MTH3D_M_vMulMatrixVector ( aDEF_stVertex, &_p_stGlobalMatrix->stTransformMatrix, &stOrig );
|
|
|
|
/*--- Projection of Dx and Dy vectors and Unary Dz Vector ---*/
|
|
MTH3D_M_vSetVectorElements( (stVRef ), MTH_C_ONE, MTH_C_ZERO, MTH_C_ZERO );
|
|
MTH3D_M_vSetVectorElements( (stVRef + 1), MTH_C_ZERO, MTH_C_ONE, MTH_C_ZERO );
|
|
MTH3D_M_vSetVectorElements( (stVRef + 2), MTH_C_ZERO, MTH_C_ZERO, MTH_C_ONE );
|
|
|
|
MTH3D_M_vMulMatrixVector ( (stAVRef ), &_p_stGlobalMatrix->stTransformMatrix, (stVRef ) );
|
|
MTH3D_M_vMulMatrixVector ( (stAVRef + 1), &_p_stGlobalMatrix->stTransformMatrix, (stVRef + 1) );
|
|
MTH3D_M_vMulMatrixVector ( (stAVRef + 2), &_p_stGlobalMatrix->stTransformMatrix, (stVRef + 2) );
|
|
|
|
MTH3D_M_vMulScalarVector( (stAVRef ), p_stLocalElementAltimap->xDeltaX, (stAVRef ) );
|
|
MTH3D_M_vMulScalarVector( (stAVRef + 1), p_stLocalElementAltimap->xDeltaY, (stAVRef + 1) );
|
|
|
|
/*--- Loops initialisations ---*/
|
|
p_stAVectCurr = p_stAVectNext = aDEF_stVertex;
|
|
xNbAltimapVertex = (p_stLocalElementAltimap->xWidth + 1) * (p_stLocalElementAltimap->xDepth + 1);
|
|
p_xHeight = p_stLocalElementAltimap->d_xHeight;
|
|
|
|
/*--- Filling the array along X and Y. Heights are calculated further ---*/
|
|
for( cDepth = 0 ; cDepth < p_stLocalElementAltimap->xDepth + 1 ; cDepth ++ )
|
|
{
|
|
if( cDepth > 0 )
|
|
{
|
|
p_stAVectNext ++;
|
|
MTH3D_M_vAddVector( p_stAVectNext, (stAVRef + 1), p_stAVectCurr ); /*--- p(0,y+1) = p(0,y) + dy*/
|
|
}
|
|
p_stAVectCurr = p_stAVectNext; /*--- We save the 1st point of current line*/
|
|
for( cWidth = 1 ; cWidth < p_stLocalElementAltimap->xWidth + 1 ; cWidth ++ )
|
|
{
|
|
MTH3D_M_vAddVector( p_stAVectNext + 1, stAVRef, p_stAVectNext );
|
|
p_stAVectNext++;
|
|
}
|
|
}
|
|
|
|
/*--- Adding the Height projection ---*/
|
|
p_stAVectCurr = aDEF_stVertex;
|
|
p_stEndLoop = p_stAVectCurr + xNbAltimapVertex;
|
|
for( ; p_stAVectCurr < p_stEndLoop ; p_xHeight ++, p_stAVectCurr ++ )
|
|
{
|
|
MTH3D_M_vMulAddVector( p_stAVectCurr,
|
|
*p_xHeight,
|
|
(stAVRef + 2),
|
|
p_stAVectCurr );
|
|
}
|
|
|
|
/*--- Computation of the Bounding Parallel box ---*/
|
|
/*--- All the vertices have been projected ---*/
|
|
p_stVertex = aDEF_stVertex;
|
|
|
|
for (i=0; i<_hGeometricObject->xNbPoints; i++,p_stVertex++)
|
|
{
|
|
if (MTH_M_bLess(p_stVertex->xX, _p_stMin->xX))
|
|
_p_stMin->xX = p_stVertex->xX;
|
|
if(MTH_M_bGreater(p_stVertex->xX, _p_stMax->xX))
|
|
_p_stMax->xX = p_stVertex->xX;
|
|
if (MTH_M_bLess(p_stVertex->xY, _p_stMin->xY))
|
|
_p_stMin->xY = p_stVertex->xY;
|
|
if(MTH_M_bGreater(p_stVertex->xY, _p_stMax->xY))
|
|
_p_stMax->xY = p_stVertex->xY;
|
|
if (MTH_M_bLess(p_stVertex->xZ, _p_stMin->xZ))
|
|
_p_stMin->xZ = p_stVertex->xZ;
|
|
if(MTH_M_bGreater(p_stVertex->xZ, _p_stMax->xZ))
|
|
_p_stMax->xZ = p_stVertex->xZ;
|
|
}
|
|
}
|
|
else
|
|
#endif /*USE_ALTIMAPS*/
|
|
{
|
|
long lElementCounter;
|
|
|
|
/*--- It is NOT an Altimap ! ---*/
|
|
p_stVertex = _hGeometricObject->d_stListOfPoints;
|
|
|
|
for (i=0; i<_hGeometricObject->xNbPoints; i++,p_stVertex++)
|
|
{
|
|
/* The point must be computed in the global world, not in the local one...*/
|
|
MTH3D_M_vMulMatrixVector ( &stVertex, &_p_stGlobalMatrix->stTransformMatrix, p_stVertex );
|
|
|
|
if (MTH_M_bLess(stVertex.xX, _p_stMin->xX))
|
|
_p_stMin->xX = stVertex.xX;
|
|
if(MTH_M_bGreater(stVertex.xX, _p_stMax->xX))
|
|
_p_stMax->xX = stVertex.xX;
|
|
if (MTH_M_bLess(stVertex.xY, _p_stMin->xY))
|
|
_p_stMin->xY = stVertex.xY;
|
|
if(MTH_M_bGreater(stVertex.xY, _p_stMax->xY))
|
|
_p_stMax->xY = stVertex.xY;
|
|
if (MTH_M_bLess(stVertex.xZ, _p_stMin->xZ))
|
|
_p_stMin->xZ = stVertex.xZ;
|
|
if(MTH_M_bGreater(stVertex.xZ, _p_stMax->xZ))
|
|
_p_stMax->xZ = stVertex.xZ;
|
|
|
|
}
|
|
|
|
/* Some elements are not included by the point, it's the case for the spheres, the boxes, the sprites & the cones.*/
|
|
/* So here some new box are added.*/
|
|
for (lElementCounter = 0 ; lElementCounter < _hGeometricObject->xNbElements;lElementCounter++) {
|
|
if (_hGeometricObject->d_xListOfElementsTypes[lElementCounter] == GEO_C_xElementSprites) {
|
|
GEO_tdstElementSprite * p_stLocalElementSprite =
|
|
((GEO_tdstElementSprite *) _hGeometricObject -> d_stListOfElements[lElementCounter]);
|
|
for ( i = 0 ; i < p_stLocalElementSprite -> xNbSprites; i ++) {
|
|
MTH_tdxReal xRadius;
|
|
/* because all sprites are scaled Sprites*/
|
|
MTH2D_tdstVector * p_stSize =
|
|
p_stLocalElementSprite->d_stListOfSprites[i].hSprite->d_xSizeOfSprite;
|
|
MTH3D_tdstVector stCenter;
|
|
|
|
/* compute bulk of sprite*/
|
|
xRadius = MTH_M_xMul(MTH2D_M_xNormVector(p_stSize),MTH_C_Inv2);
|
|
xRadius = MTH_M_xMul(xRadius,POS_fn_xGetMaxScale(_p_stGlobalMatrix));
|
|
|
|
/* Compute Center in Global World coordintes*/
|
|
MTH3D_M_vMulMatrixVector(&stCenter,&_p_stGlobalMatrix->stTransformMatrix,
|
|
&_hGeometricObject->d_stListOfPoints[p_stLocalElementSprite->d_stListOfSprites[i].xCenterPoint]);
|
|
|
|
/* Compute Min Point */
|
|
_p_stMin->xX = MTH_M_xMin(_p_stMin->xX,MTH_M_xSub(stCenter.xX,xRadius));
|
|
_p_stMin->xY = MTH_M_xMin(_p_stMin->xY,MTH_M_xSub(stCenter.xY,xRadius));
|
|
_p_stMin->xZ = MTH_M_xMin(_p_stMin->xZ,MTH_M_xSub(stCenter.xZ,xRadius));
|
|
|
|
/* Compute Max Point */
|
|
_p_stMax->xX = MTH_M_xMax(_p_stMax->xX,MTH_M_xAdd(stCenter.xX,xRadius));
|
|
_p_stMax->xY = MTH_M_xMax(_p_stMax->xY,MTH_M_xAdd(stCenter.xY,xRadius));
|
|
_p_stMax->xZ = MTH_M_xMax(_p_stMax->xZ,MTH_M_xAdd(stCenter.xZ,xRadius));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#if defined(U64)
|
|
void GEO_fn_vAddObjectToBox2
|
|
(
|
|
ACP_tdxHandleOfObject _hGeometricObject,
|
|
struct POS_stCompletePosition *_p_stGlobalMatrix,
|
|
MTH3D_tdstVector *_p_stMax,
|
|
MTH3D_tdstVector *_p_stMin
|
|
)
|
|
{
|
|
MTH3D_tdstVector* p_stVertex;
|
|
MTH3D_tdstVector stVertex;
|
|
long i;
|
|
|
|
/* First : get the collision part*/
|
|
p_stVertex = _hGeometricObject->d_stListOfPoints;
|
|
|
|
for (i=0; i<_hGeometricObject->xNbPoints; i++,p_stVertex++)
|
|
{
|
|
/* The point must be computed in the global world, not in the local one...*/
|
|
POS_fn_vMulMatrixVertex( &stVertex, _p_stGlobalMatrix, p_stVertex );
|
|
|
|
if (MTH_M_bLess(stVertex.xX, _p_stMin->xX))
|
|
_p_stMin->xX = stVertex.xX;
|
|
if(MTH_M_bGreater(stVertex.xX, _p_stMax->xX))
|
|
_p_stMax->xX = stVertex.xX;
|
|
if (MTH_M_bLess(stVertex.xY, _p_stMin->xY))
|
|
_p_stMin->xY = stVertex.xY;
|
|
if(MTH_M_bGreater(stVertex.xY, _p_stMax->xY))
|
|
_p_stMax->xY = stVertex.xY;
|
|
if (MTH_M_bLess(stVertex.xZ, _p_stMin->xZ))
|
|
_p_stMin->xZ = stVertex.xZ;
|
|
if(MTH_M_bGreater(stVertex.xZ, _p_stMax->xZ))
|
|
_p_stMax->xZ = stVertex.xZ;
|
|
}
|
|
/* Second : deals with the graphics part ... this is temporary anti-bug, waiting for binarization of BV*/
|
|
{
|
|
/* Max*/
|
|
MTH_tdxReal xCoord = MTH_M_xFloatToReal(_hGeometricObject->fRadius);
|
|
|
|
MTH3D_M_vSetVectorElements( &stVertex, xCoord, xCoord, xCoord );
|
|
POS_fn_vMulMatrixVertex( &stVertex, _p_stGlobalMatrix, &stVertex );
|
|
if(MTH_M_bGreater(stVertex.xX, _p_stMax->xX))
|
|
_p_stMax->xX = stVertex.xX;
|
|
if(MTH_M_bGreater(stVertex.xY, _p_stMax->xY))
|
|
_p_stMax->xY = stVertex.xY;
|
|
if(MTH_M_bGreater(stVertex.xZ, _p_stMax->xZ))
|
|
_p_stMax->xZ = stVertex.xZ;
|
|
|
|
/* Min*/
|
|
xCoord = MTH_M_xNeg( xCoord );
|
|
|
|
MTH3D_M_vSetVectorElements( &stVertex, xCoord, xCoord, xCoord );
|
|
POS_fn_vMulMatrixVertex( &stVertex, _p_stGlobalMatrix, &stVertex );
|
|
if (MTH_M_bLess(stVertex.xX, _p_stMin->xX))
|
|
_p_stMin->xX = stVertex.xX;
|
|
if (MTH_M_bLess(stVertex.xY, _p_stMin->xY))
|
|
_p_stMin->xY = stVertex.xY;
|
|
if (MTH_M_bLess(stVertex.xZ, _p_stMin->xZ))
|
|
_p_stMin->xZ = stVertex.xZ;
|
|
}
|
|
}
|
|
#endif /* U64 */
|
|
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create a bounding sphere that includes 2 bounding spheres*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vComputeBoundingSphereOfTwoSpheres
|
|
(
|
|
MTH3D_tdstVector *_p_stReturnedSphereCenter,
|
|
MTH_tdxReal *_p_xReturnedSphereRadius,
|
|
MTH3D_tdstVector *_p_stFirstSphereCenter,
|
|
MTH_tdxReal _xFirstSphereRadius,
|
|
MTH3D_tdstVector *_p_stSecondSphereCenter,
|
|
MTH_tdxReal _xSecondSphereRadius
|
|
)
|
|
{
|
|
MTH_tdxReal xDistanceBetweenCenters, xAlpha;
|
|
MTH3D_tdstVector stDeltaCenter;
|
|
|
|
|
|
MTH3D_M_vSubVector(&stDeltaCenter, _p_stFirstSphereCenter, _p_stSecondSphereCenter);
|
|
xDistanceBetweenCenters=MTH3D_M_xNormVector(&stDeltaCenter);/*! can be zero*/
|
|
if(xDistanceBetweenCenters+_xFirstSphereRadius<=_xSecondSphereRadius)
|
|
{
|
|
MTH3D_M_vCopyVector(_p_stReturnedSphereCenter,_p_stSecondSphereCenter);
|
|
*_p_xReturnedSphereRadius=_xSecondSphereRadius;
|
|
return;
|
|
}
|
|
else if(xDistanceBetweenCenters+_xSecondSphereRadius<_xFirstSphereRadius)
|
|
{
|
|
MTH3D_M_vCopyVector(_p_stReturnedSphereCenter,_p_stFirstSphereCenter);
|
|
*_p_xReturnedSphereRadius=_xFirstSphereRadius;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
xAlpha=(1.0f-(_xFirstSphereRadius-_xSecondSphereRadius)/xDistanceBetweenCenters)/2.0f;
|
|
MTH3D_M_vLinearInterpolVector( _p_stReturnedSphereCenter, _p_stFirstSphereCenter, _p_stSecondSphereCenter, xAlpha);
|
|
*_p_xReturnedSphereRadius=(xDistanceBetweenCenters+_xFirstSphereRadius+_xSecondSphereRadius)/2.0f;
|
|
}
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create a bounding sphere that includes a bounding sphere and a point*/
|
|
/* It is exactly the same function as before with a null radius second sphere*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vComputeBoundingSphereOfOneSphereAndOnePoint
|
|
(
|
|
MTH3D_tdstVector *_p_stReturnedSphereCenter,
|
|
MTH_tdxReal *_p_xReturnedSphereRadius,
|
|
MTH3D_tdstVector *_p_stFirstSphereCenter,
|
|
MTH_tdxReal _xFirstSphereRadius,
|
|
MTH3D_tdstVector *_p_stSecondSphereCenter
|
|
)
|
|
{
|
|
MTH_tdxReal xDistanceBetweenCenters, xAlpha;
|
|
MTH3D_tdstVector stDeltaCenter;
|
|
|
|
|
|
MTH3D_M_vSubVector(&stDeltaCenter, _p_stFirstSphereCenter, _p_stSecondSphereCenter);
|
|
xDistanceBetweenCenters=MTH3D_M_xNormVector(&stDeltaCenter);/*! can be zero*/
|
|
if(xDistanceBetweenCenters<=_xFirstSphereRadius)/* ! both can be zero*/
|
|
{
|
|
MTH3D_M_vCopyVector(_p_stReturnedSphereCenter,_p_stFirstSphereCenter);
|
|
*_p_xReturnedSphereRadius=_xFirstSphereRadius;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
xAlpha=(1.0f-(_xFirstSphereRadius)/xDistanceBetweenCenters)/2.0f;
|
|
MTH3D_M_vLinearInterpolVector( _p_stReturnedSphereCenter, _p_stFirstSphereCenter, _p_stSecondSphereCenter, xAlpha);
|
|
*_p_xReturnedSphereRadius=(xDistanceBetweenCenters+_xFirstSphereRadius)/2.0f;
|
|
}
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create a bounding sphere that includes a sprite*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vComputeBoundingSphereOfSprite
|
|
(
|
|
GEO_tdstIndexedSprite *p_stIndexedSprite,
|
|
MTH_tdxReal *p_stSphereRadius
|
|
)
|
|
{
|
|
MTH_tdxReal xLocalValueX,xLocalValueY;
|
|
xLocalValueX = p_stIndexedSprite->stSize . xX * ( p_stIndexedSprite -> hSprite -> d_xSizeOfSprite[0] . xX + p_stIndexedSprite -> hSprite -> d_xDisplacementOfSprite[0].xX );
|
|
xLocalValueY = p_stIndexedSprite->stSize . xY * ( p_stIndexedSprite -> hSprite -> d_xSizeOfSprite[0] . xY + p_stIndexedSprite -> hSprite -> d_xDisplacementOfSprite[0].xY );
|
|
*p_stSphereRadius = MTH_M_xSqrt( xLocalValueX * xLocalValueX + xLocalValueY * xLocalValueY ) ;
|
|
}
|
|
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
|
|
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create a bounding sphere that includes an altimap*/
|
|
/* */
|
|
/*--------------------------------------------------------------------------------------*/
|
|
#ifdef USE_ALTIMAPS
|
|
void GEO_fn_vAddAltimapToSphere
|
|
(
|
|
ACP_tdxHandleOfObject _hGeometricObject,
|
|
MTH3D_tdstVector *_p_stSphereCenter,
|
|
MTH_tdxReal *_p_xSphereRadius
|
|
)
|
|
|
|
{
|
|
MTH3D_tdstVector stVertex, stVectI, stVectJ, stVectK;
|
|
long cWidth, cDepth, cVertex;
|
|
GEO_tdstElementAltimap *p_stEAltimap;
|
|
MTH_tdxReal xOrigZ;
|
|
|
|
assert(_hGeometricObject != NULL);
|
|
|
|
/*--- Getting the Altimap Element*/
|
|
p_stEAltimap = (GEO_tdstElementAltimap *) _hGeometricObject->d_stListOfElements[ 0 ];
|
|
|
|
/*--- Getting the Origin for Z=0 ---*/
|
|
xOrigZ = p_stEAltimap->stOrigin.xZ;
|
|
p_stEAltimap->stOrigin.xZ = MTH_C_ZERO;
|
|
|
|
/*--- Setting reference Vectors*/
|
|
MTH3D_M_vSetBaseIVector( &stVectI );
|
|
MTH3D_M_vMulScalarVector( &stVectI, p_stEAltimap->xDeltaX, &stVectI );
|
|
MTH3D_M_vSetBaseJVector( &stVectJ );
|
|
MTH3D_M_vMulScalarVector( &stVectJ, p_stEAltimap->xDeltaY, &stVectJ );
|
|
MTH3D_M_vSetBaseKVector( &stVectK );
|
|
|
|
for( cVertex = 0, cDepth = 0 ; cDepth < p_stEAltimap->xDepth ; cDepth ++ )
|
|
for( cWidth = 0 ; cWidth < p_stEAltimap->xWidth ; cWidth ++, cVertex++ )
|
|
{
|
|
MTH3D_M_vMulAddVector( &stVertex,
|
|
MTH_M_xLongToReal( cWidth ),
|
|
&stVectI,
|
|
&p_stEAltimap->stOrigin );
|
|
MTH3D_M_vMulAddVector( &stVertex,
|
|
MTH_M_xLongToReal( cDepth ),
|
|
&stVectJ,
|
|
&stVertex );
|
|
MTH3D_M_vMulAddVector( &stVertex,
|
|
p_stEAltimap->d_xHeight[ p_stEAltimap->xWidth * cDepth + cWidth ],
|
|
&stVectK,
|
|
&stVertex );
|
|
|
|
GEO_fn_vComputeBoundingSphereOfOneSphereAndOnePoint( _p_stSphereCenter,
|
|
_p_xSphereRadius,
|
|
_p_stSphereCenter,
|
|
*_p_xSphereRadius,
|
|
&stVertex );
|
|
|
|
}
|
|
/*--- Restoring the Original Z ---*/
|
|
p_stEAltimap->stOrigin.xZ = xOrigZ;
|
|
}
|
|
#endif /*USE_ALTIMAPS*/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create a sphere that includes perfectly a geometric object.*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
|
|
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
|
|
void GEO_fn_vAddObjectToSphere
|
|
(
|
|
ACP_tdxHandleOfObject _hGeometricObject,
|
|
MTH3D_tdstVector *_p_stSphereCenter,
|
|
MTH_tdxReal *_p_xSphereRadius
|
|
)
|
|
|
|
{
|
|
MTH3D_tdstVector* p_stVertex;
|
|
long i,lElementCounter ;
|
|
GEO_tdstElementSpheres *p_stLocalElementSphere;
|
|
GEO_tdstElementSprite *p_stLocalElementSprite;
|
|
MTH3D_tdstVector stSphereCenterLocal;
|
|
MTH_tdxReal xSphereRadiusLocal;
|
|
|
|
|
|
assert(_hGeometricObject != NULL);
|
|
|
|
p_stVertex=_hGeometricObject->d_stListOfPoints;
|
|
for (i=0; i<_hGeometricObject->xNbPoints; i++,p_stVertex++)
|
|
{
|
|
GEO_fn_vComputeBoundingSphereOfOneSphereAndOnePoint
|
|
(
|
|
_p_stSphereCenter,
|
|
_p_xSphereRadius,
|
|
_p_stSphereCenter,
|
|
*_p_xSphereRadius,
|
|
p_stVertex
|
|
);
|
|
|
|
}
|
|
/* Some elements are not included by the point, it's the case for the spheres, the boxes, the sprites & the cones.*/
|
|
/* So here some new spheres are added.*/
|
|
for (lElementCounter = 0 ; lElementCounter < _hGeometricObject -> xNbElements; lElementCounter ++ )
|
|
switch (_hGeometricObject -> d_xListOfElementsTypes [lElementCounter ] )
|
|
{
|
|
default:break;
|
|
case GEO_C_xElementSprites:
|
|
p_stLocalElementSprite = ((GEO_tdstElementSprite *) _hGeometricObject -> d_stListOfElements[lElementCounter]);
|
|
for ( i = 0 ; i < p_stLocalElementSprite -> xNbSprites; i ++)
|
|
{
|
|
GEO_fn_vComputeBoundingSphereOfSprite(&p_stLocalElementSprite -> d_stListOfSprites[i],&xSphereRadiusLocal);
|
|
stSphereCenterLocal = *(_hGeometricObject->d_stListOfPoints + p_stLocalElementSprite -> d_stListOfSprites[i] . xCenterPoint);
|
|
GEO_fn_vComputeBoundingSphereOfTwoSpheres
|
|
(
|
|
_p_stSphereCenter,
|
|
_p_xSphereRadius,
|
|
_p_stSphereCenter,
|
|
*_p_xSphereRadius,
|
|
&stSphereCenterLocal,
|
|
xSphereRadiusLocal
|
|
);
|
|
}
|
|
break;
|
|
case GEO_C_xElementSpheres:
|
|
p_stLocalElementSphere = ((GEO_tdstElementSpheres*) _hGeometricObject -> d_stListOfElements[lElementCounter]);
|
|
for ( i= 0 ;i< p_stLocalElementSphere -> xNbSpheres ;i++ )
|
|
{
|
|
stSphereCenterLocal = *(_hGeometricObject->d_stListOfPoints + p_stLocalElementSphere -> d_stListOfSpheres [i] .xCenterPoint);
|
|
xSphereRadiusLocal = p_stLocalElementSphere -> d_stListOfSpheres [i] .xRadius;
|
|
GEO_fn_vComputeBoundingSphereOfTwoSpheres
|
|
(
|
|
_p_stSphereCenter,
|
|
_p_xSphereRadius,
|
|
_p_stSphereCenter,
|
|
*_p_xSphereRadius,
|
|
&stSphereCenterLocal,
|
|
xSphereRadiusLocal
|
|
);
|
|
}
|
|
break;
|
|
case GEO_C_xElementAlignedBoxes:
|
|
break;
|
|
case GEO_C_xElementCones:
|
|
break;
|
|
} /* Element switch*/
|
|
}
|
|
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
|
|
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Find the radius and the center of a sphere geometric object*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
|
|
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC 04/06/99 */
|
|
void GEO_fn_vGetInfoFromGeometricSphere
|
|
(
|
|
MTH3D_tdstVector *_p_stSphereCenter,
|
|
MTH_tdxReal *_p_xSphereRadius,
|
|
ACP_tdxHandleOfObject _hBoundingVolume
|
|
)
|
|
{
|
|
MTH3D_tdstVector* p_stCenter;
|
|
struct GEO_tdstIndexedSphere_ * p_stOneSphere;
|
|
struct GEO_tdstElementSpheres_ * p_stAllTheSpheres;
|
|
|
|
p_stAllTheSpheres = (struct GEO_tdstElementSpheres_ *)(_hBoundingVolume->d_stListOfElements[0]);
|
|
p_stOneSphere = (struct GEO_tdstIndexedSphere_ *)(p_stAllTheSpheres->d_stListOfSpheres);
|
|
p_stCenter = _hBoundingVolume->d_stListOfPoints + p_stOneSphere->xCenterPoint;
|
|
|
|
MTH3D_M_vCopyVector ( _p_stSphereCenter, p_stCenter );
|
|
*_p_xSphereRadius = p_stOneSphere->xRadius;
|
|
}
|
|
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC 04/06/99 */
|
|
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Creation of a sphere geometric object*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
|
|
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
|
|
ACP_tdxHandleOfObject GEO_fn_hCreateGeometricSphere
|
|
(
|
|
void
|
|
)
|
|
{
|
|
MTH3D_tdstVector stVertex;
|
|
ACP_tdxHandleOfObject hReturnedObject;
|
|
ACP_tdxHandleOfElement hElmt;
|
|
|
|
MTH3D_M_vNullVector ( &stVertex );
|
|
GEO_vCreateGeometricObject(&hReturnedObject, 1/*xNbPoints*/, 1/*xNbElements*/);
|
|
GEO_vCreateElementSpheres(hReturnedObject, &hElmt, 1/*one sphere*/);
|
|
GEO_vSetPointOfObject (hReturnedObject, &stVertex , 0/*first point*/);
|
|
GEO_vSetCenterPointOfIndexedSphere (hReturnedObject, hElmt, 0/*first sphere*/, 0/*first point*/);
|
|
GEO_vSetRadiusOfIndexedSphere (hReturnedObject, hElmt, 0/*first sphere*/, 0.0/*xRadius = 0 */);
|
|
GEO_vSetGameMaterialOfIndexedSphere (hReturnedObject, hElmt, 0/*first sphere*/, gs_hMaterial);
|
|
return hReturnedObject;
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Fill the sphere geometric object structure*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vSetGeometricSphere
|
|
(
|
|
MTH3D_tdstVector *_p_stSphereCenter,
|
|
MTH_tdxReal _xSphereRadius,
|
|
ACP_tdxHandleOfObject _hBoundingSphere
|
|
)
|
|
{
|
|
GEO_vSetPointOfObject (_hBoundingSphere, _p_stSphereCenter , 0/*first point*/);
|
|
GEO_vSetRadiusOfIndexedSphere (_hBoundingSphere, 0/*first elmt*/, 0/*first sphere*/, _xSphereRadius);
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Copy the radius and the center of the geometric object(sphere)*/
|
|
/* into the bounding sphere structure*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vUpdateBoundingSphere
|
|
(
|
|
ACP_tdxHandleOfObject _hGeometricSphere,
|
|
GEO_tdxHandleToBoundingSphere _hBoundingSphere
|
|
)
|
|
{
|
|
MTH3D_tdstVector stCenter;
|
|
MTH_tdxReal xRadius;
|
|
|
|
GEO_fn_vGetInfoFromGeometricSphere (&stCenter, &xRadius, _hGeometricSphere);
|
|
GEO_fn_vSetBoundingSphere( _hBoundingSphere, &stCenter, xRadius);
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Copy the radius and the center of the bounding sphere*/
|
|
/* into the geometric object structure*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vUpdateGeometricSphere
|
|
(
|
|
ACP_tdxHandleOfObject _hGeometricSphere,
|
|
GEO_tdxHandleToBoundingSphere _hBoundingSphere
|
|
)
|
|
{
|
|
GEO_fn_vSetGeometricSphere
|
|
(
|
|
GEO_fn_pGetCenterPointOfBoundingSphere(_hBoundingSphere),
|
|
GEO_fn_xGetRadiusOfBoundingSphere(_hBoundingSphere),
|
|
_hGeometricSphere
|
|
);
|
|
}
|
|
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
|
|
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/* */
|
|
/* Create a Parallel Box*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vCreateParallelBox
|
|
(
|
|
GEO_tdxHandleToParallelBox *_p_hNewBox
|
|
)
|
|
{
|
|
GEO_tdxHandleToParallelBox hBox;
|
|
|
|
MMG_fn_vAddMemoryInfo( MMG_C_lTypeGeometricObject , MMG_C_lSubTypeParallelBox , 0 );
|
|
GEO_M_CPAMalloc ( hBox,
|
|
GEO_tdxHandleToParallelBox,
|
|
sizeof(GEO_tdstParallelBox),
|
|
E_uwGEONotEnoughtMemory );
|
|
|
|
MTH3D_M_vNullVector( &(hBox -> stMinPoint) );
|
|
MTH3D_M_vNullVector( &(hBox -> stMaxPoint) );
|
|
|
|
*_p_hNewBox = hBox;
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Delete a Parallel Box*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
|
|
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
|
|
void GEO_vDeleteParallelBox
|
|
(
|
|
GEO_tdxHandleToParallelBox _hParallelBox
|
|
)
|
|
{
|
|
GEO_M_CPAFree( _hParallelBox );
|
|
}
|
|
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
|
|
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create a Parallel box and fill the structure*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
|
|
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
|
|
void GEO_fn_vCreateAndInitBoxBoundingVolume
|
|
(
|
|
GEO_tdxHandleToParallelBox *_p_hNewBox,
|
|
MTH3D_tdstVector *_p_stMaxBoxPoint,
|
|
MTH3D_tdstVector *_p_stMinBoxPoint
|
|
)
|
|
{
|
|
GEO_fn_vCreateParallelBox( _p_hNewBox );
|
|
GEO_fn_vSetMaxPointOfParallelBox( *_p_hNewBox, _p_stMaxBoxPoint );
|
|
GEO_fn_vSetMinPointOfParallelBox( *_p_hNewBox, _p_stMinBoxPoint );
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create the sphere that includes a parallel box*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vGetSphereFromParallelBox
|
|
(
|
|
MTH3D_tdstVector *_p_stCenter,
|
|
MTH_tdxReal *_p_xRadius,
|
|
MTH3D_tdstVector *_p_stMaxBoxPoint,
|
|
MTH3D_tdstVector *_p_stMinBoxPoint
|
|
)
|
|
{
|
|
MTH3D_tdstVector stDist;
|
|
|
|
MTH3D_M_vAddVector( &stDist, _p_stMinBoxPoint, _p_stMaxBoxPoint );
|
|
*_p_xRadius = MTH3D_M_xNormVector( &stDist );
|
|
MTH3D_M_vMiddleVector( _p_stCenter, _p_stMinBoxPoint, _p_stMaxBoxPoint );
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create the parallel box that includes a sphere*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vComputeParallelBoxOfSphere
|
|
(
|
|
MTH3D_tdstVector *_p_stMaxBoxPoint,
|
|
MTH3D_tdstVector *_p_stMinBoxPoint,
|
|
MTH3D_tdstVector *_p_stCenter,
|
|
MTH_tdxReal _p_xSphereRadius
|
|
)
|
|
{
|
|
MTH3D_M_vAddScalarVector(_p_stMaxBoxPoint, _p_xSphereRadius, _p_stCenter);
|
|
MTH3D_M_vSubScalarVector(_p_stMinBoxPoint, _p_xSphereRadius, _p_stCenter);
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create a Parallel box that includes 2 parallel boxes*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vComputeParallelBoxOfTwoBoxes
|
|
(
|
|
MTH3D_tdstVector *_p_stMaxReturnedBoxPoint,
|
|
MTH3D_tdstVector *_p_stMinReturnedBoxPoint,
|
|
MTH3D_tdstVector *_p_stMaxFirstBoxPoint,
|
|
MTH3D_tdstVector *_p_stMinFirstBoxPoint,
|
|
MTH3D_tdstVector *_p_stMaxSecondBoxPoint,
|
|
MTH3D_tdstVector *_p_stMinSecondBoxPoint
|
|
)
|
|
{
|
|
MTH3D_tdstVector stFirstTempVect, stSecondTempVect;
|
|
|
|
MTH3D_M_vMaxVector(&stFirstTempVect, _p_stMaxFirstBoxPoint, _p_stMinFirstBoxPoint);
|
|
MTH3D_M_vMaxVector(&stSecondTempVect, _p_stMaxSecondBoxPoint, _p_stMinSecondBoxPoint)
|
|
MTH3D_M_vMaxVector(_p_stMaxReturnedBoxPoint, &stFirstTempVect, &stSecondTempVect);
|
|
MTH3D_M_vMinVector(&stFirstTempVect, _p_stMaxFirstBoxPoint, _p_stMinFirstBoxPoint);
|
|
MTH3D_M_vMinVector(&stSecondTempVect, _p_stMaxSecondBoxPoint, _p_stMinSecondBoxPoint)
|
|
MTH3D_M_vMinVector(_p_stMinReturnedBoxPoint, &stFirstTempVect, &stSecondTempVect);
|
|
}
|
|
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
|
|
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/* */
|
|
/* Create a bounding sphere*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vCreateBoundingSphere
|
|
(
|
|
GEO_tdxHandleToBoundingSphere *_p_hNewSphere
|
|
)
|
|
{
|
|
GEO_tdxHandleToBoundingSphere hSphere;
|
|
|
|
MMG_fn_vAddMemoryInfo( MMG_C_lTypeGeometricObject , MMG_C_lSubTypeBoundingSphere , 0 );
|
|
GEO_M_CPAMalloc ( hSphere,
|
|
GEO_tdxHandleToBoundingSphere,
|
|
sizeof(GEO_tdstBoundingSphere),
|
|
E_uwGEONotEnoughtMemory );
|
|
|
|
MTH3D_M_vNullVector(&(hSphere->stCenterPoint));
|
|
hSphere->xRadius = 0.0;
|
|
|
|
*_p_hNewSphere = hSphere;
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Fill the bounding sphere structure */
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
void GEO_fn_vSetBoundingSphere
|
|
(
|
|
GEO_tdxHandleToBoundingSphere _hBoundingSphere,
|
|
MTH3D_tdstVector *_p_stCenterPoint,
|
|
MTH_tdxReal _xRadius
|
|
)
|
|
{
|
|
if( _hBoundingSphere)
|
|
{
|
|
MTH3D_M_vCopyVector( & (_hBoundingSphere->stCenterPoint ), _p_stCenterPoint );
|
|
_hBoundingSphere->xRadius = _xRadius;
|
|
}
|
|
}
|
|
/*--------------------------------------------------------------------------------------*/
|
|
/**/
|
|
/* Create a bounding sphere and fill the structure*/
|
|
/**/
|
|
/*--------------------------------------------------------------------------------------*/
|
|
|
|
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
|
|
void GEO_fn_vCreateAndInitBoundingSphere
|
|
(
|
|
GEO_tdxHandleToBoundingSphere *_p_hNewSphere,
|
|
MTH3D_tdstVector *_p_stCenter,
|
|
MTH_tdxReal _xRadius)
|
|
{
|
|
GEO_fn_vCreateBoundingSphere( _p_hNewSphere );
|
|
GEO_fn_vSetBoundingSphere( *_p_hNewSphere, _p_stCenter, _xRadius );
|
|
}
|
|
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
|
|
|
|
/*ENDANNECY TQ}*/
|
|
|
|
|
|
|