Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Trying to use rotate_scaled_sprite()... trouble with 'fixed'

This thread is locked; no one can reply to it. rss feed Print
Trying to use rotate_scaled_sprite()... trouble with 'fixed'
peelemachine
Member #8,085
December 2006

I can scale my bitmap, but I need to rotate it too.

The rotate_scaled_sprite() function needs a 'fixed' argument, unlike stretch_sprite() which lets you specify the scaling in width and height. How do i convert width and height into 'fixed' for scaling?

Thanks

You're damned if you do, and you're damned if you don't.

HoHo
Member #4,534
April 2004
avatar

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

peelemachine
Member #8,085
December 2006

I know about those, but they don't help.

I need to get two different integers into 1 fixed.

You're damned if you do, and you're damned if you don't.

X-G
Member #856
December 2000
avatar

Not possible. At least not what you seem to want to do.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Kibiz0r
Member #6,203
September 2005
avatar

There's no function for what you want to do, you'll have to write the algorithm yourself using some crazy trig I don't care to work out right now. (I'm in class)

Kris Asick
Member #1,424
July 2001

What exactly do you mean by "two different integers"?

If you're trying to combine one integer as the whole value and another as the decimal value, you could try this:

fixed fixed_val = ftofix((float)decimal_int/1000.0f+(float)whole_int);

Though if that's the case, I'd have to question your sanity for keeping track of the two separately in the first place. :P

--- Kris Asick (Gemini)
--- http://www.pixelships.con

--- Kris Asick (Gemini)
--- http://www.pixelships.com

peelemachine
Member #8,085
December 2006

All i want to do is rotate and stretch the sprite at the same time, to a specific width and height. I just want to use the function.

You're damned if you do, and you're damned if you don't.

Kibiz0r
Member #6,203
September 2005
avatar

I believe he wants to keep a sprite bounded by a certain width and height, no matter what the rotation.

Hard Rock
Member #1,547
September 2001
avatar

Quote:

What exactly do you mean by "two different integers"?

If you're trying to combine one integer as the whole value and another as the decimal value

Thats not it at all. In fact the question is quite clear.

stretch_sprite() takes two parameters (width, height to stetch) whereas rotate_scaled_sprite() takes one parameter, the scale.

Anyway to try to answer you question, you cant scale an image like you are doing with stretch blit, as scale requires you to do it proportionately. However you can do this:

fixed scale = ftofix( new_sprite_height/actual_sprite_height)

And use that as a parameter, although this assumes you have kept the stretching proportional. If not then you'll either have to write your own function which lets you do exactly what you are asking as it appears stretch_sprite may not have the functionality you require. Or use a more specific approximation (which you should be able to come up with on your own as mentioned a few time).

_________________________________________________
Hard Rock
[ Stars Dev Company ][ Twitter ][Global Warming: ARA My TINS 07 Entry][Pong Ultra Website][GifAllegS Ver 1.07]
"Well there's also coolwebsearch but we'll let that be an IE exclusive feature" - arielb on the New Browser Plugins "What's better, HTML or Variables?"

Kris Asick
Member #1,424
July 2001

Ok, I see what you're getting at.

Well, if you're only going to scale the sprite equally on both axises at the same time, that's simple enough to do. You simply make a multiplier variable and apply that to the rotate_scaled_sprite() function for the scale argument.

However, if you want to stretch both axises independently, like you can with stretch_sprite(), you need to make a few extra steps and an extra bitmap. Do the following:

1: Make an extra bitmap (we'll call it "xbitmap") large enough to fit the largest stretching your sprite will ever reach.

2: When the stretched size of the sprite changes, clear xbitmap to the masked colour for your video mode, (IE: bitmap_mask_color(xbitmap)), and then call stretch_sprite() on your sprite to draw it to the centre of xbitmap.

3: Draw xbitmap to the screen using rotate_sprite().

Does that help? Note that this method will NOT be very fast at all, since it has to detect and skip over all those empty masked pixels in xbitmap, but it's the only thing I can think of off-hand that will give you independent control over height and width. (Using rotate_scaled_sprite(), you control the overall size, not the height and width.)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

gnolam
Member #2,030
March 2002
avatar

Quote:

Does that help? Note that this method will NOT be very fast at all, since it has to detect and skip over all those empty masked pixels in xbitmap, but it's the only thing I can think of off-hand that will give you independent control over height and width.

stretch_blit()

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

peelemachine
Member #8,085
December 2006

Thanks for the help you guys.

I can live with proportional scaling and rotation, so I'll use the ftofix idea. I didn't know what kind of value the 'fixed scale' parameter needed to be, now I understand. Thanks again.

You're damned if you do, and you're damned if you don't.

Kris Asick
Member #1,424
July 2001

gnolam: ...with rotation. ;)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

X-G
Member #856
December 2000
avatar

His point is that it's wasteful to stretch_sprite onto xbitmap, since the background is just going to be magic pink anyway. Using stretch_blit will be faster and produce the same result.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Kris Asick
Member #1,424
July 2001

Quote:

His point is that it's wasteful to stretch_sprite onto xbitmap, since the background is just going to be magic pink anyway. Using stretch_blit will be faster and produce the same result.

...oh yeah! ;D

I think too fast sometimes... ::)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Johan Peitz
Member #9
April 2000
avatar

[nothing]

--
johan peitz :: things I made

Go to: