#include #include #include #include #include #include #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 #define SCREEN_DEPTH 16 #define SCALE 10 const int radius = 200; int angle = 0; #define _X(x) ((SCREEN_WIDTH / 2) + (x)) #define _Y(y) return (T)((SCREEN_HEIGHT / 2) - (y)) /* The screen surface */ SDL_Surface *screen = NULL; void draw () { angle++; SDL_Rect box; box.w = 40; box.h = 40; double cosx; cosx = cos(deg2rad(angle)); box.x = (int)_X(cosx*radius) ; box.y = (int)_X(cosx*radius); //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_FillRect(screen, &box, SDL_MapRGB(screen->format, 255, 0, 0)); /* Make sure everything is displayed on screen */ SDL_Flip (screen); /* Don't run too fast */ SDL_Delay (1); } int main (int argc, char *argv[]) { char *msg; int done; /* Initialize SDL */ if (SDL_Init (SDL_INIT_VIDEO) < 0) { sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ()); MessageBox (0, msg, "Error", MB_ICONHAND); free (msg); exit (1); } atexit (SDL_Quit); /* Set 640x480 16-bits video mode */ screen = SDL_SetVideoMode (SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE | SDL_DOUBLEBUF); if (screen == NULL) { sprintf (msg, "Couldn't set 640x480x16 video mode: %s\n", SDL_GetError ()); MessageBox (0, msg, "Error", MB_ICONHAND); free (msg); exit (2); } SDL_WM_SetCaption ("Circulator Rotation around a Vertex", NULL); done = 0; while (!done) { SDL_Event event; /* Check for events */ while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYDOWN: break; case SDL_QUIT: done = 1; break; default: break; } } /* Draw to screen */ draw (); } return 0; }