From 78a546af1e00b4051066f01ad9e6cffbaf8cd7de Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 16 Oct 2007 22:36:28 +0000 Subject: Stern X11 version --- Makefile | 13 +++++ stern.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 Makefile create mode 100644 stern.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1040c07 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +PROG= stern +#PROG= simple-drawing + +NOMAN= + +COPTS+= -I/usr/X11R6/include +LDFLAGS+= -L/usr/X11R6/lib +LDADD+= -lX11 -lm +#LDADD+=-lGL +#LDADD+=-lGLU +#LDADD+=-lglut + +. include diff --git a/stern.c b/stern.c new file mode 100644 index 0000000..e866f17 --- /dev/null +++ b/stern.c @@ -0,0 +1,184 @@ +// STERN.BAS 29.04.1996 +// STERN.CPP 11.02.2000 +// STERN.C 11.07.2003 +// stern.c 07.02.2004 + +#include +#include +#include +#include +#include + +void Calc3D(void); +void DrawObject(void); +void InitProgram(void); +void MainLoop(void); +void Rotation(void); + +#define SLEEP 50000 +#define WIDTH 320 +#define HIGHT 320 +#define X_POS 0 +#define Y_POS 0 +#define BORDER 2 +#define PI 3.1415926 +#define Lines 72 + +/* Lines 36 +static int World[Lines][3] = { + -60, 40, 20, -20, 40, 20, + -20, 40, 20, -20, 0, 20, + -20, 0, 20, 60, 0, 20, + 60, 0, 20, 60,-40, 20, + 60,-40, 20, -60,-40, 20, + -60,-40, 20, -60, 40, 20, + + -60, 40,-20, -20, 40,-20, + -20, 40,-20, -20, 0,-20, + -20, 0,-20, 60, 0,-20, + 60, 0,-20, 60,-40,-20, + 60,-40,-20, -60,-40,-20, + -60,-40,-20, -60, 40,-20, + + -60, 40, 20, -60, 40,-20, + -20, 40, 20, -20, 40,-20, + -20, 0, 20, -20, 0,-20, + 60, 0, 20, 60, 0,-20, + 60,-40, 20, 60,-40,-20, + -60,-40, 20, -60,-40,-20}; +*/ +/* 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, Xmid, Ymid; +float R, R1, R2, R3, Sr1, Sr2, Sr3, Cr1, Cr2, Cr3, mX, mY, mZ; + +Display *display; +Window win; +GC gc; +XGCValues values; + +int main(void) +{ + InitProgram(); + MainLoop(); + XCloseDisplay(display); + exit(0); +} + + +void InitProgram(void) +{ + int screen; + + display = XOpenDisplay(getenv("DISPLAY")); + screen = DefaultScreen(display); + win = XCreateSimpleWindow(display, RootWindow(display, screen), + X_POS, Y_POS, WIDTH, HIGHT, BORDER, + BlackPixel(display, screen), + WhitePixel(display, screen)); + XMapWindow(display, win); + XFlush(display); + gc = XCreateGC(display, win, 0, &values); + XSetForeground(display, gc, BlackPixel(display, screen)); + XSetBackground(display, gc, WhitePixel(display, screen)); + XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinBevel); + XSetFillStyle(display, gc, FillSolid); + XSync(display, False); + + Xmid = WIDTH / 2; + Ymid = HIGHT / 2; + + D = 1200; /* View point and rotation values */ + mZ = -850; + mX = -5; + R1 = 0; + R2 = 0; + R3 = 0.3; +} + +void MainLoop(void) +{ + int k; + while(1) + { + R += 0.1; + if(R > (2 * PI)) R = 0; + R1 = R; + R2 = R; + R3 = R; + + XClearWindow(display, win); + DrawObject(); + XFlush(display); + usleep(SLEEP); + } +} + +void DrawObject(void) +{ + int i; + + Rotation(); + for(i=0; i