Hi
Please let me know is it possible to make a sprite follow a parabolic path and move or rotate sprite at all angles. I am trying to use parabolic equations but i am stuck in this.
Printable View
Hi
Please let me know is it possible to make a sprite follow a parabolic path and move or rotate sprite at all angles. I am trying to use parabolic equations but i am stuck in this.
Hi,
it is possible to move a sprite in any path that you can calculate. What you need is a simple function that will return position for any point in time. Something like:
f(t) = (t * vx, height - t * t * vy) = (x, y)
Let me explain:
- t = time in miliseconds
- vx = horizontal speed
- vy = vertical speed
- height = height of the screen
What you need to do is call this function in the Update method to get the position for that point in time and then use the result to position the sprite. Once you have a position, it is easy to draw it. As for rotation, this depends on the target framework.
Which framework are you using for game development?
Thanks for help
I am working in J2me. I was trying to implement something like this as i have already found angle.
Basically these are equations for projectile motion.
x =(initial_velocity*t_time*Cos(angle));
y =(initial_velocity*t_time*Sin(angle)-0.5*gravity*(t_time)^2);
Yes, the expressions in #3 are the correct ones.
For the rotation stuff, there is no direct, built-in support in Java ME. You can experiment with using 3D library for 2D rendering (if the target devices have M3G support), or you can implement some bitmap rotator algorithm yourself.
Ok i was able to move a sprite in parabolic path by moving sprite x,y each time.But that was not accurate as i can't use decimal values.
I have practically no knowledge of 3d library but i will try using M3G.
Can you give me slight idea about bitmap rotator algorithm?
Thanks for support
[QUOTE=dhruvpsaru;909004]Ok i was able to move a sprite in parabolic path by moving sprite x,y each time.But that was not accurate as i can't use decimal values.[/QUOTE]You can use fixed point arithmetics. Instead of working with x, work with x*100. Addition and subtraction remains the same, multiplication needs a division (x*100*y*100=(x*y*100)*100, so you need to divide back the result by 100). In your expression there are no real divisions, but that would also need "fixing" at the end as 100/100 disappears. For working with 0.5*gravity, you end up with 50*gravity of course, but that is more of a pre-calculated constant anyway.
In the computing world that 100 is usually a power of 2, like 256 (a complete byte, out of the 4 you have in a 32-bit integer), this way the "fixing" divisions/multiplications can be done with the shift operators ( >>8 instead of /256 ), which is faster.[QUOTE]I have practically no knowledge of 3d library but i will try using M3G.[/QUOTE]Me neither, but it is absolutely sure that there are tutorials for it.[QUOTE]Can you give me slight idea about bitmap rotator algorithm?[/QUOTE]I provided such stuff once, in [url]http://www.developer.nokia.com/Community/Discussion/showthread.php?78676-How-to-rotate-an-image[/url], just it is (Symbian) C++.
The idea is not difficult:
1- calculate the corners for the rotated shape (sin-cos things, you already know)
2a- walk the edges between these corners, also interpolating the texture coordinates
2b- store the leftmost/rightmost coordinates and the respective texture coordinates for each y-position you traverse while walking the edges
3- fill the lines: you have the leftmost(L) and rightmost(R) coordinates for each scanline, and the respective texture coordinates(LU,LV,RU,LV)
In step 1 the texture coordinates just rest.
In step 2 the "lines" should be interpolated vertically, since you need a single x coordinate for every y position
In step 3 the interpolation is horizontal, since you want to draw each pixel between L and R in the given line
You may want to ignore the DDA magic, and use fixed point stuff instead.
ok i will try that..
Thanks
Ok please let me know
Will using m3g slow my game?...
[QUOTE=dhruvpsaru;909044]Will using m3g slow my game?...[/QUOTE]I do not know, I have no experience with M3G.
ok ..
Thanks for support
By the way, it may be worth mentioning here that there are specialized Java ME boards hosted on this site too: [url]http://www.developer.nokia.com/Community/Discussion/forumdisplay.php?3-Mobile-Java[/url]
thanks and i started with m3g and trying to get hold of it..
By the way thanks again
awesome!
Thanks for sharing with us :)