Thread: Physics Programming Tutorials?

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    22

    Physics Programming Tutorials?

    Are there any online physics programming tutorials or guides out there?

    I've used the search facility on this forum, couldn't see anything specifically for getting into programming physics for games/simulations etc.

    I'd like to give it a whirl but can't afford a book at the moment.

    Is the basis of physics programming to begin with newtons laws?

  2. #2
    NotSoAvgProgrammer
    Join Date
    Jul 2007
    Location
    Virginia, U.S.
    Posts
    57
    There isn't really any many articles on physics "programing." In games, you are more or less expected to understand the physics, or learn it, then apply it to the game. I have had this problem as well. I am a 15 year old, and have not been able to take many advanced maths. This has limited me to some degree, but you can still get the basic understanding of it.
    Anyways, take a look here.

    Joe
    A quality job is not necessarily a *good* job. A quality job is, by definition, conformance to requirements. Therefore a *good* job, may not be a quality job.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by goatslayer View Post
    Is the basis of physics programming to begin with newtons laws?
    Yes. For games, where simulation fidelity is not so important (you only care that things "look right," not that they actually "are right"), you typically do some simple integration of Newton's laws to figure out where things are and how fast they are going.

    At the very least you need a good working understanding of force and torque. Integration of the equations can be done through a simple finite difference method.

    Can you be more specific about what kind of physics you are interested in?

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by avgprogamerjoe View Post
    There isn't really any many articles on physics "programing." In games, you are more or less expected to understand the physics, or learn it, then apply it to the game. I have had this problem as well. I am a 15 year old, and have not been able to take many advanced maths. This has limited me to some degree, but you can still get the basic understanding of it.
    You actually don't need terribly complicated math to do some pretty cool physics.

    You can find a lot of relevant information by Googling the term "finite difference method." Most of the stuff on the web is geared toward "real" physics simulation, not game-specific, but it is still applicable. Don't let the math scare you -- it actually all boils down to a few multiplies and adds.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    22
    thanks avgprogamerjoe, excellent tutorials there, I'll probably start looking at that immediately, very useful.

    brewbuck, thanks also. I am interested in just basics at the moment, ball bouncing kind of stuff, probably leading into creating some sort of simulation of a larger real-world system, i know i have a wish to simulate the physics involved in the turning over of a piece of paper, but i'd like to try larger systems too. Just for recreational purposes really.

  6. #6
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Rather than learning a whole lot of physics with nothing to apply it to why not learn stuff as and when you need it? I did some maths a while back and I forgot nearly all of it because I never use it. Then again there are some things I use a lot and remember them from frequency of use (which generally relates to how useful they are).

    As for bouncing balls I came up with various imperfect but looked more or less right solutions. For something more accurate maybe check out this the code is in freebasic, but it should give you an idea of the maths involved.

  7. #7
    Registered User
    Join Date
    Sep 2007
    Posts
    22
    you have a point mike_g, but if i were learning physics i would be programming demos for myself with it simultaneously, the idea being not necessarily to remember all the physics, but to learn how and when to apply the physics, as is the nature of learning one would have thought.

  8. #8
    NotSoAvgProgrammer
    Join Date
    Jul 2007
    Location
    Virginia, U.S.
    Posts
    57
    Well, I guess I should ask if you were using 2d or 3d, as 2d you don't even need physics really, you simply have to change the direction. The tutorials I linked are good for both, and are related to game development (as it's on a huge game development site).
    Anyways, 3d physics can get quite complicated. It all depends on what you are programming, a simple pong clone, or a 3d driving game.

    Joe
    A quality job is not necessarily a *good* job. A quality job is, by definition, conformance to requirements. Therefore a *good* job, may not be a quality job.

  9. #9
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Lol, so physics only applies to the lofty heights of the third dimension then? Physics can be done in both 2d or 3d. 2D is simpler and easier to get into. It dosent mean that you cant do cool stuff with it. Check out N. Its just a flash game, but its good fun Theres also some tuts on the site.

  10. #10
    Registered User
    Join Date
    Sep 2007
    Posts
    22
    Neat game mike_g, very nice indeed, i'll have to check out the authors website, learn a bit more about that.

    Yea, on 2D, I think physics does still apply to as much of an extent as your imagination will allow i guess, for example you could simulate dropping a ball from the leaning tower of pisa obviously using the relevant laws to calculate its bounce and then showing that in 2D, or like that game N, you could use creative physics to create your own rules in your own world, but i guess that can only (for the most part anyhow) come from having the knowledge of real world systems and how to apply them.

  11. #11
    NotSoAvgProgrammer
    Join Date
    Jul 2007
    Location
    Virginia, U.S.
    Posts
    57
    I didn't say that you can't use physics in 2d, you just don't have to. all you have to do is add and subtract speed. BTW: N tutorials, are more on collision detection, but they are very useful.
    A quality job is not necessarily a *good* job. A quality job is, by definition, conformance to requirements. Therefore a *good* job, may not be a quality job.

  12. #12
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by avgprogamerjoe View Post
    Anyways, 3d physics can get quite complicated. It all depends on what you are programming, a simple pong clone, or a 3d driving game.
    Not sure where you get this idea. The physics is the same no matter how many dimensions you have.

  13. #13
    NotSoAvgProgrammer
    Join Date
    Jul 2007
    Location
    Virginia, U.S.
    Posts
    57
    Yes, but you have to agree, that the physics for a 3d racing game, will take a lot more than that of a simple pong game.

    BTW: goat, if you are finding the physics too hard, there are always physics libraries out there, but I suggest you go the extra mile, and do it on your own, it will really pay off in the end.


    Joe
    A quality job is not necessarily a *good* job. A quality job is, by definition, conformance to requirements. Therefore a *good* job, may not be a quality job.

  14. #14
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Are there any online physics programming tutorials...?
    I think you'll have better luck if you split-up the task. That is, learn the physics & math, learn the programming, and then make the connection yourself.

    I don’t want to make this sound impossibly hard (you can take some shortcuts), but you are working in three different disciplines - Math, Physics, and Programming!

    If you were in college, you would be required to take calculus as a prerequisite, before taking physics or programming. So, maybe in your 2nd year of programming, you would be ready to take-on a physics-programming project. (I doubt you would find a specalized class in "physics programming"...but it might depend on the school.)

    Once you have the physics & math under control, you are confronted with the limits of the C++ standard library. It can do trigonometry with <cmath>, but it doesn’t do much calculus or differential equations.

    I’ve never done any high-level math-programming*, but I think there are three options -

    1. Write the functions yourself. This might be acceptable if your requirements are limited to a few functions. This might even be what you want to do.

    2. Find an existing physics/engineering-math programming library. I assume you can find an open-source one.

    3. Use a high-level math application, like Matlab or Mathmatica. (Like these, but hopefully something more affordable...)


    If you are making a graphical game, you will also need to learn a 3rd-party graphics library. There are no graphics in ANSI/ISO Standard C++. (Of course, the WinAPI does have graphics so any Windows compiler can do simple graphics.)

    Most games are going to “cheat” on the math. Like mike_g said, imperfect, but good enough. Games need to be fast, and performing all the math in real-time can really slow things up. For example, if a game needs to draw a sine wave, it’s probably not going to calculate the sine of all the points along the wave… It’s going to store a standardized sine wave in a table… i.e. 1000 points along a wave with a height of 100. That table can be generated at compile-time, or when the game starts-up. Those numbers can be retrieved from the table and re-scaled for any hieght/frequency very quickly, when needed.

    On the other hand, if you’re doing something like simulation or movie animation that doesn’t need to be rendered in real-time, you can take as much time as needed to make accurate calculations… Let it run overnight if it needs to.



    * I am planning to do some DSP (digital Signal Processing) programming. I will be using "choice #2". I will use a 3rd-party library, and maybe copy some existing example-code. I don't expect to develop my own functions from scratch!

  15. #15
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by avgprogamerjoe View Post
    Yes, but you have to agree, that the physics for a 3d racing game, will take a lot more than that of a simple pong game.
    Well, that's because Pong doesn't use any physics. When the ball hits the bar or a wall, the velocity along the appropriate dimension is negated. I hardly consider that "physics."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  2. Wiki for Tutorials
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 08-16-2005, 03:03 PM
  3. CProgramming.com should update their tutorials.
    By PorkyChop in forum C++ Programming
    Replies: 17
    Last Post: 09-19-2004, 10:51 PM
  4. Best way to organize tutorials
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 05-30-2004, 04:41 AM
  5. February 1, 2019...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 98
    Last Post: 08-03-2002, 07:24 AM