Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gb\gb.h>
- #include <gb\drawing.h>
- typedef unsigned int Point[2];
- typedef int Vertex[3];
- //typedef long Point[2];
- //typedef long Vertex[3];
- typedef unsigned int Line[2];
- //#define Sar(a,b) (((a)<0) ? -((-a)>>(b)) : ((a)>>(b)))
- #define Mul(a,b) (long)(a)*(b)
- #define VERTICES (8)
- #define LINES (12)
- Point projected[VERTICES];
- int cx,cy,cz,sx,sy,sz;
- long dist;
- long Sar(long a, UINT8 b)
- {
- if (a < 0U)
- return -(-(a)>>(b));
- else return (a)>>(b);
- }
- int stab[] = {
- 0, 3, 6, 9, 12, 16, 19, 22,
- 25, 28, 31, 34, 37, 40, 43, 46,
- 49, 51, 54, 57, 60, 63, 65, 68,
- 71, 73, 76, 78, 81, 83, 85, 88,
- 90, 92, 94, 96, 98, 100, 102, 104,
- 106, 107, 109, 111, 112, 113, 115, 116,
- 117, 118, 120, 121, 122, 122, 123, 124,
- 125, 125, 126, 126, 126, 127, 127, 127,
- 127, 127, 127, 127, 126, 126, 126, 125,
- 125, 124, 123, 122, 122, 121, 120, 118,
- 117, 116, 115, 113, 112, 111, 109, 107,
- 106, 104, 102, 100, 98, 96, 94, 92,
- 90, 88, 85, 83, 81, 78, 76, 73,
- 71, 68, 65, 63, 60, 57, 54, 51,
- 49, 46, 43, 40, 37, 34, 31, 28,
- 25, 22, 19, 16, 12, 9, 6, 3,
- 0, -3, -6, -9, -12, -16, -19, -22,
- -25, -28, -31, -34, -37, -40, -43, -46,
- -49, -51, -54, -57, -60, -63, -65, -68,
- -71, -73, -76, -78, -81, -83, -85, -88,
- -90, -92, -94, -96, -98, -100, -102, -104,
- -106, -107, -109, -111, -112, -113, -115, -116,
- -117, -118, -120, -121, -122, -122, -123, -124,
- -125, -125, -126, -126, -126, -127, -127, -127,
- -127, -127, -127, -127, -126, -126, -126, -125,
- -125, -124, -123, -122, -122, -121, -120, -118,
- -117, -116, -115, -113, -112, -111, -109, -107,
- -106, -104, -102, -100, -98, -96, -94, -92,
- -90, -88, -85, -83, -81, -78, -76, -73,
- -71, -68, -65, -63, -60, -57, -54, -51,
- -49, -46, -43, -40, -37, -34, -31, -28,
- -25, -22, -19, -16, -12, -9, -6, -3, c
- };
- int ctab[] = {
- 127, 127, 127, 127, 126, 126, 126, 125,
- 125, 124, 123, 122, 122, 121, 120, 118,
- 117, 116, 115, 113, 112, 111, 109, 107,
- 106, 104, 102, 100, 98, 96, 94, 92,
- 90, 88, 85, 83, 81, 78, 76, 73,
- 71, 68, 65, 63, 60, 57, 54, 51,
- 49, 46, 43, 40, 37, 34, 31, 28,
- 25, 22, 19, 16, 12, 9, 6, 3,
- 0, -3, -6, -9, -12, -16, -19, -22,
- -25, -28, -31, -34, -37, -40, -43, -46,
- -49, -51, -54, -57, -60, -63, -65, -68,
- -71, -73, -76, -78, -81, -83, -85, -88,
- -90, -92, -94, -96, -98, -100, -102, -104,
- -106, -107, -109, -111, -112, -113, -115, -116,
- -117, -118, -120, -121, -122, -122, -123, -124,
- -125, -125, -126, -126, -126, -127, -127, -127,
- -127, -127, -127, -127, -126, -126, -126, -125,
- -125, -124, -123, -122, -122, -121, -120, -118,
- -117, -116, -115, -113, -112, -111, -109, -107,
- -106, -104, -102, -100, -98, -96, -94, -92,
- -90, -88, -85, -83, -81, -78, -76, -73,
- -71, -68, -65, -63, -60, -57, -54, -51,
- -49, -46, -43, -40, -37, -34, -31, -28,
- -25, -22, -19, -16, -12, -9, -6, -3,
- -0, 3, 6, 9, 12, 16, 19, 22,
- 25, 28, 31, 34, 37, 40, 43, 46,
- 49, 51, 54, 57, 60, 63, 65, 68,
- 71, 73, 76, 78, 81, 83, 85, 88,
- 90, 92, 94, 96, 98, 100, 102, 104,
- 106, 107, 109, 111, 112, 113, 115, 116,
- 117, 118, 120, 121, 122, 122, 123, 124,
- 125, 125, 126, 126, 126, 127, 127, 127,
- };
- Vertex vertices[VERTICES] =
- {
- -32,-32,-32, // 0
- -32,-32, 32, // 1
- -32, 32,-32, // 2
- -32, 32, 32, // 3
- 32,-32,-32, // 4
- 32,-32, 32, // 5
- 32, 32,-32, // 6
- 32, 32, 32, // 7
- };
- Line lines[LINES] =
- {
- 0,4, 1,5, 2,6, 3,7,
- 0,2, 1,3, 4,6, 5,7,
- 0,1, 2,3, 4,5, 6,7,
- //0,7, 1,6, 2,5, 3,4,
- };
- //UINT8 c;
- //UINT8 d;
- //
- //long Sar(long a, UINT8 b)
- //{
- // if(a < 0)
- // {
- // c = 0U;
- // d = b;
- // //a *= -1;
- // //c = (-1 * ((a)>>(b)));
- // //return c;
- // while(d) c+=b; d--;
- // return ((a)/(d));
- // }
- // else
- // {
- // return ((a)>>(b));
- // }
- //}
- void RotateAndProject()
- {
- UINT8 v;
- for (v=0; v<VERTICES; v++)
- {
- long x1,y1,z1;
- long xx,yy;
- long zz;
- x1 = Mul(cy, vertices[v][0]) - Mul(sy, vertices[v][2]);
- x1 = Sar(x1,7U);
- z1 = Mul(sy, vertices[v][0]) + Mul(cy, vertices[v][2]);
- z1 = Sar(z1,7U);
- xx = Mul(cz, x1 ) + Mul(sz, vertices[v][1]);
- xx = Sar(xx,7U);
- y1 = Mul(cz, vertices[v][1]) - Mul(sz, x1 );
- y1 = Sar(y1,7U);
- yy = Mul(sx, z1 ) + Mul(cx, y1 );
- yy = Sar(yy,7U);
- zz = Mul(cx, z1 ) - Mul(sx, y1 );
- zz = Sar(zz,7U) + 256U;
- zz += dist;
- projected[v][0] = 80U + Sar((xx * zz),8U);
- projected[v][1] = 72U + Sar((yy * zz),8U);
- }
- }
- void DrawLines()
- {
- int L;
- for (L=0; L<LINES-0; L++)
- {
- int x1 = projected[lines[L][0]][0];
- int y1 = projected[lines[L][0]][1];
- int x2 = projected[lines[L][1]][0];
- int y2 = projected[lines[L][1]][1];
- if (y2<y1) // swap points
- {
- int t;
- t = x1; x1 = x2; x2 = t;
- t = y1; y1 = y2; y2 = t;
- }
- line(x1,y1,x2,y2);
- }
- }
- void main()
- {
- int writebank=0;
- int rx=0, ry=0, rz=0;
- dist = 0;
- //Init();
- while (1)
- {
- // UBYTE joy = joypad();
- // if (joy & J_UP) rx-=1;
- // if (joy & J_DOWN) rx+=1;
- // if (joy & J_LEFT) ry+=1;
- // if (joy & J_RIGHT) ry-=1;
- // if (joy & J_SELECT) rz+=1;
- // if (joy & J_START) rz-=1;
- // if (joy & J_A) dist-=3;
- // if (joy & J_B) dist+=3;
- rx+=1; ry+=2; rz+=2;
- cx = ctab[rx]; cy = ctab[ry]; cz = ctab[rz];
- sx = stab[rx]; sy = stab[ry]; sz = stab[rz];
- RotateAndProject();
- DrawLines();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement