Computer Science Canada Modelling a specific sort of curve |
Author: | Insectoid [ Fri Apr 04, 2014 1:24 pm ] |
Post subject: | Modelling a specific sort of curve |
I'm starting to build a game very similar to Steambirds. I'm having trouble coming up with a way to recreate the movement planning for the aircraft. I tried using Bezier curves, but they don't quite fit the problem (or I can't manipulate them correctly) and seem like overkill for this task. Anyone got any ideas? |
Author: | Zren [ Fri Apr 04, 2014 4:35 pm ] |
Post subject: | RE:Modelling a specific sort of curve |
Constant rotation rate + linear movement. Draw Arc + Draw Line. That might be even harder that beziers though. Steambirds is deffinitely using a bezier though. |
Author: | Insectoid [ Fri Apr 04, 2014 5:08 pm ] |
Post subject: | RE:Modelling a specific sort of curve |
I think I might have a solution. Draw the path as a chain of 3 links (4 points) of the same length and with the same angle between them. Clicking & dragging the last point moves the whole thing to satisfy those conditions. These 4 points describe the bezier curve of the flight path. Figuring out a solver for this will be a pain, but I'm confident it will work. |
Author: | Insectoid [ Fri Apr 04, 2014 7:52 pm ] | ||
Post subject: | RE:Modelling a specific sort of curve | ||
I've been playing around with it a little and came up with this solution (it's a bit messy). Ended up using a trigonometric bezier to model the path. Click & drag to move the bezier around. I can't figure out a way to make the 2 lines that define the bezier the same length.
|
Author: | Raknarg [ Fri Apr 04, 2014 8:12 pm ] |
Post subject: | RE:Modelling a specific sort of curve |
Just out of curiosity, why are you using Turing for this project? |
Author: | Insectoid [ Fri Apr 04, 2014 8:39 pm ] |
Post subject: | RE:Modelling a specific sort of curve |
It lets you write small graphical prototypes really quickly (and I can't get Allegro to function properly). Eventually, when I get a functional prototype, I might rewrite it in something more iOS/Android friendly and really polish it up, but I'm not planning that far ahead. |
Author: | Raknarg [ Fri Apr 04, 2014 8:45 pm ] |
Post subject: | RE:Modelling a specific sort of curve |
I used to think so too, but once I got used to Processing, it really changed my mind. Simplicity but with the power of Java. Not saying you should change what you've already started, though. Just for future reference |
Author: | Dreadnought [ Fri Apr 04, 2014 11:07 pm ] | ||
Post subject: | Re: Modelling a specific sort of curve | ||
Insectoid wrote: I can't figure out a way to make the 2 lines that define the bezier the same length. Here's how I thought of doing it. If you force the angles between some line to be the same, you can get lines of the same length. Let L0, L1, L2 be the lines from (0,0) to p0, p1, p2 respectively. Force the angle between L0 and L1 to be equal to the angle from L1 to L2. This gives an isosceles triangle with vertices p0, p1 and p2 and lets us solve for the length with the cosine law. Here's what I got (just modified the way you compute p1).
|
Author: | Insectoid [ Sat Apr 05, 2014 1:48 pm ] | ||
Post subject: | RE:Modelling a specific sort of curve | ||
That works pretty well, thanks. I've added a little more functionality to it, and came up with this. Same deal, click & drag the blue dot to move it. Press enter to advance the bezier, sort of. There is an issue when p0 is pointing right-to-left; the slope gets reflected around the y axis (you'll see what I mean). Pretty sure this has something to do with the CAST rule of trig, but I can't figure it out right now. It's a long time since I did any trig. Also, if p2 = origin (the opposite end of the bezier), the program will crash due to division by zero in the slope function. This is normal and will be fixed by limiting the values of p2 later on.
|
Author: | Dreadnought [ Sun Apr 06, 2014 12:44 am ] | ||
Post subject: | Re: Modelling a specific sort of curve | ||
Insectoid wrote: There is an issue when p0 is pointing right-to-left; the slope gets reflected around the y axis (you'll see what I mean). Pretty sure this has something to do with the CAST rule of trig, but I can't figure it out right now. It's a long time since I did any trig. You could try changing the computation of a2 to something like this
Just causes a problem if a2 = -a0 (division by zero when computing len) |