Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
20 May, 2013, 23:51:04 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Sprite/Picture rotating -  (Read 528 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
MGOS
LV5 Advanced (Next: 300)
*****
Online Online

Gender: Male
Last Login: Today at 23:45:26
Date Registered: 29 July, 2011, 16:54:53
Location: Germany
Posts: 295


Topic starter
Total Post Ratings: +73

View Profile
« on: 07 January, 2012, 15:54:33 »
0

I wanted to test the tan-1 function in the latest version of axe and tried to rotate a spite with this little program:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
:ClrDraw
:Draw sprite with size E*F at (0|0)
:For(A,0,E-1)
:  For(B,0,F-1)
:    If pxl-Test(A,B)
:      sqrt(4*A*A+(4*B*B))->D  .four times precision
:      arctan(A,B)->W
:      W+32->W  .Let's rotate that 45 degrees or whatever you like
:      sin(W)*D//512->Y
:      cos(W)*D//512->X
:      Pxl-On(X+32,Y+32) .A little offset
:    End
:  End
:End
:DispGraph

I tried it with only a box and it works, ut this gives me some really bad quality results. When I try to rotate pictures, it is even worse.

Where is the fault in my program? Are the trigonometry functions to low resulution? The square root?
What can I do to make it better?


* ROTATE.BMP (72.05 KB, 192x128 - viewed 163 times.)
Logged

Click those to see more information Smiley
Current   
Projects: 
Happybobjr
James Oldiges
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: Today at 00:20:45
Date Registered: 01 June, 2010, 00:52:05
Location: IN, United States
Posts: 2273


Total Post Ratings: +100

View Profile
« Reply #1 on: 07 January, 2012, 16:41:23 »
0

why are you using arctan?

My rotation routine.

cos(O)->C
sin(O)->E
For (L,0,R)
Pxl-on(({L+L1}-32->G*C)-({L+L1+1}-32->M*E)//128+48,(M*C)+(G*E)//128+32)
L++
End

Where i have indexed all the points used in L1, because my picture was small. {2*n+L1} are x, while {2*n+L1+1} are y values.
« Last Edit: 07 January, 2012, 16:47:58 by Happybobjr » Logged

School: East Central High School

Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Non-Cas |||  OS: 1.1 |||  Build: Old  |||  84+ keypad.   Being lent out
____________________________________________________________
MGOS
LV5 Advanced (Next: 300)
*****
Online Online

Gender: Male
Last Login: Today at 23:45:26
Date Registered: 29 July, 2011, 16:54:53
Location: Germany
Posts: 295


Topic starter
Total Post Ratings: +73

View Profile
« Reply #2 on: 07 January, 2012, 17:35:58 »
0

Ok, thanks. I will try that out.

Edit: works Smiley

Btw I used the arctan to calculate the angle between each point and (0|0), then add an offset to that and draw it down. So basically I transform it to polar first, add the angle I want to turn, and retransform it to rect again.

And you are actually doing that:

X = (XI * cos a) - (YI * sin a) + XOffset
Y = (YI * cos a) + (XI * sin a) + YOffset

Right?
« Last Edit: 07 January, 2012, 18:36:18 by MGOS » Logged

Click those to see more information Smiley
Current   
Projects: 
Quigibo
The Executioner
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: 18 May, 2013, 00:55:01
Date Registered: 22 January, 2010, 05:02:37
Location: Los Angeles
Posts: 2022


Total Post Ratings: +1019

View Profile
« Reply #3 on: 07 January, 2012, 19:22:05 »
0

Not all pixels are being mapped to because you only Pxl-On if there was a Pxl-Test.  This restricts sprites to have the same number of pixels in the best case even though there could be a lot more when the sprite is rotated and I'm not even including the overlapped pixels.  Instead what you have to do is get a bounding box of the destination zone (which could be the whole screen) and then run for loops over the region to see if each destination pixel belonged to the original image.  So you need to find the inverse in your eqaution first of all:

XI = ([X - XOffset] * cos a) + ([Y - YOffset] * sin a)
YI = ([Y - YOffset] * cos a) - ([X - XOffset] * sin a)

Something like that...  So you for loop over the X and Y bounding box, pixel test if (XI,YI) is shaded, and if it is, fill in (X,Y)
« Last Edit: 07 January, 2012, 19:25:07 by Quigibo » Logged

___Axe_Parser___
Today the calculator, tomorrow the world!
Happybobjr
James Oldiges
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: Today at 00:20:45
Date Registered: 01 June, 2010, 00:52:05
Location: IN, United States
Posts: 2273


Total Post Ratings: +100

View Profile
« Reply #4 on: 07 January, 2012, 19:23:07 »
+1

nope, but very close!
Pxl-on(({L+L1}-32->G*C)-({L+L1+1}-32->M*E)//128+48,(M*C)+(G*E)//128+32)
the bolded is the point of rotation
the //128 scales it down because programming trig and math class trig are different, as programming trig (at least here) doesn't use a decimal point.


i have all those extra variables for speed improvement.  when going through a loop many times, especially for larger pictures, it can provide a big speed boost.


Quigibo.  are you sure you don't have your plus and minus sign mixed up?
« Last Edit: 07 January, 2012, 19:25:50 by Happybobjr » Logged

School: East Central High School

Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Non-Cas |||  OS: 1.1 |||  Build: Old  |||  84+ keypad.   Being lent out
____________________________________________________________
Ki1o
LV3 Member (Next: 100)
***
Offline Offline

Gender: Male
Last Login: 26 April, 2013, 00:22:15
Date Registered: 30 January, 2012, 22:19:11
Location: Behind my computer
Posts: 88

Total Post Ratings: +2

View Profile
« Reply #5 on: 07 February, 2012, 00:41:53 »
0

I have a question concerning this particular routine. Would it work for 8x8 sprites? 
EDIT: Also how would go about it so that when I press a button the rotation occurs to a certain degree depending on how long u held it for?
« Last Edit: 07 February, 2012, 00:43:45 by Ki1o » Logged

Co-developer of Quasar (formerly M4trix)
Axe programmer - lvl 2
Spoiler for Projects:
Rebirth: The Soul of Icarus (R:TSoI): (5%): Planning Stages
Vulcan's Labyrinth: (0%): Backstory Only
MGOS
LV5 Advanced (Next: 300)
*****
Online Online

Gender: Male
Last Login: Today at 23:45:26
Date Registered: 29 July, 2011, 16:54:53
Location: Germany
Posts: 295


Topic starter
Total Post Ratings: +73

View Profile
« Reply #6 on: 07 February, 2012, 07:26:10 »
0

I have a question concerning this particular routine. Would it work for 8x8 sprites?  
EDIT: Also how would go about it so that when I press a button the rotation occurs to a certain degree depending on how long u held it for?

Yeah, of course. This routine works for any sprites, any size. If you store each black pixel's coordinate to the memory before the main loop, it'll be much faster.
« Last Edit: 15 February, 2012, 16:28:24 by MGOS » Logged

Click those to see more information Smiley
Current   
Projects: 
Keoni29
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: Today at 21:50:48
Date Registered: 15 March, 2011, 16:23:33
Location: The Netherlands
Posts: 1113


Total Post Ratings: +146

View Profile WWW
« Reply #7 on: 15 February, 2012, 13:59:58 »
0

I have a question concerning this particular routine. Would it work for 8x8 sprites?  
EDIT: Also how would go about it so that when I press a button the rotation occurs to a certain degree depending on how long u held it for?

Yeah, offcourse. This routine works for any sprites, any size. If you store each black pixel's coordinate to the memory before the main loop, it'll be much faster.
Nice one. Now add grayscale, zooming and skewing.
« Last Edit: 15 February, 2012, 14:00:20 by Keoni29 » Logged


Spoiler for Hidden:
Last signature update 10:55 april 22nd 2013
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 23:49:25
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50206


Total Post Ratings: +2611

View Profile WWW
« Reply #8 on: 16 February, 2012, 07:14:06 »
0

How fast does this routine runs btw? I'm curious if it could be used in games?
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
MGOS
LV5 Advanced (Next: 300)
*****
Online Online

Gender: Male
Last Login: Today at 23:45:26
Date Registered: 29 July, 2011, 16:54:53
Location: Germany
Posts: 295


Topic starter
Total Post Ratings: +73

View Profile
« Reply #9 on: 16 February, 2012, 07:50:48 »
0

I don't know the exact numbers, but for up to 64 pixel sprites it works quite well in my games.
Logged

Click those to see more information Smiley
Current   
Projects: 
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.419 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.