Sign in to follow this  

SDL_rotozoom sucks?

Recommended Posts

I'm working on this 2D space game, and I have to rotate images. So instead of manually making 16 different versions of the same thing and using spite sheets, I decided to try out "rotozoom" from the SDL_gfx library and save myself some time. So far I hate the lack of documentation. But the worst part it's just that sometimes it works, sometimes it doesn't. For example I have the following in my object constructor:
    //create rotozoomed surfaces
    itsSurface22 = rotozoomSurface (itsSurface0, -22, 1, 0);
    itsSurface45 = rotozoomSurface (itsSurface0, -45, 1, 0);
    itsSurface68 = rotozoomSurface (itsSurface0, -68, 1, 0);	    
    itsSurface90 = rotozoomSurface (itsSurface0, -90, 1, 0);
    itsSurface112 = rotozoomSurface (itsSurface0, -112, 1, 0);	    
    itsSurface135 = rotozoomSurface (itsSurface0, -135, 1, 0);
    itsSurface158 = rotozoomSurface (itsSurface0, -158, 1, 0);
    itsSurface180 = rotozoomSurface (itsSurface0, -180, 1, 0);
    itsSurface202 = rotozoomSurface (itsSurface0, -202, 1, 0);
    itsSurface224 = rotozoomSurface (itsSurface0, -224, 1, 0);
    itsSurface246 = rotozoomSurface (itsSurface0, -246, 1, 0);
    itsSurface270 = rotozoomSurface (itsSurface0, -270, 1, 0);
    itsSurface292 = rotozoomSurface (itsSurface0, -292, 1, 0);
    itsSurface315 = rotozoomSurface (itsSurface0, -315, 1, 0);
    itsSurface337 = rotozoomSurface (itsSurface0, -337, 1, 0);

And then I have a function for that object that returns a pointer to a surface which gets sent to the renderer:
SDL_Surface* cVessel :: getSuf()
	if( itsOrientation >= 349 && itsOrientation <= 11 )
    	return itsSurface0;
    else if( itsOrientation >= 12 && itsOrientation <= 33 )
    	return itsSurface22;
	else if( itsOrientation >= 34 && itsOrientation <= 56 )
    	return itsSurface45;
    else if( itsOrientation >= 57 && itsOrientation <= 79 )
    	return itsSurface68;
    else if( itsOrientation >= 80 && itsOrientation <= 101 )
  		return itsSurface90;
  	else if( itsOrientation >= 102 && itsOrientation <= 123 )
    	return itsSurface112;
    else if( itsOrientation >= 124 && itsOrientation <= 146 )
    	return itsSurface135;
    else if( itsOrientation >= 147 && itsOrientation <= 169 )
    	return itsSurface158;
    else if( itsOrientation >= 170 && itsOrientation <= 191 )
    	return itsSurface180;
    else if( itsOrientation >= 192 && itsOrientation <= 213 )
    	return itsSurface202;
    else if( itsOrientation >= 214 && itsOrientation <= 235 )
    	return itsSurface224;
    else if( itsOrientation >= 236 && itsOrientation <= 257 )
    	return itsSurface246;
    else if( itsOrientation >= 258 && itsOrientation <= 281 )
    	return itsSurface270;
    else if( itsOrientation >= 282 && itsOrientation <= 303 )
    	return itsSurface292;
    else if( itsOrientation >= 304 && itsOrientation <= 326 )
    	return itsSurface315;
    	return itsSurface337;
    	return itsSurface270;

What is happening is that the game crashes, and I ended up tracing it back to this file. I decided to manually return values. So far the only ones that work are itsSurface0, itsSurface90 and itsSurface270. All others crash the game. You can probably understand my confusion since my code is identical for each of the surfaces... I think I'll just go back to old fashioned sprite sheets, but I figured I'd post something here first maybe someone can help. Alternatively, does anyone know of a program that can rotate and save images for you? Preferably something with an angle input/number of images and if it could create a sprite sheet that would be even better.

Share this post

Link to post
Share on other sites
I concur. I don't like using SDL_rotozoom. I had it working correctly, but I simply didn't think it was that great at rotating. I ended up drawing a sprite sheet since that's about the only way to "get it done right".

Share this post

Link to post
Share on other sites
My god man, use an array! [smile] Check the return values of the rotozoom function.

I can vouch that I had SDL rotozoom working at one time and it seemed to work very well. Since then I've moved most of my code to using Opengl so I no longer need to use rotozoom.

Share this post

Link to post
Share on other sites
Oh my gosh, *giggle* please store these in a better and more beautiful way! Like an array or something, with ID numbers from 0 to 15. Anyways, I think Rotozoom works. It have worked for me but it was a while ago I used it. It's abit slow, but it works.

Can your craft have fractional orientations between 56 & 57 (for example) degrees? If so then your if-codes don't really cut it.

How about doing it with math instead?? :D Much prettier. Like this copy/paste from my code:

int getdrawdir(double dir, int avail)
// returns the display picture corresponding to "dir" out of all the "avail"-able ones
double section = 360/avail;
double halfsection = section/2;

dir = correctdir(dir+halfsection);
return trunc(dir/section);

Looks a wee bit prettier right? :D
(I edited it abit for easier reading)
So if there's 16 available angles, then pass that to avail. For direction 0 it returns the image ID 0. Then it continues clockwise (I think). The last before a whole lap is image ID 15. Correctdir() is just a function which checks if that value is within bounds 0-360.

You can edit it so the function only contains one single row, if you want to be leet-haxx0r.

Just debug and have fun!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this