freshman's first question

This topic is 3492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

hi , guys ,i'm from china, now i have a problem: I'm using DEV-CPP 4.9.9.2 with SDL,yesterday,i downloaded the SDL_gfx and installde it,now,i want to make a surface rotate around a point,how can i do ? I use the rotozoomsurface() function, but it don't look natural,please heip me ! with best ragards!

Share on other sites
Im not sure how to help you with this problem but i know that this site has lots of great tutorials.

Good luck =)

Share on other sites
Can you describe what you mean by "doesn't feel natural".

One way to rotate around a point is to offset the x and y co-ordinates of the blit by half the width and height of the image respectively. When you rotate SDL surfaces, the width and height will change, and the image will appear to move as well as rotate. I am guessing that this is what you mean by "doesn't feel natural".

Example of offset:
// the x,y co-ordinate mark where the centre of the surface will bevoid offset_blit(SDL_Surface *source, int x, int y, SDL_Surface *dest ){    x -= source->w / 2;    y -= source->h / 2;    SDL_Rect rect = {x,y};    SDL_BlitSurface(source,NULL,dest,&rect);}int main(int, char **){    SDL_Init(SDL_INIT_VIDEO);    SDL_Surface *screen = SDL_SetVideoMode(800,600,32,SDL_SWSURFACE);    const int x = screen->w / 2, y = screen->h / 2;    int angle = 0;    SDL_Surface *source = IMG_Load("sampleM.bmp"); // or whatever image    SDL_Event event;    bool running = true;    while(running)    {        while(SDL_PollEvent(&event))        {            if(event.type == SDL_QUIT)            {                running = false;            }        }        SDL_FillRect(screen,0,0);        ++angle;        SDL_Surface *rotated = rotozoomSurface(source, angle, 1.0f, 0);        offset_blit(rotated,x,y,screen);        SDL_FreeSurface(rotated);        SDL_Flip(screen);    }    SDL_Quit();}

Please note the utter lack of error checking due to me throwing this together in a really short time period.

Finally, SDL isn't really great if you want to do lots of rotation in real time. If this is a goal of yours, consider using OpenGL. It isn't that much harder.

Share on other sites
Its probably not directly applicable to this problem, but you may avoid some problems in the future by switching to a new IDE. the Dev-C++ project has kind of been dead for a couple years now. I would suggest wxDev-C++, its basically an up to date (and much more stable) version of the same thing.

Share on other sites
Around a point means :the image rotates around a point within the image
for example: image.w = 800,image.h = 600,so the point is (400,300),i want the image to rotate around (400,300)