Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: JWinslow23 on March 11, 2014, 01:21:19 pm

Title: Axe Pseudo-physics help?
Post by: JWinslow23 on March 11, 2014, 01:21:19 pm
I need help with calculations for bouncing a ball off of a moving, curved surface (and one static, straight one). I know that trig is involved, but I don't know exactly what calculations to make (and since articles are still being ported through SMFs, that's no help)!


Help? :-\
Title: Re: Axe Pseudo-physics help?
Post by: Matrefeytontias on March 11, 2014, 02:32:54 pm
Okay so I've never done that before, but I gave it a quick think and that's what I thought of.

Let's say you have a curved surface sprite that is 16 pixels wide. Let's make it look like this :

(http://img.ourl.ca/sprite.png)

Now you have to build a 16-entries normal angles table. By that I mean a table that will hold 16 values, one for each X coordinate on the sprite, and which will represent the normal angle of the pixel on that coordinate. I don't think you have to calculate them, just guess them based on what you see. Of course, they had to be in the range 0-255 and not 0-359.

(http://img.ourl.ca/spritesAndAngles.png)

Using these angles requires all of your velocities to use polar coordinates. That means that your ball will not have X, Y, VX and VY coordinates (VX and VY being velocity amount for X and Y coordinates), but X, Y, VR and VT coordinates. X and Y will be your ball's coordinates on the screen, like you always used them, but VR and VT will be the polar coordinate for your velocity vector - respectively the length and the angle.

When you hit a pixel - I'll let collisions to you - just grab the X coordinate of the pixel relative to the start of the sprite, get the corresponding angle in the normal angles table and apply symmetry with the velocity angle - I think you'd do velocityAngle += (pixelNormal - velocityAngle) * 2. Then that should be good.

Of course you will have to write the code to handle polar velocity. You might want to apply trig on the angle and multiply the result by the length, to add both results (X and Y) to the ball's coordinates.
Title: Re: Axe Pseudo-physics help?
Post by: willrandship on March 11, 2014, 02:39:37 pm
The curved surface is moving at a static speed, right? If you treat the collision like a static collision, but apply the curved surface's velocity as an offset to the ball's velocity, then subtract that offset from the result, you get the correct result.
Title: Re: Axe Pseudo-physics help?
Post by: JWinslow23 on March 11, 2014, 04:56:49 pm
The curved surface is moving at a static speed, right? If you treat the collision like a static collision, but apply the curved surface's velocity as an offset to the ball's velocity, then subtract that offset from the result, you get the correct result.
Left and right, it will be constant. I'll make the curved object bounce on command, though.
Okay so I've never done that before, but I gave it a quick think and that's what I thought of.

Let's say you have a curved surface sprite that is 16 pixels wide. Let's make it look like this :

(http://img.ourl.ca/sprite.png)

Now you have to build a 16-entries normal angles table. By that I mean a table that will hold 16 values, one for each X coordinate on the sprite, and which will represent the normal angle of the pixel on that coordinate. I don't think you have to calculate them, just guess them based on what you see. Of course, they had to be in the range 0-255 and not 0-359.

(http://img.ourl.ca/spritesAndAngles.png)

Using these angles requires all of your velocities to use polar coordinates. That means that your ball will not have X, Y, VX and VY coordinates (VX and VY being velocity amount for X and Y coordinates), but X, Y, VR and VT coordinates. X and Y will be your ball's coordinates on the screen, like you always used them, but VR and VT will be the polar coordinate for your velocity vector - respectively the length and the angle.

When you hit a pixel - I'll let collisions to you - just grab the X coordinate of the pixel relative to the start of the sprite, get the corresponding angle in the normal angles table and apply symmetry with the velocity angle - I think you'd do velocityAngle += (pixelNormal - velocityAngle) * 2. Then that should be good.

Of course you will have to write the code to handle polar velocity. You might want to apply trig on the angle and multiply the result by the length, to add both results (X and Y) to the ball's coordinates.
...I'm assuming this works with falling with proper accel, right? :-\
Title: Re: Axe Pseudo-physics help?
Post by: Matrefeytontias on March 19, 2014, 10:43:29 am
Well yes, you'll have to handle that. It's pretty easy as soon as you're familiar with binary trigonometry.
Title: Re: Axe Pseudo-physics help?
Post by: JWinslow23 on March 19, 2014, 04:39:29 pm
Well yes, you'll have to handle that. It's pretty easy as soon as you're familiar with binary trigonometry.
I am not. :(
Title: Re: Axe Pseudo-physics help?
Post by: DJ Omnimaga on March 19, 2014, 05:16:14 pm
Well yes, you'll have to handle that. It's pretty easy as soon as you're familiar with binary trigonometry.
knowing JWinslow's age, I doubt he even had the chance to learn trig in depth yet. Probably in 2 years if it's similar to Canada and even then, in Canada, it was optional.
Title: Re: Axe Pseudo-physics help?
Post by: Matrefeytontias on March 20, 2014, 02:35:05 am
Oh ... :/ well I don't know your age, but there are many things you can't do if you don't know trig. Including this. And sorry but I don't feel like doing the work of your future math teacher ; trigonometry is something complicated and I don't know your grade (don't really know how to say it, the year you're in I guess).
Title: Re: Axe Pseudo-physics help?
Post by: TheCoder1998 on March 20, 2014, 02:49:45 am
if i were you, i should look up some turorials about trigonometry.
then you'll understand most of how to do what you want to do