Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: nemo on June 16, 2010, 04:31:49 pm

Title: Sprite Direction
Post by: nemo on June 16, 2010, 04:31:49 pm
Suppose i have a sprite moving across the screen from left to right, and i want to press a button and it will make a large sweeping arc and change its direction 180°.
this would be its trajectory:
Start:
---->---
            \
             )
            /
---<----
^End

now i'm wondering how i could implement this in axe. keep in mind i want this to be free of any sort of gravity, so the sprite is moving at a constant velocity and all i want to do is change its direction.
Title: Re: Sprite Direction
Post by: Ikkerens on June 16, 2010, 04:35:38 pm
Could be done by using sin/cos to generate the coordinates.
Its called goniometrics (w00t) i learned something at math.

I know how to do this but not in the mood to boot up my comp atm.
Title: Re: Sprite Direction
Post by: nemo on June 16, 2010, 04:37:04 pm
yeah, it's summer. all the math i learned last year (which included sin cos tan  :-\) has been forgotten
Title: Re: Sprite Direction
Post by: Ikkerens on June 16, 2010, 04:40:06 pm
If no one has created something by tomorrow, il create you some commented code...
Title: Re: Sprite Direction
Post by: meishe91 on June 16, 2010, 04:41:53 pm
If I knew more about the cos( and sin( functions in Axe I would help. Unfortunately I haven't much. Maybe later.
Title: Re: Sprite Direction
Post by: Ikkerens on June 16, 2010, 04:46:40 pm
Btw, quigibo (dunno if I spelled that right)
Which mode of angles is axe using? Degrees or Radials?
Title: Re: Sprite Direction
Post by: calcdude84se on June 16, 2010, 04:50:03 pm
You spelled it right.
Since Axe doesn't support floating point numbers, it uses neither Degrees nor Radians. Rather, the input, in range 0-255, corresponds to 0-2*pi radians and the output, in range -128 to 127, corresponds to -1-1.
Edit: 300th post!
Title: Re: Sprite Direction
Post by: Ikkerens on June 16, 2010, 04:55:01 pm
You spelled it right.
Since Axe doesn't support floating point numbers, it uses neither Degrees nor Radians. Rather, the input, in range 0-255, corresponds to 0-2*pi radians and the output, in range -128 to 127, corresponds to -1-1.
Edit: 300th post!
Gz,
Anyway, that's too bad, how are we supposed to make circles or something round then?
Title: Re: Sprite Direction
Post by: nemo on June 16, 2010, 04:58:18 pm
idea: have an x and y velocity, and make sure they ALWAYS add up to 100. then when the user presses a key, you change one of the velocities, thus changing the other. so 50/50 would make the sprite move at a 45 degree angle, while 25 Y velocity with 75 X velocity would make the sprite move at a 22.5 degree angle. i'm not sure if the sprite would move at a constant speed though... you'd have to do some division tricks as well, so you can get good precision.
Title: Re: Sprite Direction
Post by: calcdude84se on June 16, 2010, 05:01:27 pm
That's off-topic, but I'll write you a quick one (should work)
Code: [Select]
.CIRCLE
For(X,0,255
Pxl-On(cos(X)//4+48,sin(X)//4+32
End
Okay, it's not perfect (some points are off-screen), but it should draw a circle
Edit: Did I really type Pt-On( ... fixed
Title: Re: Sprite Direction
Post by: meishe91 on June 16, 2010, 05:25:56 pm
Ya, that routine works for the most part (you do need to change Pt-On( to Pxl-On( and put a DispGraph at the end). Only thing is that the circle produced is sort of square-ish.

Edit:
Here is a screenshot of what I mean.

Edit 2:
Here is one with a sprite.

Also, glad you got use from it, nemo.
Title: Re: Sprite Direction
Post by: nemo on June 16, 2010, 05:44:20 pm
thanks calcdude! it's been modified for my purposes but i doubt i would've come up with that code on my own.
EDIT: the inside of your sprite gif looks like a perfect circle, though.
Title: Re: Sprite Direction
Post by: ztrumpet on June 16, 2010, 09:25:24 pm
Nice circle!  Great job calcdude and meishe! ;D
Title: Re: Sprite Direction
Post by: meishe91 on June 16, 2010, 11:17:50 pm
thanks calcdude! it's been modified for my purposes but i doubt i would've come up with that code on my own.
EDIT: the inside of your sprite gif looks like a perfect circle, though.

That's due to the properties of how sprites are displayed I believe. If it displayed sprites from the center instead of the top-left corner you would get a skewed inner-circle (I believe).
Title: Re: Sprite Direction
Post by: DJ Omnimaga on June 16, 2010, 11:28:37 pm
Wow, despite not looking 100% perfect (the later screenshot) it sure draws circles friggin fast!

Sadly I can't help much though because we did not do a lot of trig at school (it was only people who had advanced maths classes) and most was forgotten since my last math class was 7 years ago
Title: Re: Sprite Direction
Post by: meishe91 on June 16, 2010, 11:42:37 pm
Wow, despite not looking 100% perfect (the later screenshot) it sure draws circles friggin fast!

Sadly I can't help much though because we did not do a lot of trig at school (it was only people who had advanced maths classes) and most was forgotten since my last math class was 7 years ago

Well that is kind of lame that they only left trigonometry for more advanced classes. Personally I learned the basics and such it my freshman and sophomore year (9th and 10th grade in USA). It really isn't that hard of a concept to learn. Maybe I'll try to throw together another tutorial (since Builderboy already has here here (http://ourl.ca/4279/84115)) before I leave or have one for when I get back.
Title: Re: Sprite Direction
Post by: DJ Omnimaga on June 17, 2010, 01:29:40 am
Yeah, I wish they taught us more about it. I learned easier back then too. Today I seem to take longer to learn anything so I will have a much harder time understanding the concepts x.x