Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Help Image/Sprite Rotation

Help Image/Sprite Rotation

Discuss topics that apply across the products, such as the PocketC language, or development in general

Postby dan_priv on Wed Mar 03, 2004 9:22 am

:) Hi all

There's a function in PocketC allowing you to rotate images for 90/180 degrees.

The question now is: Is it possible to rotate an image by a certain value (eg. 5 degrees)?

If there's no such thing, does anybody know about a method to do that?

Help is very much apreciated...

Thanks in advance, with best regards
dan_priv
dan_priv
 
Posts: 4
Joined: Wed Mar 03, 2004 9:07 am
Location: Switzerland

Postby wolfgang on Thu Mar 04, 2004 12:17 am

Rotating by an arbitrary angle is much more complex than 90 and 180 degree, because the - square! - pixel-grid does not match anymore. You'll also need to change (increase) the size of the rectangular sprite to hold the rotated version. You need to determine for each point in the new (rotated) sprite where it "comes from" in the old (original) sprite. If you want to get even more sophisticated, you should weigh the value from adjacent points so the picture becomes smoother and avoids raggedness due to aliasing (even though that works better for photos and at higher resolution than for painted, low-res sprites). Basic transformation:

For all points in the new sprite:

r_new = sqrt(x_new^2 + y_new^2)
phi_new = acos (x_new / r_new) (beware of the special case r_new=0, and also you'll need to treat each quadrant on its own because acos() is not unique across the full circle)

Calculate the original location (rho is the rotation angle):
phi_old = phi_new - rho
r_old = r_new
x_old = r_old * cos (phi_old)
y_old = r_old * sin (phi_old)

Get the color of pixel (x_old, y_old) in the old sprite. This is the color for pixel (x_new, y_new) in the rotated sprite.

Assume the old sprite is x_max wide and y_max high.

r_max = sqrt(x_max^2 + y_max^2)

To be on the save side, so the rotated picture always fits, make the new sprite r_max wide and r_max high.

All those formulas assume the origin (0,0) is in the center of the sprite!

Hope that gets you going!

Wolfgang


Composing music on the PocketPC! - http://www.pdamusician.com
Composing music on the PocketPC! - http://www.pdamusician.com
wolfgang
 
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Postby dan_priv on Thu Mar 04, 2004 12:56 pm

Thank's wolfgang!

This seems to be the solution!

Thanks you very much for your time and tip!!! When I get lucky coding this, I'll ow you a free copy of my Program.

With best regards

dan_priv
dan_priv
 
Posts: 4
Joined: Wed Mar 03, 2004 9:07 am
Location: Switzerland

Postby wolfgang on Thu Mar 04, 2004 6:00 pm

Hi again,

I forgot to mention a few details:

The angle rho is the angle measured from the horizontal axis (x-axis).

I'm not sure acos() is available in PocketC, but I am positive atan() is. The easiest way then is to use:

rho=atan(y_new/x_new)

(again caution with x_new=0 OR EVEN JUST CLOSE TO ZERO, and treat every quadrant separately).

To avoid piling up roundoff/aliasing errors dur to subsequent rotations (a big problem especially with the coarse resolution of a Palm screen), it is best to keep the original (unrotated) sprite in memory and calculate all rotated ones directly from this one, instead of calculating rotation 1 from the original, then rotation 2 from rotation 1, etc.

Wolfgang


Composing music on the PocketPC! - http://www.pdamusician.com
Composing music on the PocketPC! - http://www.pdamusician.com
wolfgang
 
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron