977 lines
47 KiB
C
977 lines
47 KiB
C
/**********************************************************************************************/
|
||
/* Name: BigFunc1*/
|
||
/* Goal: Draw a list of indexed triangles..*/
|
||
/* Code: Steve McCalla */
|
||
/* OPTIMIZED : Halfway - in order to keep this fast, please avoid sticking DD branches in here.*/
|
||
/* it would be really nice if we could get rid of a few copies too!*/
|
||
/**********************************************************************************************/
|
||
|
||
#ifdef __BigFunc1__From_Steve_Mac_Calla__
|
||
|
||
static void
|
||
BigFunc1 (ACP_tdxIndex xTriangleCounter)
|
||
{
|
||
int iIndex = xTriangleCounter;
|
||
for (; iIndex--; p_stCurrentTriangle ++, p_stCurrentTriangleUV ++) {
|
||
#ifdef PROFILING_STUFF
|
||
PRF_MDRV_vSetIndependantVariable( PRF_C_ulIdpDisplayedTriangle , 0 );
|
||
#endif
|
||
/* This function should be identical to calling this series of functions:*/
|
||
/*GLI_vComputeXYZ();*/
|
||
/*GLI_vSetSpecular();*/
|
||
/*GLI_TestBackfaceClockwise();*/
|
||
/*GLI_vComputeNormalUVW();*/
|
||
/*GLI_vDrawTriangle();*/
|
||
/*GLI_vCorrect3DFXBug1();*/
|
||
GLI_tdstAligned2DVector *p_ScreenPoint;
|
||
p_ScreenPoint = GLI_BIG_GLOBALS->GLI_ScreenPoint+p_stCurrentTriangle->a3_xIndex[0];
|
||
SetX(CurrentDestXYZ[0],p_ScreenPoint->xX);
|
||
SetY(CurrentDestXYZ[0],p_ScreenPoint->xY);
|
||
SetZ(CurrentDestXYZ[0],p_ScreenPoint->xOoZ);
|
||
SetPackedColor(CurrentDestXYZ[0],p_ScreenPoint->ulPackedColor );
|
||
p_ScreenPoint = GLI_BIG_GLOBALS->GLI_ScreenPoint+p_stCurrentTriangle->a3_xIndex[1];
|
||
SetX(CurrentDestXYZ[1],p_ScreenPoint->xX);
|
||
SetY(CurrentDestXYZ[1],p_ScreenPoint->xY);
|
||
SetZ(CurrentDestXYZ[1],p_ScreenPoint->xOoZ);
|
||
SetPackedColor(CurrentDestXYZ[1],p_ScreenPoint->ulPackedColor );
|
||
p_ScreenPoint = GLI_BIG_GLOBALS->GLI_ScreenPoint+p_stCurrentTriangle->a3_xIndex[2];
|
||
SetX(CurrentDestXYZ[2],p_ScreenPoint->xX);
|
||
SetY(CurrentDestXYZ[2],p_ScreenPoint->xY);
|
||
SetZ(CurrentDestXYZ[2],p_ScreenPoint->xOoZ);
|
||
SetPackedColor(CurrentDestXYZ[2],p_ScreenPoint->ulPackedColor );
|
||
|
||
|
||
|
||
if ( ( ( GetY(CurrentDestXYZ[2]) - GetY(CurrentDestXYZ[1]) ) * ( GetX(CurrentDestXYZ[0]) - GetX(CurrentDestXYZ[1]) ) ) - ( ( GetX(CurrentDestXYZ[2]) - GetX(CurrentDestXYZ[1]) )* ( GetY(CurrentDestXYZ[0]) - GetY(CurrentDestXYZ[1]) ) ) < 0.f )
|
||
continue;
|
||
/* After this function, no index from the element should be used...*/
|
||
SetPackedSpecular( CurrentDestXYZ[0], *((unsigned long *) GLI_BIG_GLOBALS->GLI_aDEF_stColorsRLIS + p_stCurrentTriangle->a3_xIndex[0]) );
|
||
SetPackedSpecular( CurrentDestXYZ[1], *((unsigned long *) GLI_BIG_GLOBALS->GLI_aDEF_stColorsRLIS + p_stCurrentTriangle->a3_xIndex[1]) );
|
||
SetPackedSpecular( CurrentDestXYZ[2], *((unsigned long *) GLI_BIG_GLOBALS->GLI_aDEF_stColorsRLIS + p_stCurrentTriangle->a3_xIndex[2]) );
|
||
|
||
d_stVirtualUV[0] = p_stCurrentElementIndexedTriangle -> d_stListOfElementUV + p_stCurrentTriangleUV -> a3_xIndex[0];
|
||
d_stVirtualUV[1] = p_stCurrentElementIndexedTriangle -> d_stListOfElementUV + p_stCurrentTriangleUV -> a3_xIndex[1];
|
||
d_stVirtualUV[2] = p_stCurrentElementIndexedTriangle -> d_stListOfElementUV + p_stCurrentTriangleUV -> a3_xIndex[2];
|
||
|
||
SetU_Cpy(CurrentDestXYZ[0],(d_stVirtualUV[0]) -> xU );
|
||
SetV_Cpy(CurrentDestXYZ[0],(d_stVirtualUV[0]) -> xV );
|
||
SetU_Cpy(CurrentDestXYZ[1],(d_stVirtualUV[1]) -> xU );
|
||
SetV_Cpy(CurrentDestXYZ[1],(d_stVirtualUV[1]) -> xV );
|
||
SetU_Cpy(CurrentDestXYZ[2],(d_stVirtualUV[2]) -> xU );
|
||
SetV_Cpy(CurrentDestXYZ[2],(d_stVirtualUV[2]) -> xV );
|
||
|
||
GLI_M_Correct3DFXBug1(CurrentDestXYZ[0]);
|
||
GLI_M_Correct3DFXBug1(CurrentDestXYZ[1]);
|
||
GLI_M_Correct3DFXBug1(CurrentDestXYZ[2]);
|
||
|
||
GLI_vDrawTriangle();
|
||
|
||
#ifdef PROFILING_STUFF
|
||
if( PRF_MDRV_lGetIndependantVariable( PRF_C_ulIdpDisplayedTriangle ) )
|
||
{
|
||
PRF_MDRV_vIncreaseVariable( PRF_C_ulVarFaces + PRF_MDRV_lGetIndependantVariable( PRF_C_ulIdpDynOrSta ), PRF_C_pvDisplayed, 1 );
|
||
PRF_MDRV_vSetIndependantVariable( PRF_C_ulIdpDisplayedFaces, 1 );
|
||
}
|
||
#endif
|
||
|
||
}
|
||
}
|
||
|
||
|
||
#endif
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* BACKFACE CULLING*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
GLI_FuncNodeBegin(GLI_TestBackfaceClockwise)
|
||
{
|
||
if ( ( ( GetY(CurrentDestXYZ[2]) - GetY(CurrentDestXYZ[1]) ) * ( GetX(CurrentDestXYZ[0]) - GetX(CurrentDestXYZ[1]) ) ) - ( ( GetX(CurrentDestXYZ[2]) - GetX(CurrentDestXYZ[1]) )* ( GetY(CurrentDestXYZ[0]) - GetY(CurrentDestXYZ[1]) ) ) < 0.f ) GLI_M_TriangleIsOut();
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
GLI_FuncNodeBegin(GLI_TestBackfaceCounterClockwize)
|
||
{
|
||
if ( ( ( GetY(CurrentDestXYZ[2]) - GetY(CurrentDestXYZ[1]) ) * ( GetX(CurrentDestXYZ[0]) - GetX(CurrentDestXYZ[1]) ) ) - ( ( GetX(CurrentDestXYZ[2]) - GetX(CurrentDestXYZ[1]) )* ( GetY(CurrentDestXYZ[0]) - GetY(CurrentDestXYZ[1]) ) ) > 0.f ) GLI_M_TriangleIsOut();
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* UVW Computing*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
GLI_FuncNodeBegin(GLI_vComputeMovingUVW)
|
||
{
|
||
SetU(CurrentDestXYZ[0],(d_stVirtualUV[0]) -> xU + fAddU);
|
||
SetV(CurrentDestXYZ[0],(d_stVirtualUV[0]) -> xV + fAddV);
|
||
SetU(CurrentDestXYZ[1],(d_stVirtualUV[1]) -> xU + fAddU);
|
||
SetV(CurrentDestXYZ[1],(d_stVirtualUV[1]) -> xV + fAddV);
|
||
SetU(CurrentDestXYZ[2],(d_stVirtualUV[2]) -> xU + fAddU);
|
||
SetV(CurrentDestXYZ[2],(d_stVirtualUV[2]) -> xV + fAddV);
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
GLI_FuncNodeBegin(GLI_vComputeNormalUVW)
|
||
{
|
||
SetU_Cpy(CurrentDestXYZ[0],(d_stVirtualUV[0]) -> xU );
|
||
SetV_Cpy(CurrentDestXYZ[0],(d_stVirtualUV[0]) -> xV );
|
||
SetU_Cpy(CurrentDestXYZ[1],(d_stVirtualUV[1]) -> xU );
|
||
SetV_Cpy(CurrentDestXYZ[1],(d_stVirtualUV[1]) -> xV );
|
||
SetU_Cpy(CurrentDestXYZ[2],(d_stVirtualUV[2]) -> xU );
|
||
SetV_Cpy(CurrentDestXYZ[2],(d_stVirtualUV[2]) -> xV );
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
GLI_FuncNodeBegin(GLI_vComputeMirrorUVW)
|
||
{
|
||
SetPackedColor(CurrentDestXYZ[0],0x3f3f3f3f );
|
||
SetPackedColor(CurrentDestXYZ[1],0x3f3f3f3f );
|
||
SetPackedColor(CurrentDestXYZ[2],0x3f3f3f3f );
|
||
SetU(CurrentDestXYZ[0],GetX(CurrentDestXYZ[0]) / 640.0f);
|
||
SetV(CurrentDestXYZ[0],GetY(CurrentDestXYZ[0]) / 512.0f);
|
||
SetU(CurrentDestXYZ[1],GetX(CurrentDestXYZ[1]) / 640.0f);
|
||
SetV(CurrentDestXYZ[1],GetY(CurrentDestXYZ[1]) / 512.0f);
|
||
SetU(CurrentDestXYZ[2],GetX(CurrentDestXYZ[2]) / 640.0f);
|
||
SetV(CurrentDestXYZ[2],GetY(CurrentDestXYZ[2]) / 512.0f);
|
||
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
GLI_FuncNodeBegin( GLI_vAlignUForMirrorTexture )
|
||
{
|
||
SetU(CurrentDestXYZ[0],GetU(CurrentDestXYZ[0]) * .5f);
|
||
SetU(CurrentDestXYZ[1],GetU(CurrentDestXYZ[1]) * .5f);
|
||
SetU(CurrentDestXYZ[2],GetU(CurrentDestXYZ[2]) * .5f);
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
GLI_FuncNodeBegin( GLI_vAlignVForMirrorTexture )
|
||
{
|
||
SetV(CurrentDestXYZ[0], (GetV(CurrentDestXYZ[0]) + 1.0f) * .5f);
|
||
SetV(CurrentDestXYZ[1], (GetV(CurrentDestXYZ[1]) + 1.0f) * .5f);
|
||
SetV(CurrentDestXYZ[2], (GetV(CurrentDestXYZ[2]) + 1.0f) * .5f);
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* Set UV*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/*VLCHROME*/
|
||
GLI_FuncNodeBegin(GLI_vSetChromeUVW)
|
||
{
|
||
d_stVirtualUV[0] = GLI_BIG_GLOBALS->GLI_aDEF_stEnvUV + p_stCurrentTriangle->a3_xIndex[0];
|
||
d_stVirtualUV[1] = GLI_BIG_GLOBALS->GLI_aDEF_stEnvUV + p_stCurrentTriangle->a3_xIndex[1];
|
||
d_stVirtualUV[2] = GLI_BIG_GLOBALS->GLI_aDEF_stEnvUV + p_stCurrentTriangle->a3_xIndex[2];
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
/* Normal UV*/
|
||
GLI_FuncNodeBegin(GLI_vSetNormalUVW)
|
||
{
|
||
d_stVirtualUV[0] = p_stCurrentElementIndexedTriangle->d_stListOfElementUV + p_stCurrentTriangleUV->a3_xIndex[0];
|
||
d_stVirtualUV[1] = p_stCurrentElementIndexedTriangle->d_stListOfElementUV + p_stCurrentTriangleUV->a3_xIndex[1];
|
||
d_stVirtualUV[2] = p_stCurrentElementIndexedTriangle->d_stListOfElementUV + p_stCurrentTriangleUV->a3_xIndex[2];
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* Z & MIRROR CULLING*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
|
||
GLI_FuncNodeBegin(GLI_FastZCull)
|
||
{
|
||
if (((*(unsigned long *)&GetZ(CurrentDestXYZ[0]) ) & (*(unsigned long *)&GetZ(CurrentDestXYZ[1]) ) & (*(unsigned long *)&GetZ(CurrentDestXYZ[2]) )) & 0x80000000 ) GLI_M_TriangleIsOut();
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
GLI_FuncNodeBegin(GLI_FastMirrorCulling)
|
||
{
|
||
if ((*(unsigned long *)(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[0])) & (*(unsigned long *)(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[1])) & *(unsigned long *)(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[2]) & 0x80000000) GLI_M_TriangleIsOut();
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* SCREEN CULLING*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
#define GLI_M_CullXMin() *(unsigned long *)&GetX(CurrentDestXYZ[0]) & *(unsigned long *)&GetX(CurrentDestXYZ[1]) & *(unsigned long *)&GetX(CurrentDestXYZ[2]) & 0x80000000
|
||
#define GLI_M_CullXMax() (*(long *)&GetX(CurrentDestXYZ[0]) > fX_CMP_Optimize) && (*(long *)&GetX(CurrentDestXYZ[1]) > fX_CMP_Optimize) && (*(long *)&GetX(CurrentDestXYZ[2]) > fX_CMP_Optimize)
|
||
#define GLI_M_CullYMin() *(unsigned long *)&GetY(CurrentDestXYZ[0]) & *(unsigned long *)&GetY(CurrentDestXYZ[1]) & *(unsigned long *)&GetY(CurrentDestXYZ[2]) & 0x80000000
|
||
#define GLI_M_CullYMax() (*(long *)&GetY(CurrentDestXYZ[0]) > fY_CMP_Optimize) && (*(long *)&GetY(CurrentDestXYZ[1]) > fY_CMP_Optimize) && (*(long *)&GetY(CurrentDestXYZ[2]) > fY_CMP_Optimize)
|
||
|
||
GLI_FuncNodeBegin(GLI_bCullingXMax_XMin)
|
||
{
|
||
if (GLI_M_CullXMin()) GLI_M_TriangleIsOut() ;
|
||
if (GLI_M_CullXMax()) GLI_M_TriangleIsOut() ;
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
GLI_FuncNodeBegin(GLI_bCullingXMax)
|
||
{
|
||
if (GLI_M_CullXMax()) GLI_M_TriangleIsOut() ;
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
GLI_FuncNodeBegin(GLI_bCullingXMin)
|
||
{
|
||
if (GLI_M_CullXMin()) GLI_M_TriangleIsOut() ;
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
GLI_FuncNodeBegin(GLI_bCullingYMax_YMin)
|
||
{
|
||
if (GLI_M_CullYMin()) GLI_M_TriangleIsOut() ;
|
||
if (GLI_M_CullYMax()) GLI_M_TriangleIsOut() ;
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
GLI_FuncNodeBegin(GLI_bCullingYMax)
|
||
{
|
||
if (GLI_M_CullYMax()) GLI_M_TriangleIsOut() ;
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
GLI_FuncNodeBegin(GLI_bCullingYMin)
|
||
{
|
||
if (GLI_M_CullYMax()) GLI_M_TriangleIsOut() ;
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
GLI_FuncNodeBegin(GLI_bCullingXYALL)
|
||
{
|
||
if (GLI_M_CullXMin()) GLI_M_TriangleIsOut() ;
|
||
if (GLI_M_CullYMin()) GLI_M_TriangleIsOut() ;
|
||
if (GLI_M_CullXMax()) GLI_M_TriangleIsOut() ;
|
||
if (GLI_M_CullYMax()) GLI_M_TriangleIsOut() ;
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* First function*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
GLI_FuncNodeBegin(GLI_vComputeXYZ)
|
||
{
|
||
/* After this function, no index from the element should be used...*/
|
||
GLI_tdstAligned2DVector *p_ScreenPoint;
|
||
p_ScreenPoint = GLI_BIG_GLOBALS->GLI_ScreenPoint+p_stCurrentTriangle->a3_xIndex[0];
|
||
SetX(CurrentDestXYZ[0],p_ScreenPoint->xX);
|
||
SetY(CurrentDestXYZ[0],p_ScreenPoint->xY);
|
||
SetZ(CurrentDestXYZ[0],p_ScreenPoint->xOoZ);
|
||
SetPackedColor(CurrentDestXYZ[0],p_ScreenPoint->ulPackedColor );
|
||
p_ScreenPoint = GLI_BIG_GLOBALS->GLI_ScreenPoint+p_stCurrentTriangle->a3_xIndex[1];
|
||
SetX(CurrentDestXYZ[1],p_ScreenPoint->xX);
|
||
SetY(CurrentDestXYZ[1],p_ScreenPoint->xY);
|
||
SetZ(CurrentDestXYZ[1],p_ScreenPoint->xOoZ);
|
||
SetPackedColor(CurrentDestXYZ[1],p_ScreenPoint->ulPackedColor );
|
||
p_ScreenPoint = GLI_BIG_GLOBALS->GLI_ScreenPoint+p_stCurrentTriangle->a3_xIndex[2];
|
||
SetX(CurrentDestXYZ[2],p_ScreenPoint->xX);
|
||
SetY(CurrentDestXYZ[2],p_ScreenPoint->xY);
|
||
SetZ(CurrentDestXYZ[2],p_ScreenPoint->xOoZ);
|
||
SetPackedColor(CurrentDestXYZ[2],p_ScreenPoint->ulPackedColor );
|
||
/*d_stVirtualUV[0] = p_stCurrentElementIndexedTriangle -> d_stListOfElementUV + p_stCurrentTriangleUV -> a3_xIndex[0];*/
|
||
/*d_stVirtualUV[1] = p_stCurrentElementIndexedTriangle -> d_stListOfElementUV + p_stCurrentTriangleUV -> a3_xIndex[1];*/
|
||
/*d_stVirtualUV[2] = p_stCurrentElementIndexedTriangle -> d_stListOfElementUV + p_stCurrentTriangleUV -> a3_xIndex[2];*/
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* second function : eventually set specular color*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
GLI_FuncNodeBegin(GLI_vSetSpecular)
|
||
{
|
||
/* After this function, no index from the element should be used...*/
|
||
SetPackedSpecular( CurrentDestXYZ[0], *((unsigned long *) GLI_BIG_GLOBALS->GLI_aDEF_stColorsRLIS + p_stCurrentTriangle->a3_xIndex[0]) );
|
||
SetPackedSpecular( CurrentDestXYZ[1], *((unsigned long *) GLI_BIG_GLOBALS->GLI_aDEF_stColorsRLIS + p_stCurrentTriangle->a3_xIndex[1]) );
|
||
SetPackedSpecular( CurrentDestXYZ[2], *((unsigned long *) GLI_BIG_GLOBALS->GLI_aDEF_stColorsRLIS + p_stCurrentTriangle->a3_xIndex[2]) );
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* Z Clipping*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
#define GLI_M_BuildPointIO( Des, Index, Index2 )\
|
||
{\
|
||
p_stLocalZClipVertex1 = (GLI_BIG_GLOBALS -> GLI_TurnedScaledDisplecedPoint + p_stCurrentTriangle -> a3_xIndex[Index]);\
|
||
p_stLocalZClipVertex2 = (GLI_BIG_GLOBALS -> GLI_TurnedScaledDisplecedPoint + p_stCurrentTriangle -> a3_xIndex[Index2]);\
|
||
/*fZClipLocalCoef = ( GLI_C_xZClippingNear - p_stLocalZClipVertex1 -> xZ ) / (p_stLocalZClipVertex2 -> xZ - p_stLocalZClipVertex1 -> xZ);*/\
|
||
fZClipLocalCoef = ( GLI_BIG_GLOBALS->p_stCurrentCamera->xNear - p_stLocalZClipVertex1 -> xZ ) / (p_stLocalZClipVertex2 -> xZ - p_stLocalZClipVertex1 -> xZ);\
|
||
stLocalZClipVertex.xX = p_stLocalZClipVertex1 -> xX + (p_stLocalZClipVertex2 -> xX - p_stLocalZClipVertex1 -> xX) * fZClipLocalCoef;\
|
||
stLocalZClipVertex.xY = p_stLocalZClipVertex1 -> xY + (p_stLocalZClipVertex2 -> xY - p_stLocalZClipVertex1 -> xY) * fZClipLocalCoef;\
|
||
stLocalZClipVertex.xZ = GLI_BIG_GLOBALS -> fZClipping;\
|
||
GLI_MDRV_vSerialProjection( GLI_BIG_GLOBALS -> p_stCurrentCamera , 1 , &stLocalZClipVertex , &stLocalZProjVertex);\
|
||
SetX(LocalTab[Des],stLocalZProjVertex.xX); \
|
||
SetY(LocalTab[Des],stLocalZProjVertex.xY); \
|
||
SetZ(LocalTab[Des],stLocalZProjVertex.xOoZ); \
|
||
SetPackedColor(LocalTab[Des],GLI_ulInterpol2PackedColor(GetPackedColor(CurrentDestXYZ[Index]),GetPackedColor(CurrentDestXYZ[Index2]),fZClipLocalCoef)) ;\
|
||
SetPackedSpecular(LocalTab[Des],GLI_ulInterpol2PackedColor(GetPackedSpecular(CurrentDestXYZ[Index]),GetPackedSpecular(CurrentDestXYZ[Index2]),fZClipLocalCoef)) ;\
|
||
SetU(LocalTab[Des],(d_stVirtualUV[Index]) -> xU + ((d_stVirtualUV[Index2]) -> xU - (d_stVirtualUV[Index]) -> xU) * fZClipLocalCoef ); \
|
||
SetV(LocalTab[Des],(d_stVirtualUV[Index]) -> xV + ((d_stVirtualUV[Index2]) -> xV - (d_stVirtualUV[Index]) -> xV) * fZClipLocalCoef ); \
|
||
}
|
||
#define BLincheuZ( aws, bws, cws)\
|
||
{\
|
||
CurrentDestXYZ[0] = LocalTab[aws];\
|
||
CurrentDestXYZ[1] = LocalTab[bws];\
|
||
CurrentDestXYZ[2] = LocalTab[cws];\
|
||
d_stVirtualUV[0] = (ACP_tdst2DUVValues *)&GetU(LocalTab[aws]);\
|
||
d_stVirtualUV[1] = (ACP_tdst2DUVValues *)&GetU(LocalTab[bws]);\
|
||
d_stVirtualUV[2] = (ACP_tdst2DUVValues *)&GetU(LocalTab[cws]);\
|
||
GLI_M_RestoreCW()\
|
||
}
|
||
GLI_FuncNodeBegin(GLI_vZClipping)
|
||
{
|
||
if (((*(unsigned long *)&GetZ(CurrentDestXYZ[0]) ) | (*(unsigned long *)&GetZ(CurrentDestXYZ[1]) ) | (*(unsigned long *)&GetZ(CurrentDestXYZ[2]) )) & 0x80000000 )
|
||
{
|
||
GLI_tdstAligned3DVector stLocalZClipVertex,*p_stLocalZClipVertex1,*p_stLocalZClipVertex2;
|
||
GLI_tdstAligned2DVector stLocalZProjVertex;
|
||
float fZClipLocalCoef;
|
||
GLI_tdScreenVertx LocalTab[4];
|
||
unsigned long ZState,Zcounter,ZCounterLast,ZBuilder;
|
||
ACP_tdxIndex NewVertices ;
|
||
|
||
/* ZClipping*/
|
||
NewVertices = GLI_BIG_GLOBALS -> p_stObj -> xNbPoints;
|
||
ZState = ((*(unsigned long *)&GetZ(CurrentDestXYZ[2])) >> 31 ) ;
|
||
for ( ZBuilder = 0 , ZCounterLast = 2 , Zcounter = 0 ; Zcounter < 3 ; ZCounterLast = Zcounter , Zcounter ++ )
|
||
{
|
||
ZState = ((*(unsigned long *)&GetZ(CurrentDestXYZ[Zcounter])) >> 31) | (ZState<<1); /* Kepp the sign*/
|
||
switch ( ZState & 3 )
|
||
{
|
||
case 2: /*Come in*/
|
||
GLI_M_BuildPointIO( ZBuilder , Zcounter , ZCounterLast );
|
||
ZBuilder++;
|
||
case 0: /*Stay in*/
|
||
LocalTab[ZBuilder] = CurrentDestXYZ[Zcounter];
|
||
*(ACP_tdst2DUVValues *)&GetU(LocalTab[ZBuilder]) = *d_stVirtualUV[Zcounter];
|
||
ZBuilder++;
|
||
break;
|
||
case 1: /*Go out*/
|
||
GLI_M_BuildPointIO( ZBuilder , ZCounterLast , Zcounter );
|
||
ZBuilder++;
|
||
case 3: /*Stay out*/
|
||
break;
|
||
}
|
||
}
|
||
if (ZBuilder == 4)
|
||
{
|
||
BLincheuZ( 0, 2, 3);
|
||
GLI_M_CallNextFuncAndSave();
|
||
BLincheuZ( 0, 1, 2);
|
||
GLI_M_CallNextFunc();
|
||
} else
|
||
{
|
||
if (ZBuilder == 3)
|
||
{
|
||
BLincheuZ( 0, 1, 2);
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* Mirror Clipping*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
#define GLI_M_BuildPointIOMirror( Index, Index2 )\
|
||
{\
|
||
p_stLocalZClipVertex1 = (GLI_BIG_GLOBALS -> GLI_TurnedScaledDisplecedPoint + p_stCurrentTriangle -> a3_xIndex[Index]);\
|
||
p_stLocalZClipVertex2 = (GLI_BIG_GLOBALS -> GLI_TurnedScaledDisplecedPoint + p_stCurrentTriangle -> a3_xIndex[Index2]);\
|
||
p_stLocalZClipVertex->xX = p_stLocalZClipVertex1 -> xX + (p_stLocalZClipVertex2 -> xX - p_stLocalZClipVertex1 -> xX) * fZClipLocalCoef;\
|
||
p_stLocalZClipVertex->xY = p_stLocalZClipVertex1 -> xY + (p_stLocalZClipVertex2 -> xY - p_stLocalZClipVertex1 -> xY) * fZClipLocalCoef;\
|
||
p_stLocalZClipVertex->xZ = p_stLocalZClipVertex1 -> xZ + (p_stLocalZClipVertex2 -> xZ - p_stLocalZClipVertex1 -> xZ) * fZClipLocalCoef;\
|
||
xLocalRestoreRefraction = MTH3D_M_xDotProductVector( (MTH3D_tdstVector *)p_stLocalZClipVertex , (MTH3D_tdstVector *)&GLI_BIG_GLOBALS->stWaterPlanNormale) - GLI_BIG_GLOBALS->xWaterPlaneDistance;\
|
||
p_stLocalZClipVertex->xX -= GLI_BIG_GLOBALS->stWaterPlanNormale.xX * xLocalRestoreRefraction;\
|
||
p_stLocalZClipVertex->xY -= GLI_BIG_GLOBALS->stWaterPlanNormale.xY * xLocalRestoreRefraction;\
|
||
p_stLocalZClipVertex->xZ -= GLI_BIG_GLOBALS->stWaterPlanNormale.xZ * xLocalRestoreRefraction;\
|
||
/* GLI_vInformWaterNoise(p_stLocalZClipVertex,GLI_BIG_GLOBALS);*/\
|
||
/* GLI_xSerialProjection ( GLI_BIG_GLOBALS -> p_stCurrentCamera , 1 , p_stLocalZClipVertex , p_stLocalZProjVertex);*/\
|
||
SetX(LocalTab[ZBuilder],p_stLocalZProjVertex->xX); \
|
||
SetY(LocalTab[ZBuilder],p_stLocalZProjVertex->xY); \
|
||
SetZ(LocalTab[ZBuilder],p_stLocalZProjVertex->xOoZ); \
|
||
/*fInvZ[ZBuilder] = 1.0f / GetZ(LocalTab[ZBuilder]);*/\
|
||
SetPackedColor(LocalTab[ZBuilder],GLI_ulInterpol2PackedColor(GetPackedColor(CurrentDestXYZ[Index]),GetPackedColor(CurrentDestXYZ[Index2]),fZClipLocalCoef * GetZ(CurrentDestXYZ[Index2]) / GetZ(LocalTab[ZBuilder]) )) ;\
|
||
SetPackedSpecular(LocalTab[ZBuilder],GLI_ulInterpol2PackedColor(GetPackedSpecular(CurrentDestXYZ[Index]),GetPackedSpecular(CurrentDestXYZ[Index2]),fZClipLocalCoef * GetZ(CurrentDestXYZ[Index2]) / GetZ(LocalTab[ZBuilder]) )) ;\
|
||
SetU(LocalTab[ZBuilder],(d_stVirtualUV[Index]) -> xU + ((d_stVirtualUV[Index2]) -> xU - (d_stVirtualUV[Index]) -> xU) * fZClipLocalCoef ); \
|
||
SetV(LocalTab[ZBuilder],(d_stVirtualUV[Index]) -> xV + ((d_stVirtualUV[Index2]) -> xV - (d_stVirtualUV[Index]) -> xV) * fZClipLocalCoef ); \
|
||
Index_LocalTab[ZBuilder++] = NewVertices++;\
|
||
p_stLocalZClipVertex++;\
|
||
p_stLocalZProjVertex++;\
|
||
}
|
||
#define BLincheuMirror( aws, bws, cws)\
|
||
{\
|
||
p_stCurrentTriangle -> a3_xIndex[0] = Index_LocalTab[aws];\
|
||
p_stCurrentTriangle -> a3_xIndex[1] = Index_LocalTab[bws];\
|
||
p_stCurrentTriangle -> a3_xIndex[2] = Index_LocalTab[cws];\
|
||
CurrentDestXYZ[0] = LocalTab[aws];\
|
||
CurrentDestXYZ[1] = LocalTab[bws];\
|
||
CurrentDestXYZ[2] = LocalTab[cws];\
|
||
GLI_M_RestoreCW();\
|
||
d_stVirtualUV[0] = (ACP_tdst2DUVValues *)&GetU(LocalTab[aws]);\
|
||
d_stVirtualUV[1] = (ACP_tdst2DUVValues *)&GetU(LocalTab[bws]);\
|
||
d_stVirtualUV[2] = (ACP_tdst2DUVValues *)&GetU(LocalTab[cws]);\
|
||
}
|
||
GLI_FuncNodeBegin(GLI_FastMirrorCLipping)
|
||
{
|
||
long K;
|
||
K = ((*(unsigned long *)(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[0])>>31) + (*(unsigned long *)(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[1])>>31) + (*(unsigned long *)(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[2])>>31));
|
||
if ((K != 3) && (K != 0))
|
||
{
|
||
GEO_tdstTripledIndex stNewCurrentTriangle;
|
||
GEO_tdstTripledIndex *p_stCurrentTriangleSave;
|
||
|
||
float xLocalRestoreRefraction;
|
||
GLI_tdstAligned3DVector *p_stLocalZClipVertex;
|
||
GLI_tdstAligned3DVector *p_stLocalZClipVertex1;
|
||
GLI_tdstAligned3DVector *p_stLocalZClipVertex2;
|
||
GLI_tdstAligned2DVector *p_stLocalZProjVertex;
|
||
float fZClipLocalCoef,LastWaterDepth,WaterDepth;
|
||
GLI_tdScreenVertx LocalTab[4];
|
||
ACP_tdxIndex Index_LocalTab[4],NewVertices ;
|
||
unsigned long ZState,Zcounter,ZCounterLast,ZBuilder;
|
||
|
||
|
||
NewVertices = GLI_BIG_GLOBALS-> p_stObj -> xNbPoints;
|
||
p_stCurrentTriangleSave = p_stCurrentTriangle ;
|
||
p_stLocalZClipVertex = GLI_BIG_GLOBALS -> GLI_TurnedScaledDisplecedPoint + NewVertices;
|
||
p_stLocalZProjVertex = GLI_BIG_GLOBALS -> GLI_ScreenPoint + NewVertices;
|
||
LastWaterDepth = *(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[2]);
|
||
ZState = (*(unsigned long *)&LastWaterDepth) >> 31 ;
|
||
for ( ZBuilder = 0 , ZCounterLast = 2 , Zcounter = 0 ; Zcounter < 3 ; ZCounterLast = Zcounter , Zcounter ++ )
|
||
{
|
||
WaterDepth = *(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[Zcounter]);
|
||
ZState = ((*(unsigned long *)&WaterDepth) >> 31) | (ZState<<1); /* Kepp the sign*/
|
||
switch ( ZState & 3 )
|
||
{
|
||
case 2: /*Come in*/
|
||
fZClipLocalCoef = WaterDepth / ( WaterDepth - LastWaterDepth );
|
||
GLI_M_BuildPointIOMirror( Zcounter , ZCounterLast );
|
||
case 0: /*Stay in*/
|
||
LocalTab[ZBuilder] = CurrentDestXYZ[Zcounter];
|
||
Index_LocalTab[ZBuilder] = p_stCurrentTriangle -> a3_xIndex[Zcounter];
|
||
*(ACP_tdst2DUVValues *)&GetU(LocalTab[ZBuilder]) = *d_stVirtualUV[Zcounter];
|
||
/*fInvZ[XYBuilder] = 1.0f / GetZ(LocalTab[XYBuilder]);*/
|
||
ZBuilder++;
|
||
break;
|
||
case 1: /*Go out*/
|
||
fZClipLocalCoef = LastWaterDepth / ( LastWaterDepth - WaterDepth ) ;
|
||
GLI_M_BuildPointIOMirror( ZCounterLast , Zcounter );
|
||
case 3: /*Stay out*/
|
||
break;
|
||
}
|
||
LastWaterDepth = WaterDepth;
|
||
}
|
||
p_stCurrentTriangle = &stNewCurrentTriangle;
|
||
if (ZBuilder == 4)
|
||
{
|
||
BLincheuMirror( 0 , 2 , 3 );
|
||
GLI_M_CallNextFuncAndSave();
|
||
BLincheuMirror( 0 , 1 , 2 );
|
||
GLI_M_CallNextFunc();
|
||
} else
|
||
{
|
||
BLincheuMirror( 0 , 1 , 2 );
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
p_stCurrentTriangle = p_stCurrentTriangleSave ;
|
||
return;
|
||
}
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* XY Clipping*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
#define GLI_M_BuildPointIOXY( Index, Index2 )\
|
||
{\
|
||
SetX(LocalTab[XYBuilder],GetX(CurrentDestXYZ[Index ]) + (GetX(CurrentDestXYZ[Index2 ]) - GetX(CurrentDestXYZ[Index ])) * fXYClipLocalCoef ); \
|
||
SetY(LocalTab[XYBuilder],GetY(CurrentDestXYZ[Index ]) + (GetY(CurrentDestXYZ[Index2 ]) - GetY(CurrentDestXYZ[Index ])) * fXYClipLocalCoef ); \
|
||
SetZ(LocalTab[XYBuilder],GetZ(CurrentDestXYZ[Index ]) + (GetZ(CurrentDestXYZ[Index2 ]) - GetZ(CurrentDestXYZ[Index ])) * fXYClipLocalCoef ); \
|
||
fInvZ[XYBuilder] = 1.0f / GetZ(LocalTab[XYBuilder]);\
|
||
GLI_M_restorePerfectClipping();\
|
||
SetPackedColor(LocalTab[XYBuilder],GLI_ulInterpol2PackedColor(GetPackedColor(CurrentDestXYZ[Index ]),GetPackedColor(CurrentDestXYZ[Index2]),fXYClipLocalCoef * GetZ(CurrentDestXYZ[Index2]) * fInvZ[XYBuilder] )) ;\
|
||
SetPackedSpecular(LocalTab[XYBuilder],GLI_ulInterpol2PackedColor(GetPackedSpecular(CurrentDestXYZ[Index ]),GetPackedSpecular(CurrentDestXYZ[Index2]),fXYClipLocalCoef * GetZ(CurrentDestXYZ[Index2]) * fInvZ[XYBuilder] )) ;\
|
||
stUV[XYBuilder].xU = (d_stVirtualUV[Index]) -> xU + ((d_stVirtualUV[Index2]) -> xU - (d_stVirtualUV[Index]) -> xU) * fXYClipLocalCoef ; \
|
||
stUV[XYBuilder].xV = (d_stVirtualUV[Index]) -> xV + ((d_stVirtualUV[Index2]) -> xV - (d_stVirtualUV[Index]) -> xV) * fXYClipLocalCoef ; \
|
||
}\
|
||
|
||
#define BLincheuYMin( aws, bws, cws)\
|
||
{\
|
||
CurrentDestXYZ[0] = LocalTab[aws];\
|
||
CurrentDestXYZ[1] = LocalTab[bws];\
|
||
CurrentDestXYZ[2] = LocalTab[cws];\
|
||
GLI_M_RestoreCW();\
|
||
d_stVirtualUV[0] = &stUV[aws];\
|
||
d_stVirtualUV[1] = &stUV[bws];\
|
||
d_stVirtualUV[2] = &stUV[cws];\
|
||
}\
|
||
|
||
/*VLNG*/
|
||
/*
|
||
J'ai chang<6E>
|
||
fXYClipLocalCoef = MTH_M_xInvLow(GetZ(LocalTab[XYcounter]));\
|
||
en
|
||
fXYClipLocalCoef = 1.0f / GetZ(LocalTab[XYcounter]);\
|
||
*/
|
||
/*EVL*/
|
||
#define GLI_M_ScreenClipping()\
|
||
if (K == 0)\
|
||
{\
|
||
GLI_M_CallNextFunc();\
|
||
return;\
|
||
}else\
|
||
{\
|
||
float fXYClipLocalCoef,CurrentXY,LastXY;\
|
||
GLI_tdScreenVertx LocalTab[4];\
|
||
unsigned long XYState,XYcounter,XYCounterLast,XYBuilder;\
|
||
float fInvZ[4];\
|
||
ACP_tdst2DUVValues stUV[4];\
|
||
for ( XYcounter = 0 ; XYcounter < 3 ; XYcounter ++ )\
|
||
{\
|
||
stUV[XYcounter+1].xU = d_stVirtualUV[XYcounter]->xU * GetZ(CurrentDestXYZ[XYcounter]);\
|
||
stUV[XYcounter+1].xV = d_stVirtualUV[XYcounter]->xV * GetZ(CurrentDestXYZ[XYcounter]);\
|
||
d_stVirtualUV[XYcounter] = &stUV[XYcounter+1];\
|
||
}\
|
||
XYcounter = 2;\
|
||
LastXY = ComputeCurrentXY();\
|
||
XYState = (*(unsigned long *)&LastXY) >> 31 ;\
|
||
for ( XYBuilder = 0 , XYCounterLast = 2 , XYcounter = 0 ; XYcounter < 3 ; XYCounterLast = XYcounter , XYcounter ++ )\
|
||
{\
|
||
CurrentXY = ComputeCurrentXY();\
|
||
XYState = ((*(unsigned long *)&CurrentXY) >> 31) | (XYState<<1); \
|
||
switch ( XYState & 3 )\
|
||
{\
|
||
case 2: \
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );\
|
||
GLI_M_BuildPointIOXY( XYcounter , XYCounterLast );\
|
||
XYBuilder++;\
|
||
case 0: \
|
||
LocalTab[XYBuilder] = CurrentDestXYZ[XYcounter];\
|
||
stUV[XYBuilder] = *d_stVirtualUV[XYcounter];\
|
||
fInvZ[XYBuilder] = 1.0f / GetZ(LocalTab[XYBuilder]);\
|
||
XYBuilder++;\
|
||
break;\
|
||
case 1: \
|
||
fXYClipLocalCoef = LastXY / ( LastXY - CurrentXY ) ;\
|
||
GLI_M_BuildPointIOXY( XYCounterLast , XYcounter );\
|
||
XYBuilder++;\
|
||
case 3: \
|
||
break;\
|
||
}\
|
||
LastXY = CurrentXY;\
|
||
}\
|
||
for ( XYcounter = 0 ; XYcounter < XYBuilder ; XYcounter ++ )\
|
||
{\
|
||
/*fXYClipLocalCoef = 1.0f / GetZ(LocalTab[XYcounter]);*/\
|
||
stUV[XYcounter].xU = stUV[XYcounter].xU * fInvZ[XYcounter];\
|
||
stUV[XYcounter].xV = stUV[XYcounter].xV * fInvZ[XYcounter];\
|
||
}\
|
||
if (XYBuilder == 4)\
|
||
{\
|
||
BLincheuYMin( 0 , 2 , 3 );\
|
||
GLI_M_CallNextFuncAndSave();\
|
||
BLincheuYMin( 0 , 1 , 2 );\
|
||
GLI_M_CallNextFunc();\
|
||
} else\
|
||
if (XYBuilder == 3)\
|
||
{\
|
||
BLincheuYMin( 0 , 1 , 2 );\
|
||
GLI_M_CallNextFunc();\
|
||
} \
|
||
return;\
|
||
}
|
||
/* ----------------------------------------------------------------------------------------------*/
|
||
/* CLIPPING X MIN */
|
||
|
||
#undef ComputeCurrentXY
|
||
#define ComputeCurrentXY() GetX(CurrentDestXYZ[XYcounter]) - *(float *)&fXMin_CLIP_Optimize
|
||
#undef GLI_M_restorePerfectClipping
|
||
#define GLI_M_restorePerfectClipping() SetX(LocalTab[XYBuilder],*(float *)&fXMin_CLIP_Optimize);
|
||
GLI_FuncNodeBegin(GLI_XMinCLipping)
|
||
{
|
||
unsigned long K;
|
||
K = (((unsigned long )((*((long *)&GetX(CurrentDestXYZ[0])) - fXMin_CLIP_Optimize))) >> 31) | (*((unsigned long *)&GetX(CurrentDestXYZ[0])) >> 31);
|
||
K += (((unsigned long )((*((long *)&GetX(CurrentDestXYZ[1])) - fXMin_CLIP_Optimize))) >> 31) | (*((unsigned long *)&GetX(CurrentDestXYZ[1])) >> 31);
|
||
K += (((unsigned long )((*((long *)&GetX(CurrentDestXYZ[2])) - fXMin_CLIP_Optimize))) >> 31) | (*((unsigned long *)&GetX(CurrentDestXYZ[2])) >> 31);
|
||
GLI_M_ScreenClipping();
|
||
}
|
||
/* ----------------------------------------------------------------------------------------------*/
|
||
/* CLIPPING Y MIN */
|
||
|
||
#undef ComputeCurrentXY
|
||
#define ComputeCurrentXY() GetY(CurrentDestXYZ[XYcounter]) - *(float *)&fYMin_CLIP_Optimize
|
||
#undef GLI_M_restorePerfectClipping
|
||
#define GLI_M_restorePerfectClipping() SetY(LocalTab[XYBuilder],*(float *)&fYMin_CLIP_Optimize);
|
||
GLI_FuncNodeBegin(GLI_YMinCLipping)
|
||
{
|
||
unsigned long K;
|
||
K = (((unsigned long )((*((long *)&GetY(CurrentDestXYZ[0])) - fYMin_CLIP_Optimize))) >> 31) | (*((unsigned long *)&GetY(CurrentDestXYZ[0])) >> 31);
|
||
K += (((unsigned long )((*((long *)&GetY(CurrentDestXYZ[1])) - fYMin_CLIP_Optimize))) >> 31) | (*((unsigned long *)&GetY(CurrentDestXYZ[1])) >> 31);
|
||
K += (((unsigned long )((*((long *)&GetY(CurrentDestXYZ[2])) - fYMin_CLIP_Optimize))) >> 31) | (*((unsigned long *)&GetY(CurrentDestXYZ[2])) >> 31);
|
||
GLI_M_ScreenClipping();
|
||
}
|
||
/* ----------------------------------------------------------------------------------------------*/
|
||
/* CLIPPING X MAX */
|
||
|
||
#undef ComputeCurrentXY
|
||
#define ComputeCurrentXY() *(float *)&fXMax_CLIP_Optimize - GetX(CurrentDestXYZ[XYcounter])
|
||
#undef GLI_M_restorePerfectClipping
|
||
#define GLI_M_restorePerfectClipping() SetX(LocalTab[XYBuilder],*(float *)&fXMax_CLIP_Optimize );
|
||
GLI_FuncNodeBegin(GLI_XMaxCLipping)
|
||
{
|
||
long K;
|
||
K = (((unsigned long )(fXMax_CLIP_Optimize - (*((long *)&GetX(CurrentDestXYZ[0]))))) >> 31) | (*((unsigned long *)&GetX(CurrentDestXYZ[0])) >> 31);
|
||
K += (((unsigned long )(fXMax_CLIP_Optimize - (*((long *)&GetX(CurrentDestXYZ[1]))))) >> 31) | (*((unsigned long *)&GetX(CurrentDestXYZ[1])) >> 31);
|
||
K += (((unsigned long )(fXMax_CLIP_Optimize - (*((long *)&GetX(CurrentDestXYZ[2]))))) >> 31) | (*((unsigned long *)&GetX(CurrentDestXYZ[2])) >> 31);
|
||
GLI_M_ScreenClipping();
|
||
}
|
||
|
||
/* ----------------------------------------------------------------------------------------------*/
|
||
/* CLIPPING Y MAX */
|
||
|
||
#undef ComputeCurrentXY
|
||
#define ComputeCurrentXY() *(float *)&fYMax_CLIP_Optimize - GetY(CurrentDestXYZ[XYcounter])
|
||
#undef GLI_M_restorePerfectClipping
|
||
#define GLI_M_restorePerfectClipping() SetY(LocalTab[XYBuilder],*(float *)&fYMax_CLIP_Optimize);
|
||
GLI_FuncNodeBegin(GLI_YMaxCLipping)
|
||
{
|
||
/*static int mytest = 1;*/
|
||
|
||
long K;
|
||
K = (((unsigned long )(fYMax_CLIP_Optimize - (*((long *)&GetY(CurrentDestXYZ[0]))))) >> 31) | (*((unsigned long *)&GetY(CurrentDestXYZ[0])) >> 31);
|
||
K += (((unsigned long )(fYMax_CLIP_Optimize - (*((long *)&GetY(CurrentDestXYZ[1]))))) >> 31) | (*((unsigned long *)&GetY(CurrentDestXYZ[1])) >> 31);
|
||
K += (((unsigned long )(fYMax_CLIP_Optimize - (*((long *)&GetY(CurrentDestXYZ[2]))))) >> 31) | (*((unsigned long *)&GetY(CurrentDestXYZ[2])) >> 31);
|
||
GLI_M_ScreenClipping();
|
||
/*
|
||
if (!mytest)
|
||
{
|
||
GLI_M_ScreenClipping();
|
||
}
|
||
else
|
||
{
|
||
if (K == 0)
|
||
{
|
||
GLI_M_CallNextFunc();
|
||
return;
|
||
}
|
||
else if (K == 3)
|
||
{
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
float fXYClipLocalCoef,CurrentXY,LastXY;
|
||
GLI_tdScreenVertx LocalTab[4];
|
||
unsigned long XYcounter,XYBuilder;
|
||
ACP_tdst2DUVValues stUV[4];
|
||
|
||
for ( XYcounter = 0 ; XYcounter < 3 ; XYcounter ++ )
|
||
{
|
||
stUV[XYcounter+1].xU = d_stVirtualUV[XYcounter]->xU * GetZ(CurrentDestXYZ[XYcounter]);
|
||
stUV[XYcounter+1].xV = d_stVirtualUV[XYcounter]->xV * GetZ(CurrentDestXYZ[XYcounter]);
|
||
d_stVirtualUV[XYcounter] = &stUV[XYcounter+1];
|
||
}
|
||
|
||
|
||
if (K == 1) /* un seul <20> l'ext<78>rieur, g<>n<EFBFBD>re deux triangles */
|
||
/*
|
||
{
|
||
XYcounter = 0;
|
||
LastXY = ComputeCurrentXY();
|
||
if ( (*(unsigned long *)&LastXY) >> 31 )
|
||
{
|
||
XYBuilder = 0;
|
||
XYcounter = 2;
|
||
CurrentXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 2, 0);
|
||
|
||
XYBuilder = 1;
|
||
XYcounter = 1;
|
||
CurrentXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 1, 0);
|
||
|
||
LocalTab[2] = CurrentDestXYZ[1];
|
||
//stUV[2] = *d_stVirtualUV[1];
|
||
LocalTab[3] = CurrentDestXYZ[2];
|
||
//stUV[3] = *d_stVirtualUV[2];
|
||
}
|
||
else
|
||
{
|
||
XYcounter = 1;
|
||
LastXY = ComputeCurrentXY();
|
||
if ( (*(unsigned long *)&LastXY) >> 31 )
|
||
{
|
||
LocalTab[0] = CurrentDestXYZ[0];
|
||
stUV[0] = *d_stVirtualUV[0];
|
||
|
||
XYBuilder = 1;
|
||
XYcounter = 0;
|
||
CurrentXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 0, 1);
|
||
|
||
XYBuilder = 2;
|
||
XYcounter = 2;
|
||
CurrentXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 2, 1);
|
||
|
||
LocalTab[3] = CurrentDestXYZ[2];
|
||
//stUV[XYBuilder] = *d_stVirtualUV[2];
|
||
}
|
||
else
|
||
{
|
||
XYcounter = 2;
|
||
LastXY = ComputeCurrentXY();
|
||
|
||
XYBuilder = 0;
|
||
XYcounter = 0;
|
||
CurrentXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 0, 2);
|
||
|
||
LocalTab[1] = CurrentDestXYZ[0];
|
||
//stUV[1] = *d_stVirtualUV[0];
|
||
LocalTab[2] = CurrentDestXYZ[1];
|
||
//stUV[XYBuilder] = *d_stVirtualUV[1];
|
||
|
||
XYBuilder = 3;
|
||
XYcounter = 1;
|
||
CurrentXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 1, 2);
|
||
}
|
||
}
|
||
|
||
for ( XYcounter = 0 ; XYcounter < 4; XYcounter ++ )
|
||
{
|
||
fXYClipLocalCoef = 1.0f / GetZ(LocalTab[XYcounter]);
|
||
stUV[XYcounter].xU = stUV[XYcounter].xU * fXYClipLocalCoef;
|
||
stUV[XYcounter].xV = stUV[XYcounter].xV * fXYClipLocalCoef;
|
||
}
|
||
|
||
BLincheuYMin( 0 , 2 , 3 );
|
||
GLI_M_CallNextFuncAndSave();
|
||
BLincheuYMin( 0 , 1 , 2 );
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
else /* deux <20> l'ext<78>rieur */
|
||
/* {
|
||
XYcounter = 0;
|
||
CurrentXY = ComputeCurrentXY();
|
||
if ( !((*(unsigned long *)&CurrentXY) >> 31 ) )
|
||
{
|
||
XYBuilder = 0;
|
||
XYcounter = 2;
|
||
LastXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 0, 2);
|
||
|
||
LocalTab[1] = CurrentDestXYZ[0];
|
||
//stUV[1] = *d_stVirtualUV[0];
|
||
|
||
XYBuilder = 2;
|
||
XYcounter = 1;
|
||
LastXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 0, 1);
|
||
}
|
||
else
|
||
{
|
||
XYcounter = 1;
|
||
CurrentXY = ComputeCurrentXY();
|
||
if ( !((*(unsigned long *)&CurrentXY) >> 31 ) ) // vertex 1 in other out
|
||
{
|
||
XYBuilder = 0;
|
||
XYcounter = 0;
|
||
LastXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 1, 0);
|
||
|
||
LocalTab[1] = CurrentDestXYZ[1];
|
||
stUV[1] = *d_stVirtualUV[1];
|
||
|
||
XYBuilder = 2;
|
||
XYcounter = 2;
|
||
LastXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 1, 2);
|
||
}
|
||
else //vertex2 is in, other out
|
||
{
|
||
XYcounter = 2;
|
||
CurrentXY = ComputeCurrentXY();
|
||
|
||
XYBuilder = 0;
|
||
XYcounter = 0;
|
||
LastXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 2, 0);
|
||
|
||
XYBuilder = 1;
|
||
XYcounter = 1;
|
||
LastXY = ComputeCurrentXY();
|
||
fXYClipLocalCoef = CurrentXY / ( CurrentXY - LastXY );
|
||
GLI_M_BuildPointIOXY( 2, 1);
|
||
|
||
LocalTab[2] = CurrentDestXYZ[2];
|
||
stUV[2] = *d_stVirtualUV[2];
|
||
}
|
||
}
|
||
|
||
for ( XYcounter = 0 ; XYcounter < 3; XYcounter ++ )
|
||
{
|
||
fXYClipLocalCoef = 1.0f / GetZ(LocalTab[XYcounter]);
|
||
stUV[XYcounter].xU = stUV[XYcounter].xU * fXYClipLocalCoef;
|
||
stUV[XYcounter].xV = stUV[XYcounter].xV * fXYClipLocalCoef;
|
||
}
|
||
|
||
BLincheuYMin( 0 , 1 , 2 );
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
*/
|
||
}
|
||
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
/* Water Clipping*/
|
||
/* ------------------------------------------------------------------------------------------------*/
|
||
|
||
#define GLI_M_BuildPointIOWater( Index, Index2 )\
|
||
{\
|
||
p_stLocalZClipVertex1 = (GLI_BIG_GLOBALS -> GLI_TurnedScaledDisplecedPoint + p_stCurrentTriangle -> a3_xIndex[Index]);\
|
||
p_stLocalZClipVertex2 = (GLI_BIG_GLOBALS -> GLI_TurnedScaledDisplecedPoint + p_stCurrentTriangle -> a3_xIndex[Index2]);\
|
||
p_stLocalZClipVertex->xX = p_stLocalZClipVertex1 -> xX + (p_stLocalZClipVertex2 -> xX - p_stLocalZClipVertex1 -> xX) * fZClipLocalCoef;\
|
||
p_stLocalZClipVertex->xY = p_stLocalZClipVertex1 -> xY + (p_stLocalZClipVertex2 -> xY - p_stLocalZClipVertex1 -> xY) * fZClipLocalCoef;\
|
||
p_stLocalZClipVertex->xZ = p_stLocalZClipVertex1 -> xZ + (p_stLocalZClipVertex2 -> xZ - p_stLocalZClipVertex1 -> xZ) * fZClipLocalCoef;\
|
||
xLocalRestoreRefraction = MTH3D_M_xDotProductVector( (MTH3D_tdstVector *)p_stLocalZClipVertex , (MTH3D_tdstVector *)&GLI_BIG_GLOBALS->stWaterPlanNormale) - GLI_BIG_GLOBALS->xWaterPlaneDistance;\
|
||
p_stLocalZClipVertex->xX -= GLI_BIG_GLOBALS->stWaterPlanNormale.xX * xLocalRestoreRefraction;\
|
||
p_stLocalZClipVertex->xY -= GLI_BIG_GLOBALS->stWaterPlanNormale.xY * xLocalRestoreRefraction;\
|
||
p_stLocalZClipVertex->xZ -= GLI_BIG_GLOBALS->stWaterPlanNormale.xZ * xLocalRestoreRefraction;\
|
||
/*GLI_vInformWaterNoise(p_stLocalZClipVertex,GLI_BIG_GLOBALS);*/\
|
||
GLI_MDRV_vSerialProjection( GLI_BIG_GLOBALS -> p_stCurrentCamera , 1 , p_stLocalZClipVertex , p_stLocalZProjVertex);\
|
||
SetX(LocalTab[ZBuilder],p_stLocalZProjVertex->xX); \
|
||
SetY(LocalTab[ZBuilder],p_stLocalZProjVertex->xY); \
|
||
SetZ(LocalTab[ZBuilder],p_stLocalZProjVertex->xOoZ); \
|
||
SetX(LocalTabSub[ZBuilderSub],p_stLocalZProjVertex->xX); \
|
||
SetY(LocalTabSub[ZBuilderSub],p_stLocalZProjVertex->xY); \
|
||
SetZ(LocalTabSub[ZBuilderSub],p_stLocalZProjVertex->xOoZ); \
|
||
SetPackedColor(LocalTab[ZBuilder],GLI_ulInterpol2PackedColor(GetPackedColor(CurrentDestXYZ[Index]),GetPackedColor(CurrentDestXYZ[Index2]),fZClipLocalCoef * GetZ(CurrentDestXYZ[Index2]) / GetZ(LocalTab[ZBuilder])) );\
|
||
SetPackedColor(LocalTabSub[ZBuilderSub],GetPackedColor(LocalTab[ZBuilder])) ;\
|
||
SetU(LocalTab[ZBuilder],(d_stVirtualUV[Index]) -> xU + ((d_stVirtualUV[Index2]) -> xU - (d_stVirtualUV[Index]) -> xU) * fZClipLocalCoef ); \
|
||
SetV(LocalTab[ZBuilder],(d_stVirtualUV[Index]) -> xV + ((d_stVirtualUV[Index2]) -> xV - (d_stVirtualUV[Index]) -> xV) * fZClipLocalCoef ); \
|
||
SetU(LocalTabSub[ZBuilderSub],(d_stVirtualUV[Index]) -> xU + ((d_stVirtualUV[Index2]) -> xU - (d_stVirtualUV[Index]) -> xU) * fZClipLocalCoef ); \
|
||
SetV(LocalTabSub[ZBuilderSub],(d_stVirtualUV[Index]) -> xV + ((d_stVirtualUV[Index2]) -> xV - (d_stVirtualUV[Index]) -> xV) * fZClipLocalCoef ); \
|
||
Index_LocalTabSub[ZBuilderSub++] = NewVertices;\
|
||
Index_LocalTab[ZBuilder++] = NewVertices++;\
|
||
p_stLocalZClipVertex++;\
|
||
p_stLocalZProjVertex++;\
|
||
}
|
||
#define BLincheuWater( aws, bws, cws)\
|
||
{\
|
||
p_stCurrentTriangle -> a3_xIndex[0] = Index_LocalTab[aws];\
|
||
p_stCurrentTriangle -> a3_xIndex[1] = Index_LocalTab[bws];\
|
||
p_stCurrentTriangle -> a3_xIndex[2] = Index_LocalTab[cws];\
|
||
CurrentDestXYZ[0] = LocalTab[aws];\
|
||
CurrentDestXYZ[1] = LocalTab[bws];\
|
||
CurrentDestXYZ[2] = LocalTab[cws];\
|
||
GLI_M_RestoreCW();\
|
||
d_stVirtualUV[0] = (ACP_tdst2DUVValues *)&GetU(LocalTab[aws]);\
|
||
d_stVirtualUV[1] = (ACP_tdst2DUVValues *)&GetU(LocalTab[bws]);\
|
||
d_stVirtualUV[2] = (ACP_tdst2DUVValues *)&GetU(LocalTab[cws]);\
|
||
}
|
||
#define BLincheuWaterSub( aws, bws, cws)\
|
||
{\
|
||
p_stCurrentTriangle -> a3_xIndex[0] = Index_LocalTabSub[aws];\
|
||
p_stCurrentTriangle -> a3_xIndex[1] = Index_LocalTabSub[bws];\
|
||
p_stCurrentTriangle -> a3_xIndex[2] = Index_LocalTabSub[cws];\
|
||
CurrentDestXYZ[0] = LocalTabSub[aws];\
|
||
CurrentDestXYZ[1] = LocalTabSub[bws];\
|
||
CurrentDestXYZ[2] = LocalTabSub[cws];\
|
||
GLI_M_RestoreCW();\
|
||
d_stVirtualUV[0] = (ACP_tdst2DUVValues *)&GetU(LocalTabSub[aws]);\
|
||
d_stVirtualUV[1] = (ACP_tdst2DUVValues *)&GetU(LocalTabSub[bws]);\
|
||
d_stVirtualUV[2] = (ACP_tdst2DUVValues *)&GetU(LocalTabSub[cws]);\
|
||
}
|
||
GLI_FuncNodeBegin(GLI_FastWaterCLipping)
|
||
{
|
||
long K;
|
||
K = ((*(unsigned long *)(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[0])>>31) + (*(unsigned long *)(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[1])>>31) + (*(unsigned long *)(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[2])>>31));
|
||
if ((K != 3) && (K != 0))
|
||
{
|
||
GEO_tdstTripledIndex stNewCurrentTriangle;
|
||
GEO_tdstTripledIndex *p_stCurrentTriangleSave;
|
||
|
||
float xLocalRestoreRefraction;
|
||
GLI_tdstAligned3DVector *p_stLocalZClipVertex;
|
||
GLI_tdstAligned3DVector *p_stLocalZClipVertex1;
|
||
GLI_tdstAligned3DVector *p_stLocalZClipVertex2;
|
||
GLI_tdstAligned2DVector *p_stLocalZProjVertex;
|
||
float fZClipLocalCoef,LastWaterDepth,WaterDepth;
|
||
GLI_tdScreenVertx LocalTab[4];
|
||
ACP_tdxIndex Index_LocalTab[4],NewVertices ;
|
||
GLI_tdScreenVertx LocalTabSub[4];
|
||
ACP_tdxIndex Index_LocalTabSub[4];
|
||
unsigned long ZState,Zcounter,ZCounterLast,ZBuilder,ZBuilderSub;
|
||
|
||
NewVertices = GLI_BIG_GLOBALS-> p_stObj -> xNbPoints;
|
||
p_stCurrentTriangleSave = p_stCurrentTriangle ;
|
||
p_stLocalZClipVertex = GLI_BIG_GLOBALS -> GLI_TurnedScaledDisplecedPoint + NewVertices;
|
||
p_stLocalZProjVertex = GLI_BIG_GLOBALS -> GLI_ScreenPoint + NewVertices;
|
||
LastWaterDepth = *(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[2]);
|
||
ZState = (*(unsigned long *)&LastWaterDepth) >> 31 ;
|
||
for ( ZBuilder = 0 , ZBuilderSub = 0 , ZCounterLast = 2 , Zcounter = 0 ; Zcounter < 3 ; ZCounterLast = Zcounter , Zcounter ++ )
|
||
{
|
||
WaterDepth = *(GLI_BIG_GLOBALS -> GLI_aDEF_xWaterPlaneDepth + p_stCurrentTriangle -> a3_xIndex[Zcounter]);
|
||
ZState = ((*(unsigned long *)&WaterDepth) >> 31) | (ZState<<1); /* Kepp the sign*/
|
||
switch ( ZState & 3 )
|
||
{
|
||
case 2: /*Come in*/
|
||
fZClipLocalCoef = WaterDepth / ( WaterDepth - LastWaterDepth );
|
||
GLI_M_BuildPointIOWater( Zcounter , ZCounterLast );
|
||
case 0: /*Stay in*/
|
||
LocalTab[ZBuilder] = CurrentDestXYZ[Zcounter];
|
||
Index_LocalTab[ZBuilder] = p_stCurrentTriangle -> a3_xIndex[Zcounter];
|
||
*(ACP_tdst2DUVValues *)&GetU(LocalTab[ZBuilder]) = *d_stVirtualUV[Zcounter];
|
||
ZBuilder++;
|
||
break;
|
||
case 1: /*Go out*/
|
||
fZClipLocalCoef = LastWaterDepth / ( LastWaterDepth - WaterDepth ) ;
|
||
GLI_M_BuildPointIOWater( ZCounterLast , Zcounter );
|
||
case 3: /*Stay out*/
|
||
LocalTabSub[ZBuilderSub] = CurrentDestXYZ[Zcounter];
|
||
Index_LocalTabSub[ZBuilderSub] = p_stCurrentTriangle -> a3_xIndex[Zcounter];
|
||
*(ACP_tdst2DUVValues *)&GetU(LocalTabSub[ZBuilderSub]) = *d_stVirtualUV[Zcounter];
|
||
ZBuilderSub++;
|
||
break;
|
||
}
|
||
LastWaterDepth = WaterDepth;
|
||
}
|
||
p_stCurrentTriangle = &stNewCurrentTriangle;
|
||
if (ZBuilder == 4)
|
||
{
|
||
BLincheuWater( 0 , 2 , 3 );
|
||
GLI_M_CallNextFuncAndSave();
|
||
BLincheuWater( 0 , 1 , 2 );
|
||
GLI_M_CallNextFuncAndSave();
|
||
BLincheuWaterSub( 0 , 1 , 2 );
|
||
GLI_M_CallNextFunc();
|
||
} else
|
||
{
|
||
BLincheuWaterSub( 0 , 2 , 3 );
|
||
GLI_M_CallNextFuncAndSave();
|
||
BLincheuWaterSub( 0 , 1 , 2 );
|
||
GLI_M_CallNextFuncAndSave();
|
||
BLincheuWater( 0 , 1 , 2 );
|
||
GLI_M_CallNextFunc();
|
||
}
|
||
p_stCurrentTriangle = p_stCurrentTriangleSave ;
|
||
return;
|
||
}
|
||
GLI_M_CallNextFunc();
|
||
}
|