home *** CD-ROM | disk | FTP | other *** search
- #include <intuition/intuitionbase.h>
- #include <graphics/gfxbase.h>
- #include <functions.h>
- #include <math.h>
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct Window *Window;
- struct IntuiMessage *Massage;
-
- struct Screen *Screen1;
- struct Screen *Screen2;
-
- struct RastPort *RPort;
-
- struct NewScreen NewScreen =
- {
- 0,0,640,400,1,
- 0,0,
- HIRES | LACE,
- CUSTOMSCREEN | SCREENQUIET,
- (struct TextAttr *)NULL,
- (STRPTR)NULL,
- (struct Gadget *)NULL,
- (struct BitMap *)NULL
- };
-
- struct NewWindow NewWindow =
- {
- 0,0,
- 640,400,
- 0,0,
- RAWKEY,
- ACTIVATE | RMBTRAP | BORDERLESS | BACKDROP,
- (struct Gadget *)NULL,
- (struct Image *)NULL,
- (STRPTR) NULL,
- (struct Screen *)NULL,
- (struct BitMap *)NULL,
- 0,0,
- 0,0,
- CUSTOMSCREEN
- };
-
- long sinus(int w);
-
- #pragma regcall(sinus(d0))
-
- #define cosinus(w) (sinus(w+256))
-
- void
- CloseAll(LONG ExitCode)
- {
- if(Window)
- CloseWindow(Window);
-
- if(Screen1)
- CloseScreen(Screen1);
-
- if(Screen2)
- CloseScreen(Screen2);
-
- if(IntuitionBase)
- CloseLibrary(IntuitionBase);
-
- if(GfxBase)
- CloseLibrary(GfxBase);
-
- exit(ExitCode);
- }
-
- void
- OpenAll()
- {
- if(!(IntuitionBase = OpenLibrary("intuition.library",0)))
- CloseAll(20);
-
- if(!(GfxBase = OpenLibrary("graphics.library",0)))
- CloseAll(21);
-
- if(!(Screen1 = OpenScreen(&NewScreen)))
- CloseAll(22);
-
- if(!(Screen2 = OpenScreen(&NewScreen)))
- CloseAll(23);
-
- NewWindow . Screen = Screen1;
-
- if(!(Window = OpenWindow(&NewWindow)))
- CloseAll(24);
-
- SetAPen(&Screen1 -> RastPort,1);
- SetAPen(&Screen2 -> RastPort,1);
-
- SetDrMd(&Screen1 -> RastPort,JAM1);
- SetDrMd(&Screen2 -> RastPort,JAM1);
- }
-
- int points = 24, lines = 31, faces = 13;
-
- struct SCPNT
- {
- int x,y;
- } scpnt[255];
-
- struct POINT
- {
- long x,y,z;
- } point[] =
- {
- -5,-10,-10,
-
- 10,-10,-10,
- 10, 10,-10,
- -10, 10,-10,
- -10,-10, 10,
- 10,-10, 10,
- 10, 10, 10,
- -10, 10, 10,
- 0, 0, 0,
-
- -6, -6, -9,
- -3, -6, -9,
- 0, -6, -9,
- -3, 6, -9,
- 6, -6, -9,
- 4, -6, -9,
- 2, -4, -9,
- 2, -2, -9,
- 6, 2, -9,
- 6, 4, -9,
- 4, 6, -9,
- 2, 6, -9,
-
- -10, -5,-10,
- -10,-10, -5,
- -5, -5, -5
- };
-
- struct POINT dp[24];
-
- struct
- {
- int to_draw;
- int p1,p2;
- } line[] =
- {
- 1,0,1, /* 00 */
- 1,1,2,
- 1,2,3,
- 1,3,21,
- 1,22,4,
- 1,1,5, /* 05 */
- 1,2,6,
- 1,3,7,
- 1,4,5,
- 1,5,6,
- 1,6,7, /* 10 */
- 1,7,4,
- 1,23,8,
- 1,1,8,
- 1,2,8,
- 1,3,8, /* 15 */
- 1,9,11,
- 1,10,12,
- 1,13,14,
- 1,14,15,
- 1,15,16, /* 20 */
- 1,16,17,
- 1,17,18,
- 1,18,19,
- 1,19,20,
- 1,0,21, /* 25 */
- 1,21,22,
- 1,22,0,
- 1,0,23,
- 1,21,23,
- 1,22,23 /* 30 */
- };
-
- struct FACE
- {
- int solid;
- int lns;
- int Line[8];
- } face[] =
- {
- 1,4, 8,11,10, 9, 0, 0, 0, 0, /* The cube itself */
- 1,4, 1, 5, 9, 6, 0, 0, 0, 0,
- 1,4, 2, 6,10, 7, 0, 0, 0, 0,
- 1,5, 7,11, 4,26, 3, 0, 0, 0,
- 1,5, 5, 0,27, 4, 8, 0, 0, 0,
-
- 1,3, 14,13, 1, 0, 0, 0, 0, 0, /* CAVE unter TS */
- 1,3, 15,14, 2, 0, 0, 0, 0, 0,
- 1,4, 0,13,12,28, 0, 0, 0, 0,
- 1,4, 12,15, 3,29, 0, 0, 0, 0,
-
- 1,3, 30,28,27, 0, 0, 0, 0, 0, /* Das kleine Eck */
- 1,3, 25,28,29, 0, 0, 0, 0, 0,
- 1,3, 29,28,25, 0, 0, 0, 0, 0, /* wie oben, nur andersrum */
- 1,3, 26,29,30, 0, 0, 0, 0, 0,
- };
-
- long sintab[1024];
- int wx = 0, wz = 0;
-
- int dz = -10;
- int xoff = 320, yoff = 200, zoff = 400;
- int wc;
-
- main()
- {
- for(wc=0; wc<1024; wc++)
- {
- sintab[wc] = (int)(sin(((double)wc) * ((double)3.14159265359) / ((double) 512)) * ((double)16384L));
- }
-
- OpenAll();
-
- for(;;)
- {
- ScreenToFront(Screen2);
-
- RPort = &Screen1 -> RastPort;
- SetRast(RPort,0);
-
- drehx();
- drehz();
- cube();
-
- ScreenToFront(Screen1);
-
- RPort = &Screen2 -> RastPort;
- SetRast(RPort,0);
-
- drehx();
- drehz();
- cube();
-
- if(Massage = GetMsg(Window -> UserPort))
- {
- ReplyMsg(Massage);
- CloseAll(0);
- }
- }
- }
-
- cube()
- {
- long cnt,p1,p2,z,zf,lc;
- int l1,l2, l1p1,l1p2,l2p1,l2p2;
- int u1,u2,u3, v1,v2,v3/*, w1,w2,w3*/; /* die VEKTOREN */
-
- for(cnt=0; cnt<points; cnt++)
- {
- z = dp[cnt].z + zoff;
- zf = (1024000L) / (1000L + z);
- scpnt[cnt].x = (((dp[cnt].x * zf) / 1024) * 100) / 100 + xoff;
- scpnt[cnt].y = (dp[cnt].y * zf) / 1024 + yoff;
- }
-
- for(cnt=0; cnt<lines; cnt++) line[cnt].to_draw = 1;
-
- for(cnt=0; cnt<faces; cnt++)
- {
- l1 = face[cnt].Line[0]; l2 = face[cnt].Line[1];
- l1p1 = line[l1].p1; l1p2 = line[l1].p2;
- l2p1 = line[l2].p1; l2p2 = line[l2].p2;
- if(l1p1 == l2p1)
- {
- u1 = dp[l1p2].x - dp[l1p1].x;
- u2 = dp[l1p2].y - dp[l1p1].y;
- u3 = dp[l1p2].z - dp[l1p1].z;
- v1 = dp[l2p2].x - dp[l1p1].x;
- v2 = dp[l2p2].y - dp[l1p1].y;
- v3 = dp[l2p2].z - dp[l1p1].z;
- }
- if(l1p2 == l2p1)
- {
- u1 = dp[l1p1].x - dp[l1p2].x;
- u2 = dp[l1p1].y - dp[l1p2].y;
- u3 = dp[l1p1].z - dp[l1p2].z;
- v1 = dp[l2p2].x - dp[l1p2].x;
- v2 = dp[l2p2].y - dp[l1p2].y;
- v3 = dp[l2p2].z - dp[l1p2].z;
- }
- if(l1p1 == l2p2)
- {
- u1 = dp[l1p2].x - dp[l1p1].x;
- u2 = dp[l1p2].y - dp[l1p1].y;
- u3 = dp[l1p2].z - dp[l1p1].z;
- v1 = dp[l2p2].x - dp[l1p1].x;
- v2 = dp[l2p2].y - dp[l1p1].y;
- v3 = dp[l2p2].z - dp[l1p1].z;
- }
- if(l1p2 == l2p2)
- {
- u1 = dp[l1p1].x - dp[l2p2].x;
- u2 = dp[l1p1].y - dp[l2p2].y;
- u3 = dp[l1p1].z - dp[l2p2].z;
- v1 = dp[l2p1].x - dp[l2p2].x;
- v2 = dp[l2p1].y - dp[l2p2].y;
- v3 = dp[l2p1].z - dp[l2p2].z;
- }
-
- for(lc=0; lc<face[cnt].lns; lc++)
- {
- if(line[face[cnt].Line[lc]].to_draw == 0) continue;
- p1 = line[face[cnt].Line[lc]].p1;
- p2 = line[face[cnt].Line[lc]].p2;
- Move(RPort,scpnt[p1].x,scpnt[p1].y);
- Draw(RPort,scpnt[p2].x,scpnt[p2].y);
- line[face[cnt].Line[lc]].to_draw = 0;
- }
- }
-
- zoff += dz;
- if(zoff>=400 || zoff<=0) dz = -dz;
- return 0;
- }
-
- drehx()
- {
- int cnt,sn,cs; long y,z;
-
- sn = sinus(wx);
- cs = cosinus(wx);
-
- wx += 2;
- if(wx > 1023) wx -= 1024;
-
- for(cnt=0; cnt<points; cnt++)
- {
- y = point[cnt].y * 10; z = point[cnt].z * 10;
- dp[cnt].x = point[cnt].x * 40;
- dp[cnt].y = (y * cs - z * sn) / 4096;
- dp[cnt].z = (z * cs + y * sn) / 16384;
- }
- return 0;
- }
-
- drehz()
- {
- int cnt,sn,cs; long x,y;
-
- sn = sinus(wz);
- cs = cosinus(wz);
-
- wz += 3;
- if(wz > 1023) wz -= 1024;
-
- for(cnt=0; cnt<points; cnt++)
- {
- x = dp[cnt].x; y = dp[cnt].y;
- dp[cnt].z = dp[cnt].z;
- dp[cnt].x = (((x * cs) + (y * sn)) / 65536L);
- dp[cnt].y = (((y * cs) - (x * sn)) / 65536L);
- }
- return 0;
- }
-
- long
- sinus(int w)
- {
- int valid;
-
- valid = w;
- while(valid > 1023) valid -= 1024;
- while(valid < 0) valid += 1024;
-
- return sintab[valid];
- }
-