123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #include <iostream>
- #include <cmath>
- #include <SDL/SDL.h>
- #undef main
- #include <SDL/SDL_rotozoom.h>
- #include "Vecteur.h"
- int main ( int argc, char** argv )
- {
-
-
- if ( SDL_Init( SDL_INIT_VIDEO ) < 0)
- {
- std::cout << "Impossible d'initialiser la SDL: " << SDL_GetError() << std::endl;
- return 1;
- }
-
- atexit(SDL_Quit);
-
- SDL_WM_SetCaption("Rotator", 0);
-
-
- SDL_Surface* screen = SDL_SetVideoMode(1280, 720, 32,
- SDL_HWSURFACE|SDL_DOUBLEBUF);
- if ( !screen )
- {
- std::cout << "Unable to set 640x480 video: " << SDL_GetError() << std::endl;
- return 1;
- }
-
- SDL_Rect pos;
- SDL_Surface* epee = SDL_LoadBMP("Perso.bmp");
- SDL_SetColorKey(epee, SDL_SRCCOLORKEY, SDL_MapRGBA(epee->format, 0, 0, 0, 255));
- SDL_Surface* rotation = rotozoomSurface(epee, 0.0, 1.0, 1);
- double angle(0.0);
- Vec dir;
- Vec axeY( 0.0f, 1.0f );
-
- bool done = false;
- SDL_Event event;
- while (!done)
- {
-
- while (SDL_PollEvent(&event))
- {
- switch (event.type)
- {
- case SDL_QUIT:
- done = true;
- break;
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_ESCAPE)
- done = true;
- case SDL_MOUSEMOTION:
- dir.setX( event.motion.x - screen->w/2 );
- dir.setY( screen->h/2 - event.motion.y );
- angle = atan((double)(dir.getY()) / (dir.getX()+0.5f));
- angle = angle * 180.0 / M_PI;
- if ( dir.getX() < 0 ) angle += 180;
- break;
- }
- }
-
- SDL_FreeSurface(rotation);
- rotation = rotozoomSurface(epee, angle, 1.0, 0);
- pos.x = screen->w/2 - rotation->w/2;
- pos.y = screen->h/2 - rotation->h/2;
-
- SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 0));
- SDL_BlitSurface(rotation, 0, screen, &pos);
- SDL_Flip(screen);
-
- SDL_Delay(30);
- }
-
-
-
- SDL_FreeSurface(screen);
- SDL_FreeSurface(epee);
- SDL_FreeSurface(rotation);
- return 0;
- }
|