#include "shtypes.h" #include "matrix.h" #include "shmatrix.h" #include "shmath.h" #include "logger.h" Matrix sp2MtrxStk[MATRIX_STK_DEPTH]; Matrix *sp2CTM; Matrix *sp2SP; XYZ matxLightVector; void sh2InitMatrixStack (void) { LOG( BEGIN, sh2InitMatrixStack, 0 ); sp2SP = &sp2MtrxStk[0]; initMatrixStack (&sp2SP, &sp2CTM); LOG( END, sh2InitMatrixStack, 0 ); } void sh2ClearMatrix() { LOG( BEGIN, sh2ClearMatrix, sp2CTM ) clearMatrix( sp2CTM ); LOG( END, sh2ClearMatrix, 0 ) } void sh2PushMatrix ( void ) { LOG( BEGIN, sh2PushMatrix, 0 ); pushmatrix(&sp2SP, &sp2CTM); LOG( END, sh2PushMatrix, 0 ); } void sh2PopMatrix (void) { LOG( BEGIN, sh2PopMatrix, 0 ); popmatrix(&sp2SP, &sp2CTM); LOG( END, sh2PopMatrix, 0 ); } void sh2RotateX ( Fixed32 angle ) { LOG( BEGIN, sh2RotateX, angle ); rotateX (sp2CTM, SIN(angle), COS(angle)); LOG( END, sh2RotateX, 0 ); } void sh2RotateY ( Fixed32 angle ) { LOG( BEGIN, sh2RotateY, angle ); rotateY (sp2CTM, SIN(angle), COS(angle)); LOG( END, sh2RotateY, 0 ); } void sh2RotateZ ( Fixed32 angle ) { LOG( BEGIN, sh2RotateZ, angle ); rotateZ (sp2CTM, SIN(angle), COS(angle)); LOG( END, sh2RotateZ, 0 ); } void sh2Scale ( Fixed32 dx, Fixed32 dy ) { LOG( BEGIN, sh2Scale, dx ); scale (sp2CTM, dx, dy); LOG( END, sh2Scale, dy ); } void sh2Move ( Fixed32 dx, Fixed32 dy, Fixed32 dz ) { LOG( BEGIN, sh2Move, dx ); translate ( sp2CTM, dx, dy, dz ); LOG( END, sh2Move, dy ); } /*------------------------------------------------------------------------ * * NAME : sh2CoordTrans * * 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 sh2CoordTrans(XYZ *src, XYZ *ans) { LOG( BEGIN, sh2CoordTrans, src ) coordTrans( sp2CTM, src, ans); LOG( END, sh2CoordTrans, ans ) return; } /*------------------------------------------------------------------------ * * NAME : sh2NormalTrans * * 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 sh2NormalTrans(XYZ *src, XYZ *ans) { Fixed32 *pts; Fixed32 *ptMatrix; Fixed32 *ptn; LOG( BEGIN, sh2NormalTrans, src ) normalTrans( sp2CTM, src, ans); LOG( END, sh2NormalTrans, 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