Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: Demon on July 15, 2006, 01:02:00 pm

Title: [83+ BASIC] Rotating matix data...
Post by: Demon on July 15, 2006, 01:02:00 pm
What would be a quick way to rotate a Matrix 90 degrees in either direction?  And if you ran the same code again it would keep rotating it in a circle?

Second question:  how would you make something move radially around a point (IE, the center of the screen) on the homescreen (not the graphscreen), so say in a "defend-the-castle" style game where you could have to shoot all the enemies coming your way, how would you rotate a character around whatever's in the center of the screen?
Title: [83+ BASIC] Rotating matix data...
Post by: kalan_vod on July 15, 2006, 06:11:00 pm
I think it would only work effeciently by going through the entire matix and rotating it. It wouldn't be too hard to make a rotating point, if you would like I could show some code for one.
Title: [83+ BASIC] Rotating matix data...
Post by: Demon on July 15, 2006, 06:20:00 pm
QuoteBegin-kalan_vod+Jul 16 2006, 12:11 AM-->
QUOTE (kalan_vod @ Jul 16 2006, 12:11 AM)
...if you would like I could show some code for one.  

 Sure.
Title: [83+ BASIC] Rotating matix data...
Post by: Liazon on July 16, 2006, 03:06:00 am
man, I wish I remembered this from math class.  To rotate a matrix, you need to multiply it by the right kind of matrix of the same size.  This probably only works for square matrices though.

I think there's a formula for determining what to do.  I'll get back to you on that, but first, are the matrices square?

edit: oops, I was confusing this with 3D math.  Never mind.
Title: [83+ BASIC] Rotating matix data...
Post by: Speler on July 16, 2006, 04:00:00 pm
QUOTE
Second question: how would you make something move radially around a point (IE, the center of the screen) on the homescreen (not the graphscreen), so say in a "defend-the-castle" style game where you could have to shoot all the enemies coming your way, how would you rotate a character around whatever's in the center of the screen?

You would use sin( and cos( functions to do this inside something similar to a for( loop with the radius of the circle outside the two trig functions.

For example:

While 1
for(A,1,360
pt-On(10sin(A),10cos(A
pt-Off(10sin(A-1),10cos(A-1
End
End

Don't have enough experiance with matrices to answer the first question though sorry.
Title: [83+ BASIC] Rotating matix data...
Post by: kalan_vod on July 17, 2006, 04:37:00 pm
Well, what super speler said is true and it works fine (but he wanted to use it on the home screen). If you wanted to use this on the graph screen I could make something better than what I am about to post...Well I made two versions of this, and the one I posted is using a list >.>, the other was slower and bloated...but didnt use lists :Ptongue.gif.

QUOTE
:ClrHome
:"OO
:Output(4,8,Ans
:Output(5,8,Ans
:10
:3,9,3,Ans,4,Ans,5,Ans,6,Ans,6,9,6,8,6,7,5,7,4,7,3,7,3,8→L1:3→A:Ans→C:9→B:Ans→D:1→E
:Repeat θ=45
:Output(C,D,"
:L1(2E-1→A:L1(2E→B
:Output(A,Ans,".
:Ans→D:A→C
:Repeat Ans
:getKey→θ
:End
:E+(Ans=26)-(Ans=24
:Ans+12(‾(Ans=13)+not(Ans→E
:End
Title: [83+ BASIC] Rotating matix data...
Post by: Demon on July 17, 2006, 05:04:00 pm
That one works pretty good.  But I think I like the one that uses the sin and cos functions better because it would be easier to tell if you're making a turn and collide with something without having to use matrices.
Title: [83+ BASIC] Rotating matix data...
Post by: kalan_vod on July 17, 2006, 05:41:00 pm
Yes, but you asked for something using the homescreen. If you could incorparate those functions into using the homescree, if would work best.
Title: [83+ BASIC] Rotating matix data...
Post by: Demon on July 18, 2006, 06:04:00 am
Hmm...  I suddenly got an idea and now I like yours better...
Besides, I need to an ASCII game.  Every since I learned the wonders of xLIB, I haven't done anything in pure ASCII since...  time to revisit...
Title: [83+ BASIC] Rotating matix data...
Post by: kalan_vod on July 19, 2006, 11:35:00 am
So, the flipping sprite routine you added in your sprite program is going through the matrix?
Title: [83+ BASIC] Rotating matix data...
Post by: Demon on July 20, 2006, 04:33:00 pm
Yeah, in the pixel editor, it does rowSwap to flip vertically, so that's no prob, but there's no colSwap command, so I had to make it go through half the matrix to flip horizontal.
Title: [83+ BASIC] Rotating matix data...
Post by: dinhotheone on December 09, 2006, 11:36:00 am
i'm not sure if you still care after these 4 months but i recently wrote a sprite rotator for a sprite editor pakage (basic) i was making. it flipps the sprite 90 degrees. but i think it would work for you. the main thing is that you take the matrix and decalre another matrix with flipped dimension so 3x2 is 2x3 then you do a nested for loop to hit all the originol dimesions and in the for loop you do
[matrix1](a,c)->[flippeddimensionmatrix]((original left,right dimension) + 1 - c,a))

in actuality the code i had was:

dim([A] -> LSize
{LSize(2),Lsize(1)} -> dim ([J]
for a, 1, Lsize(1)
for c, 1, Lsize(2)
[A](a,c) -> [J]((Lsize(2) + 1 - c), A)
end
end
[J] -> [A]
delvar [J]
Title: [83+ BASIC] Rotating matix data...
Post by: Halifax on December 09, 2006, 11:47:00 am
dinhotheone your a little wealth of knowledge aren't you :)smile.gif lol sweet routine
Title: [83+ BASIC] Rotating matix data...
Post by: DJ Omnimaga on December 09, 2006, 11:59:00 am
that sound nice, that can be cool in addition to xLIB flip sprite routine, which flip sprite horizontally only though
Title: [83+ BASIC] Rotating matix data...
Post by: Demon on December 09, 2006, 06:37:00 pm
Wow.  And it's such a simple routine, too...
I'll try that, but instead of using a matrix, I'll make it use a Finance var so you can rotate really big selections without worrying about memory...
Title: [83+ BASIC] Rotating matix data...
Post by: dinhotheone on December 12, 2006, 10:24:00 am
happy i could help but which finiance var are you using? i didn't know any of them could store more than one piece of data.
Title: [83+ BASIC] Rotating matix data...
Post by: Demon on December 12, 2006, 11:47:00 am
And that's all I'm storing is one peice of data in it.  The vertical image flipping routing switches out each bit one by one and uses a finance var to remember what's in the one it's about to overwrite.

I was thinking that I could make it do that to rotate too, but I can't think of how I'd do that without having to draw it out on paper and look at it for a little while...
Title: [83+ BASIC] Rotating matix data...
Post by: dinhotheone on December 13, 2006, 10:01:00 am
oh i understand. just thought i was missing something