#include "shtypes.h" #include "matrix.h" #include "shmatrix.h" #include "shmath.h" #include "logger.h" Matrix spMtrxStk[MATRIX_STK_DEPTH]; Matrix *spCTM; Matrix *spSP; XYZ matxLightVector; void shInitMatrixStack (void) { LOG( BEGIN, shInitMatrixStack, 0 ); spSP = &spMtrxStk[0]; initMatrixStack (&spSP, &spCTM); LOG( END, shInitMatrixStack, 0 ); } void shClearMatrix() { LOG( BEGIN, shClearMatrix, spCTM ) clearMatrix( spCTM ); LOG( END, shClearMatrix, 0 ) } void shPushMatrix ( void ) { LOG( BEGIN, shPushMatrix, 0 ); pushmatrix(&spSP, &spCTM); LOG( END, shPushMatrix, 0 ); } void shPopMatrix (void) { LOG( BEGIN, shPopMatrix, 0 ); popmatrix(&spSP, &spCTM); LOG( END, shPopMatrix, 0 ); } void shRotateX ( Fixed32 angle ) { LOG( BEGIN, shRotateX, angle ); rotateX (spCTM, SIN(angle), COS(angle)); LOG( END, shRotateX, 0 ); } void shRotateY ( Fixed32 angle ) { LOG( BEGIN, shRotateY, angle ); rotateY (spCTM, SIN(angle), COS(angle)); LOG( END, shRotateY, 0 ); } void shRotateZ ( Fixed32 angle ) { LOG( BEGIN, shRotateZ, angle ); rotateZ (spCTM, SIN(angle), COS(angle)); LOG( END, shRotateZ, 0 ); } void shScale ( Fixed32 dx, Fixed32 dy ) { LOG( BEGIN, shScale, dx ); scale (spCTM, dx, dy); LOG( END, shScale, dy ); } void shMove ( Fixed32 dx, Fixed32 dy, Fixed32 dz ) { LOG( BEGIN, shMove, dx ); translate ( spCTM, dx, dy, dz ); LOG( END, shMove, dy ); } /*------------------------------------------------------------------------ * * NAME : shCoordTrans * * PARAMETERS * param1 - The source coordinate to be transformed * param2 - The result of coordinate transformation * * DESCRIPTION * * | Xn | | M00, M01, M02, M03 | | Xa | | M00Xa+M01Ya+M02Za+M03 | * | Yn | = | M10, M11, M12, M13 |.| Ya | = | M10Xa+M11Ya+M12Za+M13 | * | Zn | | M20, M21, M22, M23 | | Za | | M20Xa+M21Ya+M22Za+M23 | * | 1 | | 0, 0, 0, 1 | | 1 | | 1 | * * PRECONDITIONS * * POSTCONDITIONS * * CAVEATS * *------------------------------------------------------------------------ */ void shCoordTrans(XYZ *src, XYZ *ans) { LOG( BEGIN, shCoordTrans, src ) coordTrans( spCTM, src, ans); LOG( END, shCoordTrans, ans ) return; } /*------------------------------------------------------------------------ * * NAME : shNormalTrans * * PARAMETERS * param1 - The source normal vector to be transformed * param2 - The result of normal vector transformation * * DESCRIPTION * * | Xn | | M00, M01, M02 | | Xa | | M00Xa+M01Ya+M02Za | * | Yn | = | M10, M11, M12 |.| Ya | = | M10Xa+M11Ya+M12Za | * | Zn | | M20, M21, M22 | | Za | | M20Xa+M21Ya+M22Za | * * PRECONDITIONS * * POSTCONDITIONS * * CAVEATS * *------------------------------------------------------------------------ */ void shNormalTrans(XYZ *src, XYZ *ans) { Fixed32 *pts; Fixed32 *ptMatrix; Fixed32 *ptn; LOG( BEGIN, shNormalTrans, src ) normalTrans( spCTM, src, ans); LOG( END, shNormalTrans, ans ) return; } #ifdef NOT void ComputeBrightness(XYZ *view, XYZ *norm, Sint16 *colorNo) { Uint16 n; Fixed32 product; Sint16 color; LOG( BEGIN, ComputeBrightness, norm ) if (PRODUCT(view[0], norm[0]) > 0) { /* set color (shading brightness) */ product = PRODUCT(norm[0], matxLightVector); color = FIXED_TO_INT((product + FIXED(1.0)) * (32/2)); if (color < 0) color = 0; if (color > 31) color = 31; } else color = -1; *colorNo = color; LOG( END, ComputeBrightness, view ) } void MatxLightVector(XYZ *vector) { LOG( BEGIN, MatxLightVector, vector ); matxLightVector = *vector; matxLightVector.x = - matxLightVector.x; matxLightVector.y = - matxLightVector.y; matxLightVector.z = - matxLightVector.z; LOG( END, MatxLightVector, 0 ); return; } /*------------------------------------------------------------------------ * * NAME : VertCoordTransFlat * * PARAMETERS * param1 - Number of point list element * param2 - The source flat point list data coordinate to be transformed * param3 - The result flat point list data of coordinate transformation * * DESCRIPTION * * Transform vertices coordinate. * * PRECONDITIONS * * POSTCONDITIONS * * CAVEATS * *------------------------------------------------------------------------ */ void VertCoordTransFlat(Uint16 num, FlatPoint *src, FlatPointRes *ans) { Uint16 n; XYZ viewVect, normalVect; LOG( BEGIN, VertCoordTransFlat, num ) for (n = 0; n < num; n++) { CoordTrans(&src->pt[0], &ans->pt[0]); CoordTrans(&src->pt[1], &ans->pt[1]); NormalTrans(&src->surNormal, &normalVect); viewVect.x = - ans->pt[0].x; viewVect.y = - ans->pt[0].y; viewVect.z = - ans->pt[0].z; ComputeBrightness(&viewVect,&normalVect,&ans->surColor); src++; ans++; } LOG( END, VertCoordTransFlat, ans ) } /*------------------------------------------------------------------------ * * NAME : VertCoordTransGour * * PARAMETERS * param1 - Number of point list element * param2 - The source gourau point list data coordinate to be transformed * param3 - The result gourau point list data of coordinate transformation * * DESCRIPTION * * Transform vertices coordinate. * * PRECONDITIONS * * POSTCONDITIONS * * CAVEATS * *------------------------------------------------------------------------ */ void VertCoordTransGour(Uint16 num, GourPoint *src, GourPointRes *ans) { Uint16 n; XYZ viewVect, normalVect; Fixed32 product; Sint16 color; LOG( BEGIN, VertCoordTransGour, num ) for (n = 0; n < num; n++) { CoordTrans(&src->pt[0], &ans->pt[0]); CoordTrans(&src->pt[1], &ans->pt[1]); NormalTrans(&src->surNormal, &normalVect); viewVect.x = - ans->pt[0].x; viewVect.y = - ans->pt[0].y; viewVect.z = - ans->pt[0].z; ComputeBrightness(&viewVect,&normalVect,&ans->surColor); NormalTrans(&src->ptNormal[0], &normalVect); product = PRODUCT(normalVect, matxLightVector); color = FIXED_TO_INT((product + FIXED(1.0)) * (32/2)); if (color < 0) color = 0; if (color > 31) color = 31; ans->ptColor[0] = color; NormalTrans(&src->ptNormal[1], &normalVect); product = PRODUCT(normalVect, matxLightVector); color = FIXED_TO_INT((product + FIXED(1.0)) * (32/2)); if (color < 0) color = 0; if (color > 31) color = 31; ans->ptColor[1] = color; src++; ans++; } LOG( END, VertCoordTransGour, ans ) } #endif