Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Happybobjr on October 09, 2011, 04:55:47 pm

Title: Optimize me plz.
Post by: Happybobjr on October 09, 2011, 04:55:47 pm
Ok, so i have a rotation routine.

Code: [Select]
:For(X,0,95)
:For(Y,0,63)
:cos(A)->D
:sin(A)->E
:If pxl-Test(X,Y)^r
:Pxl-on((X*D-(Y*E)//128,Y8D+(X-16*E)//128)
:END:END:END

And i do that for every pixel on screen.
Anyone know of a fast way to do this?
Title: Re: Optimize me plz.
Post by: AngelFish on October 09, 2011, 05:14:30 pm
Code: [Select]
:cos(A)->D
:sin(A)->E
:For(X,0,95)
:For(Y,0,63)
:If pxl-Test(X,Y)^r
:Pxl-on(X-Y*E//128,Y8D+(X-16*E)//128)
:END:END:END

That's a bit more optimized, although I'm sure Runer could improve upon it.
Title: Re: Optimize me plz.
Post by: Happybobjr on October 09, 2011, 05:20:47 pm
lol.  I was looking more for an optimization in concept.

Like it would be better to only test pixels above (lesser y value) than vertical shift.
Title: Re: Optimize me plz.
Post by: AngelFish on October 09, 2011, 05:32:39 pm
If you didn't mind a 90 degree rotation, then this might be more optimized:

Code: [Select]
:For(A,0,95
:A^12->X
:A/8->Y
:Pt-On(X,Y,RotC(Pt-get(X,Y)))
:END
Title: Re: Optimize me plz.
Post by: Happybobjr on October 09, 2011, 05:42:09 pm
that will only turn 90 degrees though, correct :(
Title: Re: Optimize me plz.
Post by: AngelFish on October 09, 2011, 05:49:33 pm
Yes.
Title: Re: Optimize me plz.
Post by: Happybobjr on October 09, 2011, 07:48:52 pm
I am good now, thanks for trying to help.
Title: Re: Optimize me plz.
Post by: Quigibo on October 09, 2011, 08:45:52 pm
Instead of scanning the pixels in the back buffer and projecting them to the front buffer, you will get better results if you scan the front buffer and inverse-project from the back buffer.  This assures that every pixel is accounted for which won't happen if you do it the other way.

But as far as speed I don't think you can optimize more than that.  As Qwerty said, definitely pre-compute the sine and cosine before your for loops.
Title: Re: Optimize me plz.
Post by: Happybobjr on October 09, 2011, 08:48:51 pm
Ok thanks, but i don't exactly get what inverse-project means.

Didn't realize i put them inside the loop :/.  Thank you very much for that.  Guess i need sleep.
Title: Re: Optimize me plz.
Post by: calc84maniac on October 09, 2011, 08:55:53 pm
Actually, it's better if you get rid of all the multiplication :P

Something like this (untested):
Code: [Select]
cos(A)*2→D
sin(A)*2→E
.Upper left corner (scaled by 256) in B,C
0→B
0→C
For(Y,0,63)
B-E→B→I
C+D→C→J
For(X,0,95)
If pxl-Test(I+D→I/256,J+E→J/256)r
pxl-On(X,Y)
End
End