TCDIRECT.CPP
资源名称:tc3d.zip [点击查看]
上传用户:abcdshs
上传日期:2007-01-07
资源大小:1858k
文件大小:4k
源码类别:
游戏
开发平台:
Visual C++
- // (C) Copyright 1996 by Anthony J. Carin. All Rights Reserved.
- #include <stdafx.h>
- #include "tcdirect.h"
- #include <math.h>
- direction& direction::operator *(float r)
- {
- static direction ret;
- ret.m_val = (short) (recalc() * r);
- return ret;
- }
- char operator<(direction& a, direction& b)
- {
- short r = (short)((a.recalc()+TC_PI2)-(b.recalc()+TC_PI2));
- if (abs(r) > TC_PI)
- {
- if (r < 0)
- r = (a+(direction) TC_PI2)-b;
- else
- r = a-(b+(direction) TC_PI2);
- }
- if (r > 0)
- return FALSE;
- return TRUE;
- }
- const float ISTEP = .01f;
- const int CSCTBLSIZ = 314;
- const int INTV = 163;
- const float TCPI = 3.14f;
- static float searchcsc(float);
- static float getangle(float x,float y);
- static const short csctbl[] =
- {32760, 16239, 8118, 5411, 4057, 3245, 2703, 2316, 2025, 1799, 1618,
- 1470, 1346, 1242, 1152, 1074, 1006, 945, 892, 844, 801, 761, 726,
- 693, 663, 635, 610, 586, 564, 544, 524, 506, 489, 473, 458, 444, 431,
- 418, 406, 394, 383, 373, 363, 353, 344, 336, 327, 319, 311, 304, 297,
- 290, 283, 276, 270, 264, 258, 253, 247, 242, 237, 232, 227, 222, 217,
- 213, 208, 204, 200, 196, 192, 188, 184, 181, 177, 173, 170, 167, 163,
- 160, 157, 154, 151, 148, 145, 142, 139, 136, 133, 131, 128, 125, 123,
- 120, 118, 115, 113, 110, 108, 106, 103, 101, 99, 97, 94, 92, 90, 88,
- 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 55,
- 53, 51, 49, 47, 46, 44, 42, 40, 39, 37, 35, 34, 32, 30, 28, 27, 25,
- 23, 22, 20, 18, 17, 15, 13, 12, 10, 9, 7, 5, 4, 2, 0, 0, -2, -4, -5,
- -7, -9, -10, -12, -13, -15, -17, -18, -20, -22, -23, -25, -27, -28,
- -30, -32, -34, -35, -37, -39, -40, -42, -44, -46, -47, -49, -51, -53,
- -55, -56, -58, -60, -62, -64, -66, -68, -70, -72, -74, -76, -78, -80,
- -82, -84, -86, -88, -90, -92, -94, -97, -99, -101, -103, -106, -108,
- -110, -113, -115, -118, -120, -123, -125, -128, -131, -133, -136,
- -139, -142, -145, -148, -151, -154, -157, -160, -163, -167, -170,
- -173, -177, -181, -184, -188, -192, -196, -200, -204, -208, -213,
- -217, -222, -227, -232, -237, -242, -247, -253, -258, -264, -270,
- -276, -283, -290, -297, -304, -311, -319, -327, -336, -344, -353,
- -363, -373, -383, -394, -406, -418, -431, -444, -458, -473, -489,
- -506, -524, -544, -564, -586, -610, -635, -663, -693, -726, -761,
- -801, -844, -892, -945, -1006, -1074, -1152, -1242, -1346, -1470,
- -1618, -1799, -2025, -2316, -2703, -3245, -4057, -5411, -8118, -16239,
- -32760};
- direction& getdirection(float ox,float oy,float px,float py)
- {
- static direction r;
- r = (short)(getangle(px-ox,py-oy)*100.0f);
- return r;
- }
- static float getangle(float x,float y)
- {
- if (x == 0) {
- if (y > 0)
- return 0.0f;
- else
- return TCPI;
- }
- float i = (searchcsc((float)y/(float)x)*TCPI)/CSCTBLSIZ;
- if (x < 0)
- i += TCPI;
- return i;
- }
- static float searchcsc(float x)
- {
- short
- e = CSCTBLSIZ,
- b = 0,
- i = (CSCTBLSIZ/2);
- long
- k = (long) (x*INTV);
- while ((e - b) > 2) {
- if (k == (long) csctbl[i])
- break;
- if (k < (long) csctbl[i]) {
- b = i;
- i = (short)((short)i + (short) (((e - b) / 2) + 1));
- }
- else {
- e = i;
- i = (short)((short)i - (short) (((e - b) / 2) + 1));
- }
- }
- return (float) i;
- }
- void createtrigtable(float *sintable, float *costable)
- {
- for (int i = 0; i < TC_PI2; i++)
- {
- sintable[i] = (float) sin((6.28*(double)i)/(double)TC_PI2);
- costable[i] = (float) cos((6.28*(double)i)/(double)TC_PI2);
- }
- }