// FILE: helpers.c #include #include #include "3d\compatib.h" #include "3d\gdi3d.h" #include "3d\intern.h" #include "3d\globals.h" #include "3d\helpers.h" /* PROJECT: GDI3D DLL PROGRAMMER(S): Pasi Paavola COMPILER: Microsoft C/C++ 7.0 ENVIRONMENT: Windows 3.1 running on 386/33/SuperVGA/no 80x87; 386 enhanced mode ROUTINES: Private helper routines for GDI3D */ #define MAXSINES 359 // iSineVals array contains the sine values in the range [0 ... MAXSINES] // degrees (in 1 degree steps). These values are not the original sine values, // but the values got as the real values are multiplied by // 2^(bits in int - 2) int iSineVals[360] = { 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334, 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, 8192, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365, 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043, 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295, 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082, 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381, 16384, 16381, 16374, 16361, 16344, 16321, 16294, 16261, 16224, 16182, 16135, 16082, 16025, 15964, 15897, 15825, 15749, 15668, 15582, 15491, 15395, 15295, 15190, 15081, 14967, 14848, 14725, 14598, 14466, 14329, 14188, 14043, 13894, 13740, 13582, 13420, 13254, 13084, 12910, 12732, 12550, 12365, 12175, 11982, 11785, 11585, 11381, 11173, 10963, 10748, 10531, 10310, 10086, 9860, 9630, 9397, 9161, 8923, 8682, 8438, 8191, 7943, 7691, 7438, 7182, 6924, 6663, 6401, 6137, 5871, 5603, 5334, 5062, 4790, 4516, 4240, 3963, 3685, 3406, 3126, 2845, 2563, 2280, 1996, 1712, 1427, 1142, 857, 571, 285, 0, -285, -571, -857, -1142, -1427, -1712, -1996, -2280, -2563, -2845, -3126, -3406, -3685, -3963, -4240, -4516, -4790, -5062, -5334, -5603, -5871, -6137, -6401, -6663, -6924, -7182, -7438, -7691, -7943, -8192, -8438, -8682, -8923, -9161, -9397, -9630, -9860, -10086, -10310, -10531, -10748, -10963, -11173, -11381, -11585, -11785, -11982, -12175, -12365, -12550, -12732, -12910, -13084, -13254, -13420, -13582, -13740, -13894, -14043, -14188, -14329, -14466, -14598, -14725, -14848, -14967, -15081, -15190, -15295, -15395, -15491, -15582, -15668, -15749, -15825, -15897, -15964, -16025, -16082, -16135, -16182, -16224, -16261, -16294, -16321, -16344, -16361, -16374, -16381, -16384, -16381, -16374, -16361, -16344, -16321, -16294, -16261, -16224, -16182, -16135, -16082, -16025, -15964, -15897, -15825, -15749, -15668, -15582, -15491, -15395, -15295, -15190, -15081, -14967, -14848, -14725, -14598, -14466, -14329, -14188, -14043, -13894, -13740, -13582, -13420, -13254, -13084, -12910, -12732, -12550, -12365, -12175, -11982, -11785, -11585, -11381, -11173, -10963, -10748, -10531, -10310, -10086, -9860, -9630, -9397, -9161, -8923, -8682, -8438, -8191, -7943, -7691, -7438, -7182, -6924, -6663, -6401, -6137, -5871, -5603, -5334, -5062, -4790, -4516, -4240, -3963, -3685, -3406, -3126, -2845, -2563, -2280, -1996, -1712, -1427, -1142, -857, -571, -285 }; //////////////////////////////////////////////////////////////////////////// /* SIN() returns sine of its argument scaled (multiplied) by SCALE constant. Parameter Description iDeg Angle in degrees (can be negative and > 360) Returns The scaled sine value as an integer */ //////////////////////////////////////////////////////////////////////////// //__inline int SIN(int iDeg) { if (abs(iDeg) > MAXSINES) iDeg %= (MAXSINES+1); if (iDeg >= 0) return iSineVals[iDeg]; else return -iSineVals[abs(iDeg)]; } //////////////////////////////////////////////////////////////////////////// /* COS() returns cosine of its argument scaled (multiplied) by SCALE constant. Parameter Description iDeg Angle in degrees (can be negative and > 360) Returns The scaled cosine value as an integer */ //////////////////////////////////////////////////////////////////////////// //__inline int COS(int iDeg) { return SIN(90 - iDeg); } //////////////////////////////////////////////////////////////////////////// /* IsG3Window() checks whether the window identified by the given handle belongs to GDI3D class. Parameter Description hWnd Handle of the window to check Returns TRUE if the window belongs to GDI3D class, otherwise FALSE Comments */ //////////////////////////////////////////////////////////////////////////// BOOL IsG3Window(HWND hWnd) { if (hWnd == NULL) return FALSE; if (!GetClassName(hWnd, GszScratch, MAXSCR)) return FALSE; // Invalid handle if (lstrcmpi(GszScratch, G3CLASSNAME)) return FALSE; // Not the same class return TRUE; } //////////////////////////////////////////////////////////////////////////// /* G3ToViewport() converts a 3D point to viewport point presentation. Parameter Description x, y, z 3D point coordinates Returns Viewport point Comments */ //////////////////////////////////////////////////////////////////////////// POINT G3ToViewport(double x, double y, double z) { double xe, ye, ze; // eye coordinates POINT p; double oldx, oldy, oldz; // Calculate transformations if (GpParams->iTrFlag) { // apply some transformations if (GpParams->iTrFlag & TM_SCALE) { // implied by rotate oldx = x; oldy = y; oldz = z; x *= GpParams->M11; y *= GpParams->M22; z *= GpParams->M33; } if (GpParams->iTrFlag & TM_ROTATE) { // rotation (Not all // terms need to be calc'd // because calc'd already // in SCALE phase) x += GpParams->M12 * oldy + GpParams->M13 * oldz; y += GpParams->M21 * oldx + GpParams->M23 * oldz; z += GpParams->M31 * oldx + GpParams->M32 * oldy; } if (GpParams->iTrFlag & TM_TRANS) { // translation (order is important // tr. has to be last) x += GpParams->M14; y += GpParams->M24; z += GpParams->M34; } } // Convert to eye coordinates xe = -x * GpParams->SinTheta + y * GpParams->CosTheta; ye = -x * GpParams->CtCf - y * GpParams->StCf + z * GpParams->SinFi; ze = -x * GpParams->CtSf - y * GpParams->StSf - z * GpParams->CosFi + GpParams->r; if (ze != 0.0) { p.x = (int) ((GpParams->dS1) * (xe / ze) * GpParams->hw) + GpParams->cx; p.y = (int) ((GpParams->dS2) * (ye / ze) * GpParams->hh) + GpParams->cy; } else { p.x = 0; p.y = 0; } return p; }