Thread: trajectory: getting a ball to follow a line.

  1. #1
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67

    trajectory: getting a ball to follow a line.

    right. my peril continues. in my effort to make a program which illustrates different trajectories of a cannon positioned at different angles and units of power, i've gotten to a big hook-up:

    (by the way, i'm using the windows gdi)

    yesterday, to my glee, i managed to program a bezier curve to illustrate the aforementioned paths. however, i then realized that although i can make a line show this arc, i haven't the slightest idea where to begin when it comes to making a picture follow this line.

    so anyway, some help would be appreciated.

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Depends how you're doing the line. If you're using Bresenham for example, then you can easily store delta x and delta y values for the ball and increment these every frame.

    But considering that you're talking about Bezier curves, it will be more complex. Delta x and delta y are likely to vary across all points, so it'll be a case of sitting down with the equation and playing with it until it gives you an array of points or can operate stepwise (give you x and y at a time).

  3. #3
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67
    bressenham? what's that? could you tell me, maybe, what you're talking about, or how to use it? i'd check msdn, but i'm responding to this on my psp.
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Never mind. Professor Jack Bresenham came up with a simple algorithm to draw straight lines when he worked for IBM in the 60s. Now that I've realised that you're using GDI functions instead of your own stuff... you've got a long way to go.

  5. #5
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67
    yeah, i kinda said that i was using gdi. but uh, thanks for telling me that my method wasn't as good as some ancient algorithm, then realizing what i was talking about and offering your condolences by telling me i have a long way to go.

    i was thinking though, that maybe using a bezier curve isn't the right way to go, mainly because working with power and angle, i can't always get the angle to act accordingly with the power. for example, the same power with a 10 degree angle goes farther than a 45 degree one. that's a problem.

    I was thinking of implementing some sort of speed variable, which would depend on the power. the speed would slow down over a relative period of time, due to the simulation of air friction.

    the picture i have would follow the slope of the angle, and as the speed decreased, the slope would get nearer to, then less than, zero, and proceed downward in the same way it started. this method would probably also be capable of adding in wind, affecting the trajectory.

    the thing is, i'm sure a billion cannonball trajectory programs have probably been made, so there's probably some genious who's come up with the best way of doing it. i was just looking for those kind of tips.
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding line numbers and concatenating a filename
    By durrty in forum C Programming
    Replies: 25
    Last Post: 06-28-2008, 03:36 AM
  2. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 05:44 PM
  3. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM