200 lines
8.8 KiB
C
200 lines
8.8 KiB
C
/*
|
|
Tested with LINT
|
|
*/
|
|
#define MTH_LOW
|
|
|
|
#include"gli_st.h"
|
|
#include "GLI_Defn.h"
|
|
#include "vertex.h"
|
|
#include "light_st.h"
|
|
#include "PvObj_st.h"
|
|
#include "camera.h"
|
|
#include "dllcom.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
|
|
void GLI_DRV_vAddScrZ()
|
|
{
|
|
GLI_tdScreenVertx *pFirst , *pLast;
|
|
pFirst = GLI_ScreenVertices;
|
|
pLast = pFirst + GLI_BIG_GLOBALS->p_stObj->xNbPoints ;
|
|
for ( ; pFirst < pLast ; pFirst++)
|
|
PSetZ(pFirst, (PGetZ(pFirst) + 0.0001f));
|
|
}
|
|
|
|
|
|
void GLI_DRV_vMulScrZ()
|
|
{
|
|
GLI_tdScreenVertx *pFirst , *pLast;
|
|
pFirst = GLI_ScreenVertices;
|
|
pLast = pFirst + GLI_BIG_GLOBALS->p_stObj->xNbPoints ;
|
|
for ( ; pFirst < pLast ; pFirst++)
|
|
PSetZ(pFirst, (PGetZ(pFirst) * 30.0f));
|
|
}
|
|
|
|
|
|
/**********************************************************************************************/
|
|
/* Name: GLI_xSerialDotProduct */
|
|
/* Goal: */
|
|
/* Code: Philippe Vimont / 1.0*/
|
|
/* OPTIMMIZED : Is also in assembly pentium*/
|
|
/**********************************************************************************************/
|
|
static _inline void
|
|
GLI_xSerialDotProduct (long lNbOfVertex ,MTH3D_tdstVector *p_stSource ,float *p_stDest ,MTH3D_tdstVector *p_stMultiplicator, long lIncrement)
|
|
{
|
|
long lVertexIndex ;
|
|
for ( lVertexIndex = 0 ; lVertexIndex < lNbOfVertex ; lVertexIndex ++ , p_stSource++,p_stDest ++)
|
|
*p_stDest = MTH_M_xRealToFloat ( MTH3D_M_xDotProductVector( p_stSource,p_stMultiplicator) ) ;
|
|
}
|
|
|
|
|
|
|
|
void
|
|
GLI_DRV_vSerialLinearProjZClip ( GLI_tdstInternalGlobalValuesFor3dEngine *GLI_BG )
|
|
{
|
|
GLI_tdstAligned3DVector *p_stDest;
|
|
GLI_tdstAligned3DVector *p_stLastDest;
|
|
GLI_tdstAligned2DVector *p_st2DDest;
|
|
GLI_tdScreenVertx *p_stScrDest;
|
|
MTH3D_tdstVector stX,stY,stZ,stTrans;
|
|
float fSwapValue,fScaleX,fScaleY;
|
|
MTH3D_tdstVector *p_stSource ;
|
|
long lNewX;
|
|
*(float * )&lNewX = 8000.0f;
|
|
fScaleX = GLI_BG -> p_stCurrentCamera -> xScreen * GLI_BG -> p_stCurrentCamera -> stScale . xX ;
|
|
fScaleY = GLI_BG -> p_stCurrentCamera -> xScreen * GLI_BG -> p_stCurrentCamera -> stScale . xY ;
|
|
POS_MDRV_vGetTransformMatrix( &GLI_BG -> gs_st_CurrentMatrixMultiplyedWithCameraMatrix , &stX , &stY , &stZ);
|
|
GLI_M_SWAP (stX.xY,stY.xX);
|
|
GLI_M_SWAP (stX.xZ,stZ.xX);
|
|
GLI_M_SWAP (stY.xZ,stZ.xY);
|
|
POS_MDRV_vGetTranslationVector (&GLI_BG->gs_st_CurrentMatrixMultiplyedWithCameraMatrix , &stTrans);
|
|
p_stDest = GLI_BG -> GLI_TurnedScaledDisplecedPoint;
|
|
p_st2DDest = GLI_BG->GLI_ScreenPoint;
|
|
p_stScrDest = GLI_ScreenVertices;
|
|
p_stSource = GLI_BG->p_stObj->d_stListOfPoints ;
|
|
p_stLastDest = p_stDest + GLI_BG -> p_stObj -> xNbPoints;
|
|
for ( ; p_stDest < p_stLastDest ; p_stDest ++ , p_stSource++ , p_st2DDest++ , p_stScrDest++)
|
|
{
|
|
float fTmpZ;
|
|
p_stDest->xZ = MTH3D_M_xDotProductVector ( &stZ , p_stSource ) + stTrans . xZ;
|
|
p_stDest->xX = MTH3D_M_xDotProductVector ( &stX , p_stSource ) + stTrans . xX;
|
|
p_stDest->xY = MTH3D_M_xDotProductVector ( &stY , p_stSource ) + stTrans . xY;
|
|
if ( *(long *)&p_stDest->xZ < *(long *)&GLI_BG -> p_stCurrentCamera -> xNear)
|
|
{
|
|
float tmpFloat;
|
|
*(long *)&p_st2DDest -> xOoZ |= 0x80000000;
|
|
*((unsigned long *)&p_st2DDest ->xX) = lNewX | ((*((unsigned long *)&p_stDest->xX) & 0x80000000) ^ 0x80000000);
|
|
*((unsigned long *)&p_st2DDest ->xY) = lNewX | ((*((unsigned long *)&p_stDest->xY) & 0x80000000) ^ 0x80000000);
|
|
*((unsigned long *)&tmpFloat) = lNewX | ((*((unsigned long *)&p_stDest->xX) & 0x80000000) ^ 0x80000000);
|
|
PSetX(p_stScrDest, tmpFloat);
|
|
*((unsigned long *)&tmpFloat) = lNewX | ((*((unsigned long *)&p_stDest->xY) & 0x80000000) ^ 0x80000000);
|
|
PSetY(p_stScrDest, tmpFloat);
|
|
*((unsigned long *)&tmpFloat) = (0x80000000 | *(unsigned long*) &(PGetZ(p_stScrDest)));
|
|
PSetZ(p_stScrDest, tmpFloat);
|
|
continue ;
|
|
}
|
|
/* fTmpZ = MTH_M_xInvLow(p_stDest->xZ);*/
|
|
fTmpZ = 1.0f / p_stDest->xZ;
|
|
PSetX(p_stScrDest, GLI_BG->p_stCurrentCamera->stTrans.xX + p_stDest->xX * fScaleX * fTmpZ);
|
|
PSetY(p_stScrDest, GLI_BG->p_stCurrentCamera->stTrans.xY + p_stDest->xY * fScaleY * fTmpZ);
|
|
PSetZ(p_stScrDest, fTmpZ * GLI_BG->p_stCurrentCamera->xNear);
|
|
p_st2DDest->xX = GLI_BG -> p_stCurrentCamera -> stTrans . xX + p_stDest -> xX * fScaleX * fTmpZ;
|
|
p_st2DDest->xY = GLI_BG -> p_stCurrentCamera -> stTrans . xY + p_stDest -> xY * fScaleY * fTmpZ;
|
|
p_st2DDest->xOoZ = fTmpZ * GLI_BG -> p_stCurrentCamera -> xNear ;
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
GLI_DRV_vSerialLinearProjNoZClip ( GLI_tdstInternalGlobalValuesFor3dEngine *GLI_BG )
|
|
{
|
|
GLI_tdstAligned3DVector *p_stDest;
|
|
GLI_tdstAligned3DVector *p_stLastDest;
|
|
GLI_tdstAligned2DVector *p_st2DDest;
|
|
GLI_tdScreenVertx *p_stScrDest;
|
|
MTH3D_tdstVector stX,stY,stZ,stTrans;
|
|
float fSwapValue,fScaleX,fScaleY;
|
|
MTH3D_tdstVector *p_stSource ;
|
|
fScaleX = GLI_BG -> p_stCurrentCamera->xScreen * GLI_BG -> p_stCurrentCamera -> stScale . xX ;
|
|
fScaleY = GLI_BG -> p_stCurrentCamera->xScreen * GLI_BG -> p_stCurrentCamera -> stScale . xY ;
|
|
POS_MDRV_vGetTransformMatrix (&GLI_BG->gs_st_CurrentMatrixMultiplyedWithCameraMatrix , &stX , &stY , &stZ);
|
|
GLI_M_SWAP (stX.xY,stY.xX);
|
|
GLI_M_SWAP (stX.xZ,stZ.xX);
|
|
GLI_M_SWAP (stY.xZ,stZ.xY);
|
|
POS_MDRV_vGetTranslationVector (&GLI_BG->gs_st_CurrentMatrixMultiplyedWithCameraMatrix, &stTrans);
|
|
p_stDest = GLI_BG -> GLI_TurnedScaledDisplecedPoint;
|
|
p_st2DDest = GLI_BG -> GLI_ScreenPoint;
|
|
p_stScrDest = GLI_ScreenVertices;
|
|
p_stSource = GLI_BG -> p_stObj->d_stListOfPoints ;
|
|
p_stLastDest = p_stDest + GLI_BG -> p_stObj -> xNbPoints;
|
|
for ( ; p_stDest < p_stLastDest ; p_stDest ++ , p_stSource++ , p_st2DDest++ , p_stScrDest++)
|
|
{
|
|
float fTmpZ;
|
|
p_stDest->xZ = MTH3D_M_xDotProductVector ( &stZ , p_stSource ) + stTrans . xZ;
|
|
p_stDest->xX = MTH3D_M_xDotProductVector ( &stX , p_stSource ) + stTrans . xX;
|
|
p_stDest->xY = MTH3D_M_xDotProductVector ( &stY , p_stSource ) + stTrans . xY;
|
|
/* fTmpZ = MTH_M_xInvLow(p_stDest->xZ);*/
|
|
fTmpZ = 1.0f / p_stDest->xZ;
|
|
/* TODO: don't copy this information*/
|
|
PSetX(p_stScrDest, GLI_BG->p_stCurrentCamera->stTrans.xX + p_stDest -> xX * fScaleX * fTmpZ);
|
|
PSetY(p_stScrDest, GLI_BG->p_stCurrentCamera->stTrans.xY + p_stDest -> xY * fScaleY * fTmpZ);
|
|
PSetZ(p_stScrDest, fTmpZ * GLI_BG->p_stCurrentCamera->xNear );
|
|
p_st2DDest -> xX = GLI_BG->p_stCurrentCamera->stTrans.xX + p_stDest -> xX * fScaleX * fTmpZ;
|
|
p_st2DDest -> xY = GLI_BG->p_stCurrentCamera->stTrans.xY + p_stDest -> xY * fScaleY * fTmpZ;
|
|
p_st2DDest -> xOoZ = fTmpZ * GLI_BG->p_stCurrentCamera->xNear ;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* STM- this function is currently broken, but not used.*/
|
|
/* if we add water plane effects we'll have to fix this function to write to */
|
|
/* GLI_ScreenVertices*/
|
|
#if 0
|
|
void GLI_xNewSerialProjOp ( GLI_tdstInternalGlobalValuesFor3dEngine *GLI_BG )
|
|
{
|
|
GLI_tdstAligned3DVector *p_stDest;
|
|
GLI_tdstAligned3DVector *p_stLastDest;
|
|
GLI_tdstAligned2DVector *p_st2DDest;
|
|
float /*fSwapValue,*/fScaleX,fScaleY;
|
|
long lNewX;
|
|
*(float * )&lNewX = 8000.0f;
|
|
fScaleX = GLI_BG -> p_stCurrentCamera -> xScreen * GLI_BG -> p_stCurrentCamera -> stScale . xX ;
|
|
fScaleY = GLI_BG -> p_stCurrentCamera -> xScreen * GLI_BG -> p_stCurrentCamera -> stScale . xY ;
|
|
p_stDest = GLI_BG -> GLI_TurnedScaledDisplecedPoint;
|
|
p_st2DDest = GLI_BG -> GLI_ScreenPoint;
|
|
p_stLastDest = p_stDest + GLI_BG -> p_stObj -> xNbPoints;
|
|
if (GLI_BG -> lClippingModeMask & GLI_C_ClipMaskZ)
|
|
for ( ; p_stDest < p_stLastDest ; p_stDest ++ , p_st2DDest++ )
|
|
{
|
|
if ( *(long *)&p_stDest->xZ < *(long *)&GLI_BG -> p_stCurrentCamera -> xNear)
|
|
{
|
|
*(long *)&p_st2DDest -> xOoZ |= 0x80000000;
|
|
*((unsigned long *)&p_st2DDest ->xX) = lNewX | ((*((unsigned long *)&p_stDest->xX) & 0x80000000) ^ 0x80000000);
|
|
*((unsigned long *)&p_st2DDest ->xY) = lNewX | ((*((unsigned long *)&p_stDest->xY) & 0x80000000) ^ 0x80000000);
|
|
continue ;
|
|
}
|
|
p_st2DDest -> xOoZ = MTH_M_xInvLow(p_stDest -> xZ ) ;
|
|
p_st2DDest -> xX = GLI_BG -> p_stCurrentCamera -> stTrans . xX + p_stDest -> xX * fScaleX * p_st2DDest -> xOoZ ;
|
|
p_st2DDest -> xY = GLI_BG -> p_stCurrentCamera -> stTrans . xY + p_stDest -> xY * fScaleY * p_st2DDest -> xOoZ ;
|
|
p_st2DDest -> xOoZ *= GLI_BG -> p_stCurrentCamera -> xNear ;
|
|
}
|
|
else
|
|
for ( ; p_stDest < p_stLastDest ; p_stDest ++ , p_st2DDest++ )
|
|
{
|
|
p_st2DDest -> xOoZ = MTH_M_xInvLow(p_stDest -> xZ ) ;
|
|
p_st2DDest -> xX = GLI_BG -> p_stCurrentCamera -> stTrans . xX + p_stDest -> xX * fScaleX * p_st2DDest -> xOoZ ;
|
|
p_st2DDest -> xY = GLI_BG -> p_stCurrentCamera -> stTrans . xY + p_stDest -> xY * fScaleY * p_st2DDest -> xOoZ ;
|
|
p_st2DDest -> xOoZ *= GLI_BG -> p_stCurrentCamera -> xNear ;
|
|
}
|
|
}
|
|
#endif /* if 0*/
|
|
|
|
#ifdef __cplusplus
|
|
} /*extern "C"*/
|
|
#endif
|