From 2632e257f7b30e93dd6a410f73cdfd8c7c0c5801 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 16 Oct 2007 22:40:46 +0000 Subject: Stern X11 version --- Makefile | 4 -- stern.c | 247 +++++++++++++++++++++++++++++++-------------------------------- 2 files changed, 120 insertions(+), 131 deletions(-) diff --git a/Makefile b/Makefile index 1040c07..cabb4ae 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,9 @@ 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 index e866f17..e104fc3 100644 --- a/stern.c +++ b/stern.c @@ -1,7 +1,10 @@ -// STERN.BAS 29.04.1996 -// STERN.CPP 11.02.2000 -// STERN.C 11.07.2003 -// stern.c 07.02.2004 +/* $Id$ + * stern.c 25.12.2006 + * stern.c 07.02.2004 + * STERN.C 11.07.2003 + * STERN.CPP 11.02.2000 + * STERN.BAS 29.04.1996 + */ #include #include @@ -9,45 +12,55 @@ #include #include -void Calc3D(void); -void DrawObject(void); -void InitProgram(void); +int Calc3D(int *, int *, int *); +void DrawObject(int); 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 +#define Usleep 10000 +#define Width 800 +#define Height 600 +#define Pi 3.1415926 + +#define SECOND +#if defined(FIRST) +#define D 500 +#define Lines 24 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 */ + 50, 50, 50, -50, 50, 50, 50,-50, 50, -50,-50, 50, + 50, 50,-50, -50, 50,-50, 50,-50,-50, -50,-50,-50, + 50, 50, 50, 50,-50, 50, -50, 50, 50, -50,-50, 50, + 50, 50,-50, 50,-50,-50, -50, 50,-50, -50,-50,-50, + 50, 50, 50, 50, 50,-50, 50,-50, 50, 50,-50,-50, + -50,-50, 50, -50,-50,-50, -50, 50, 50, -50, 50,-50 +}; +#elif defined(SECOND) +#define D 200 +#define 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 +}; +#else +#define D 300 +#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, @@ -66,119 +79,99 @@ static int World[Lines][3] = { 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; + -10,-10, 10, -10,-10,-10, -10, 10, 10, -10, 10,-10 +}; +#endif + Display *display; Window win; GC gc; -XGCValues values; +/* XGCValues values; */ int main(void) -{ - InitProgram(); - MainLoop(); - XCloseDisplay(display); - exit(0); -} - - -void InitProgram(void) { int screen; + int black, white; + int r = 0; - display = XOpenDisplay(getenv("DISPLAY")); + display = XOpenDisplay(NULL); screen = DefaultScreen(display); - win = XCreateSimpleWindow(display, RootWindow(display, screen), - X_POS, Y_POS, WIDTH, HIGHT, BORDER, - BlackPixel(display, screen), - WhitePixel(display, screen)); + black = BlackPixel(display, screen); + white = WhitePixel(display, screen); + win = XCreateSimpleWindow(display, DefaultRootWindow(display), + 0, 0, Width, Height, 0, black, white); 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); + gc = XCreateGC(display, win, 0, NULL); + + XSetForeground(display, gc, black); + XSetBackground(display, gc, white); - Xmid = WIDTH / 2; - Ymid = HIGHT / 2; + XSetLineAttributes(display, gc, 2, LineSolid, CapButt, JoinBevel); + XSetFillStyle(display, gc, FillSolid); + XSelectInput(display, win, StructureNotifyMask); - D = 1200; /* View point and rotation values */ - mZ = -850; - mX = -5; - R1 = 0; - R2 = 0; - R3 = 0.3; -} + for (;;) { + XEvent event; + XNextEvent(display, &event); + if (event.type == MapNotify) + break; + } -void MainLoop(void) -{ - int k; - while(1) - { - R += 0.1; - if(R > (2 * PI)) R = 0; - R1 = R; - R2 = R; - R3 = R; + for (;;) { + if (r >= 360) + r = 0; XClearWindow(display, win); - DrawObject(); + DrawObject(++r); XFlush(display); - usleep(SLEEP); + + usleep(Usleep); } + + XCloseDisplay(display); + + return 0; } -void DrawObject(void) +float Sr, Cr; + +void DrawObject(int r) { + float R; int i; + int x1, y1, x2, y2; - Rotation(); - for(i=0; i