summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stern.bas229
-rw-r--r--stern.cpp337
2 files changed, 326 insertions, 240 deletions
diff --git a/stern.bas b/stern.bas
index 4c3da70..ee19d1b 100644
--- a/stern.bas
+++ b/stern.bas
@@ -1,114 +1,115 @@
-'STERN.BAS 29.04.1996
-
-DECLARE SUB InitProgram ()
-DECLARE SUB MainLoop ()
-DECLARE SUB Calc3D ()
-DECLARE SUB Rotation ()
-DECLARE SUB DrawObject ()
-
-DIM SHARED Lines, World(500, 3)
-DIM SHARED X, Y, Z, sX, sY, Xa, Ya, Za, sXs, sYs, D
-DIM SHARED R1, R2, R3, Sr1, Sr2, Sr3, Cr1, Cr2, Cr3, mX, mY, mZ
-
- READ Lines
- FOR i = 1 TO Lines
- FOR J = 1 TO 3
- READ World(i, J)
- NEXT
- NEXT
-
- InitProgram
- MainLoop
- SCREEN 0
-END
-
-DATA 72
-DATA 90, 0, 0, 10, 10, 10, 90, 0, 0, 10, 10,-10
-DATA 90, 0, 0, 10,-10,-10, 90, 0, 0, 10,-10, 10
-DATA -90, 0, 0, -10, 10, 10, -90, 0, 0, -10, 10,-10
-DATA -90, 0, 0, -10,-10,-10, -90, 0, 0, -10,-10, 10
-DATA 0, 90, 0, 10, 10, 10, 0, 90, 0, -10, 10, 10
-DATA 0, 90, 0, -10, 10,-10, 0, 90, 0, 10, 10,-10
-DATA 0,-90, 0, 10,-10, 10, 0,-90, 0, -10,-10, 10
-DATA 0,-90, 0, -10,-10,-10, 0,-90, 0, 10,-10,-10
-DATA 0, 0, 90, 10, 10, 10, 0, 0, 90, 10,-10, 10
-DATA 0, 0, 90, -10,-10, 10, 0, 0, 90, -10, 10, 10
-DATA 0, 0,-90, 10, 10,-10, 0, 0,-90, 10,-10,-10
-DATA 0, 0,-90, -10,-10,-10, 0, 0,-90, -10, 10,-10
-DATA 10, 10, 10, -10, 10, 10, 10,-10, 10, -10,-10, 10
-DATA 10, 10,-10, -10, 10,-10, 10,-10,-10, -10,-10,-10
-DATA 10, 10, 10, 10,-10, 10, -10, 10, 10, -10,-10, 10
-DATA 10, 10,-10, 10,-10,-10, -10, 10,-10, -10,-10,-10
-DATA 10, 10, 10, 10, 10,-10, 10,-10, 10, 10,-10,-10
-DATA -10,-10, 10, -10,-10,-10, -10, 10, 10, -10, 10,-10
-
-SUB Calc3D
- X = -1 * X
- Xa = Cr1 * X - Sr1 * Z
- Za = Sr1 * X + Cr1 * Z
- X = Cr2 * Xa + Sr2 * Y
- Ya = Cr2 * Y - Sr2 * Xa
- Z = Cr3 * Za - Sr3 * Ya
- Y = Sr3 * Za + Cr3 * Ya
- X = X + mX
- Y = Y + mY
- Z = Z + mZ
- sX = D * X / Z
- sY = D * Y / Z
-END SUB
-
-SUB DrawObject
- Rotation
- FOR i = 1 TO Lines STEP 2
- X = World(i, 1)
- Y = World(i, 2)
- Z = World(i, 3)
- Calc3D
- sXs = sX: sYs = sY
-
- X = World(i + 1, 1)
- Y = World(i + 1, 2)
- Z = World(i + 1, 3)
- Calc3D
-
- LINE (sXs, sYs)-(sX, sY), 15
- NEXT
-END SUB
-
-SUB InitProgram
- SCREEN 9, 1, 0, 1
- WINDOW (-320, -175)-(320, 175)
- CLS 'PAGE 0
-
- SCREEN 9, 1, 1, 0
- CLS 'PAGE 1
-
- D = 1200 'View point and rotation values
- mZ = -850
- mX = -5
- R1 = 0
- R2 = 0
- R3 = .3
-END SUB
-
-SUB MainLoop
- WHILE INKEY$ = ""
- R1 = R1 + .1: IF R1 > 6.28 THEN R1 = 0
- R2 = R1: R3 = R1
-
- WAIT 986, 8
- CLS : DrawObject
- Page = ABS(Page = 0) 'Page switching is used to hide the drawing
- SCREEN 9, 1, 1 - Page, Page 'process so the image looks smooth.
- WEND
-END SUB
-
-SUB Rotation
- Sr1 = SIN(R1)
- Sr2 = SIN(R2)
- Sr3 = SIN(R3)
- Cr1 = COS(R1)
- Cr2 = COS(R2)
- Cr3 = COS(R3)
-END SUB
-
+'$Id$
+'STERN.BAS 29.04.1996
+
+DECLARE SUB InitProgram ()
+DECLARE SUB MainLoop ()
+DECLARE SUB Calc3D ()
+DECLARE SUB Rotation ()
+DECLARE SUB DrawObject ()
+
+DIM SHARED Lines, World(500, 3)
+DIM SHARED X, Y, Z, sX, sY, Xa, Ya, Za, sXs, sYs, D
+DIM SHARED R1, R2, R3, Sr1, Sr2, Sr3, Cr1, Cr2, Cr3, mX, mY, mZ
+
+ READ Lines
+ FOR i = 1 TO Lines
+ FOR J = 1 TO 3
+ READ World(i, J)
+ NEXT
+ NEXT
+
+ InitProgram
+ MainLoop
+ SCREEN 0
+END
+
+DATA 72
+DATA 90, 0, 0, 10, 10, 10, 90, 0, 0, 10, 10,-10
+DATA 90, 0, 0, 10,-10,-10, 90, 0, 0, 10,-10, 10
+DATA -90, 0, 0, -10, 10, 10, -90, 0, 0, -10, 10,-10
+DATA -90, 0, 0, -10,-10,-10, -90, 0, 0, -10,-10, 10
+DATA 0, 90, 0, 10, 10, 10, 0, 90, 0, -10, 10, 10
+DATA 0, 90, 0, -10, 10,-10, 0, 90, 0, 10, 10,-10
+DATA 0,-90, 0, 10,-10, 10, 0,-90, 0, -10,-10, 10
+DATA 0,-90, 0, -10,-10,-10, 0,-90, 0, 10,-10,-10
+DATA 0, 0, 90, 10, 10, 10, 0, 0, 90, 10,-10, 10
+DATA 0, 0, 90, -10,-10, 10, 0, 0, 90, -10, 10, 10
+DATA 0, 0,-90, 10, 10,-10, 0, 0,-90, 10,-10,-10
+DATA 0, 0,-90, -10,-10,-10, 0, 0,-90, -10, 10,-10
+DATA 10, 10, 10, -10, 10, 10, 10,-10, 10, -10,-10, 10
+DATA 10, 10,-10, -10, 10,-10, 10,-10,-10, -10,-10,-10
+DATA 10, 10, 10, 10,-10, 10, -10, 10, 10, -10,-10, 10
+DATA 10, 10,-10, 10,-10,-10, -10, 10,-10, -10,-10,-10
+DATA 10, 10, 10, 10, 10,-10, 10,-10, 10, 10,-10,-10
+DATA -10,-10, 10, -10,-10,-10, -10, 10, 10, -10, 10,-10
+
+SUB Calc3D
+ X = -1 * X
+ Xa = Cr1 * X - Sr1 * Z
+ Za = Sr1 * X + Cr1 * Z
+ X = Cr2 * Xa + Sr2 * Y
+ Ya = Cr2 * Y - Sr2 * Xa
+ Z = Cr3 * Za - Sr3 * Ya
+ Y = Sr3 * Za + Cr3 * Ya
+ X = X + mX
+ Y = Y + mY
+ Z = Z + mZ
+ sX = D * X / Z
+ sY = D * Y / Z
+END SUB
+
+SUB DrawObject
+ Rotation
+ FOR i = 1 TO Lines STEP 2
+ X = World(i, 1)
+ Y = World(i, 2)
+ Z = World(i, 3)
+ Calc3D
+ sXs = sX: sYs = sY
+
+ X = World(i + 1, 1)
+ Y = World(i + 1, 2)
+ Z = World(i + 1, 3)
+ Calc3D
+
+ LINE (sXs, sYs)-(sX, sY), 15
+ NEXT
+END SUB
+
+SUB InitProgram
+ SCREEN 9, 1, 0, 1
+ WINDOW (-320, -175)-(320, 175)
+ CLS 'PAGE 0
+
+ SCREEN 9, 1, 1, 0
+ CLS 'PAGE 1
+
+ D = 1200 'View point and rotation values
+ mZ = -850
+ mX = -5
+ R1 = 0
+ R2 = 0
+ R3 = .3
+END SUB
+
+SUB MainLoop
+ WHILE INKEY$ = ""
+ R1 = R1 + .1: IF R1 > 6.28 THEN R1 = 0
+ R2 = R1: R3 = R1
+
+ WAIT 986, 8
+ CLS : DrawObject
+ Page = ABS(Page = 0) 'Page switching is used to hide the drawing
+ SCREEN 9, 1, 1 - Page, Page 'process so the image looks smooth.
+ WEND
+END SUB
+
+SUB Rotation
+ Sr1 = SIN(R1)
+ Sr2 = SIN(R2)
+ Sr3 = SIN(R3)
+ Cr1 = COS(R1)
+ Cr2 = COS(R2)
+ Cr3 = COS(R3)
+END SUB
+
diff --git a/stern.cpp b/stern.cpp
index c94f449..c1d68d9 100644
--- a/stern.cpp
+++ b/stern.cpp
@@ -1,126 +1,211 @@
-// STERN.CPP 11.02.2000
-#include <stdio.h>
-#include <conio.h>
-#include <graphics.h>
-#include <process.h>
-#include <math.h>
-
-void InitProgram(void);
-void MainLoop(void);
-void Calc3D(void);
-void Rotation(void);
-void DrawObject(void);
-
-#define COPYRIGHT "Dark Alliance (c) 1996-2000 DreamDemon"
-#define Lines 72
-static int World[Lines][3] = {
- 90, 0, 0, 10, 10, 10, 90, 0, 0, 10, 10,-10,
- 90, 0, 0, 10,-10,-10, 90, 0, 0, 10,-10, 10,
- -90, 0, 0, -10, 10, 10, -90, 0, 0, -10, 10,-10,
- -90, 0, 0, -10,-10,-10, -90, 0, 0, -10,-10, 10,
- 0, 90, 0, 10, 10, 10, 0, 90, 0, -10, 10, 10,
- 0, 90, 0, -10, 10,-10, 0, 90, 0, 10, 10,-10,
- 0,-90, 0, 10,-10, 10, 0,-90, 0, -10,-10, 10,
- 0,-90, 0, -10,-10,-10, 0,-90, 0, 10,-10,-10,
- 0, 0, 90, 10, 10, 10, 0, 0, 90, 10,-10, 10,
- 0, 0, 90, -10,-10, 10, 0, 0, 90, -10, 10, 10,
- 0, 0,-90, 10, 10,-10, 0, 0,-90, 10,-10,-10,
- 0, 0,-90, -10,-10,-10, 0, 0,-90, -10, 10,-10,
- 10, 10, 10, -10, 10, 10, 10,-10, 10, -10,-10, 10,
- 10, 10,-10, -10, 10,-10, 10,-10,-10, -10,-10,-10,
- 10, 10, 10, 10,-10, 10, -10, 10, 10, -10,-10, 10,
- 10, 10,-10, 10,-10,-10, -10, 10,-10, -10,-10,-10,
- 10, 10, 10, 10, 10,-10, 10,-10, 10, 10,-10,-10,
- -10,-10, 10, -10,-10,-10, -10, 10, 10, -10, 10,-10};
-
-float X, Y, Z, sX, sY, Xa, Ya, Za, sXs, sYs, D, Page;
-float R1, R2, R3, Sr1, Sr2, Sr3, Cr1, Cr2, Cr3, mX, mY, mZ;
-
-void main(void)
-{
- InitProgram();
- MainLoop();
- closegraph();
- printf("%s\n",COPYRIGHT);
- getch();
-}
-
-void Calc3D(void)
-{
- X = -1 * X;
- Xa = Cr1 * X - Sr1 * Z;
- Za = Sr1 * X + Cr1 * Z;
- X = Cr2 * Xa + Sr2 * Y;
- Ya = Cr2 * Y - Sr2 * Xa;
- Z = Cr3 * Za - Sr3 * Ya;
- Y = Sr3 * Za + Cr3 * Ya;
- X = X + mX;
- Y = Y + mY;
- Z = Z + mZ;
- sX = 320 + D * X / Z;
- sY = 175 + D * Y / Z;
-}
-
-void DrawObject(void)
-{
- int i;
-
- Rotation();
- for(i=0; i<Lines; i+=2) {
- X = World[i][0];
- Y = World[i][1];
- Z = World[i][2];
- Calc3D();
- sXs = sX;
- sYs = sY;
- X = World[i+1][0];
- Y = World[i+1][1];
- Z = World[i+1][2];
- Calc3D();
- line(sXs, sYs, sX, sY);
- }
-}
-
-void InitProgram(void)
-{
- int gdriver = EGA, gmode = EGAHI, errorcode;
- initgraph(&gdriver, &gmode, "");
- errorcode = graphresult();
- if (errorcode != grOk) {
- printf("Graphics error: %s\n", grapherrormsg(errorcode));
- printf("Press any key to halt:");
- getch();
- exit(1);
- }
- D = 1200; // View point and rotation values
- mZ = -850;
- mX = -5;
- R1 = 0;
- R2 = 0;
- R3 = 0.3;
-}
-
-void MainLoop(void)
-{
- while(!kbhit()) {
- R1 = R1 + 0.1;
- if(R1 > 6.28) R1 = 0;
- R2 = R1;
- R3 = R1;
- clearviewport();
- DrawObject();
- (Page == 0)? Page = 1: Page = 0;
- setactivepage(1-Page);
- setvisualpage(Page);
- }
-}
-
-void Rotation(void)
-{
- Sr1 = sin(R1);
- Sr2 = sin(R2);
- Sr3 = sin(R3);
- Cr1 = cos(R1);
- Cr2 = cos(R2);
- Cr3 = cos(R3);
-}
+/* $Id$ */
+#include <stdio.h>
+#include <conio.h>
+#include <graphics.h>
+#include <process.h>
+#include <math.h>
+
+void Calc3D(void);
+void DrawObject(void);
+void InitProgram(void);
+void MainLoop(void);
+void Rotation(void);
+int key(void);
+void Legende(void);
+
+#define COPYRIGHT "Dark Alliance (c) 1996-2000 DreamDemon"
+#define DATUM "13.02.2000"
+#define PI 3.14
+#define Lines 72
+
+static int World[Lines][3] = {
+ 90, 0, 0, 10, 10, 10, 90, 0, 0, 10, 10,-10,
+ 90, 0, 0, 10,-10,-10, 90, 0, 0, 10,-10, 10,
+ -90, 0, 0, -10, 10, 10, -90, 0, 0, -10, 10,-10,
+ -90, 0, 0, -10,-10,-10, -90, 0, 0, -10,-10, 10,
+ 0, 90, 0, 10, 10, 10, 0, 90, 0, -10, 10, 10,
+ 0, 90, 0, -10, 10,-10, 0, 90, 0, 10, 10,-10,
+ 0,-90, 0, 10,-10, 10, 0,-90, 0, -10,-10, 10,
+ 0,-90, 0, -10,-10,-10, 0,-90, 0, 10,-10,-10,
+ 0, 0, 90, 10, 10, 10, 0, 0, 90, 10,-10, 10,
+ 0, 0, 90, -10,-10, 10, 0, 0, 90, -10, 10, 10,
+ 0, 0,-90, 10, 10,-10, 0, 0,-90, 10,-10,-10,
+ 0, 0,-90, -10,-10,-10, 0, 0,-90, -10, 10,-10,
+ 10, 10, 10, -10, 10, 10, 10,-10, 10, -10,-10, 10,
+ 10, 10,-10, -10, 10,-10, 10,-10,-10, -10,-10,-10,
+ 10, 10, 10, 10,-10, 10, -10, 10, 10, -10,-10, 10,
+ 10, 10,-10, 10,-10,-10, -10, 10,-10, -10,-10,-10,
+ 10, 10, 10, 10, 10,-10, 10,-10, 10, 10,-10,-10,
+ -10,-10, 10, -10,-10,-10, -10, 10, 10, -10, 10,-10};
+
+float X, Y, Z, sX, sY, Xa, Ya, Za, sXs, sYs, D, G, Page, Xmid, Ymid;
+float R, R1, R2, R3, Sr1, Sr2, Sr3, Cr1, Cr2, Cr3, mX, mY, mZ;
+
+void main(void)
+{
+ InitProgram();
+ MainLoop();
+ closegraph();
+ printf("%s\n",COPYRIGHT);
+// getch();
+}
+
+void Calc3D(void)
+{
+ X = -1 * X;
+ Xa = Cr1 * X - Sr1 * Z;
+ Za = Sr1 * X + Cr1 * Z;
+ X = Cr2 * Xa + Sr2 * Y;
+ Ya = Cr2 * Y - Sr2 * Xa;
+ Z = Cr3 * Za - Sr3 * Ya;
+ Y = Sr3 * Za + Cr3 * Ya;
+ X = X + mX;
+ Y = Y + mY;
+ Z = Z + mZ;
+ sX = Xmid + D * X / Z;
+ sY = Ymid + D * Y / Z;
+}
+
+void DrawObject(void)
+{
+ int i;
+
+ Rotation();
+ for(i=0; i<Lines; i+=2)
+ {
+ X = World[i][0];
+ Y = World[i][1];
+ Z = World[i][2];
+ Calc3D();
+ sXs = sX;
+ sYs = sY;
+
+ X = World[i+1][0];
+ Y = World[i+1][1];
+ Z = World[i+1][2];
+ Calc3D();
+
+// line(abs(sXs), abs(sYs), abs(sX), abs(sY));
+ line(sXs, sYs, sX, sY);
+ }
+}
+
+void InitProgram(void)
+{
+ int gdriver = EGA, gmode = EGAHI, errorcode;
+ initgraph(&gdriver, &gmode, "");
+ errorcode = graphresult();
+ if (errorcode != grOk)
+ {
+ printf("%s\n", grapherrormsg(errorcode));
+ exit(1);
+ }
+ Xmid = getmaxx() / 2;
+ Ymid = getmaxy() / 2;
+
+// D = 1200; // View point and rotation values
+ D = 10000;
+// mZ = -850;
+ mZ = -10000;
+// mX = -5;
+ R1 = 0.3;
+ R2 = 0.0;
+ R3 = 0.3;
+ G = 0.3;
+}
+
+void MainLoop(void)
+{
+ int k, Demo=0;
+ while((k=key()) != 27)
+ {
+ switch(k) {
+ case 115: case 83: // S
+ R1 += G;
+ if(R1 > (2 * PI)) R1 = 0;
+ break;
+ case 101: case 69: // E
+ R2 += G;
+ if(R2 > (2 * PI)) R2 = 0;
+ break;
+ case 113: case 81: // Q
+ R3 += G;
+ if(R3 > (2 * PI)) R3 = 0;
+ break;
+ case 119: case 87: // W
+ R1 -= G;
+ if(R1 < 0) R1 = 2 * PI;
+ break;
+ case 100: case 68: // D
+ R2 -= G;
+ if(R2 < 0) R2 = 2 * PI;
+ break;
+ case 97: case 65: // A
+ R3 -= G;
+ if(R3 < 0) R3 = 2 * PI;
+ break;
+ case 43: // +
+ if(D < 30000) D += 1000;
+ break;
+ case 45: // -
+ if(D > 1000) D -= 1000;
+ break;
+ case 13: // Enter
+ R1 = 0.3;
+ R2 = 0.0;
+ R3 = 0.3;
+ D = 10000;
+ break;
+ case 32: // Space
+ Demo = 1 - Demo;
+ break;
+ default: break;
+ }
+ if(Demo == 1) {
+ R += 0.1;
+ if(R > (2 * PI)) R = 0;
+ R1 = R2 = R3 = R;
+ }
+
+ clearviewport();
+ DrawObject();
+ Legende();
+ setvisualpage(Page);
+ Page = 1 - Page;
+ setactivepage(Page);
+ }
+}
+
+void Rotation(void)
+{
+ Sr1 = sin(R1);
+ Sr2 = sin(R2);
+ Sr3 = sin(R3);
+ Cr1 = cos(R1);
+ Cr2 = cos(R2);
+ Cr3 = cos(R3);
+}
+
+extern int key(void)
+{
+ int k=0;
+ if(kbhit()) {
+ k = getch();
+ if (k == 0)
+ k = key();
+ }
+ return k;
+}
+
+void Legende(void)
+{
+ outtextxy( 10, 10,"Space: Run/Stop Demo");
+ outtextxy( 10, 20,"Enter: Set to Zero");
+ outtextxy( 10, 30,"+/- : Zoom");
+ outtextxy( 10, 40,"Esc : Quit");
+ outtextxy(470, 10,"Rotation:");
+ outtextxy(550, 10,"Q W E");
+ outtextxy(550, 20,"A S D");
+ outtextxy( 10,330,COPYRIGHT);
+ outtextxy(540,330,DATUM);
+}