4

I taken math in college (trigonometry, calculus II...) but I don't know why you use tan, arctan, etc., in game physics. I know I can find working code and understand everything except why I am using a particular trig function, but I don't want that.

I want to know why I am using arctan or sin. Where can I learn about why I am using that particular math function to make a ball bounce realistically?

Thanks for any help.

EDIT: Do I need to have taken an entry level physics class to understand game physics?

1
  • Remember that textbook math and physics only get you part of the way through the problem of game physics programming. The biggest challenge, from my experience, is casting the problem into discrete units of time. Assume your game logic runs at 90 frames per second. Do you have your ball bounce on one of those frames? Or can your ball bounce at some time between frames? How do you find the time? A binary search? A linear estimate? How often do you apply gravity, etc.
    – Nosredna
    Jul 11, 2009 at 15:51

8 Answers 8

10

You are using trig, essentially, to convert between different representations of the same world. A velocity can be expressed in a 2D world as one angle and a magnitude. Or as a delta x and a delta y.

You're using sine and cosine to convert from (in 2D again) polar coordinates to rectangular coordinates. You're using arctan to go the other way. (Hopefully, your language has an arctan2 function to get you into the correct quadrant.)

You don't strictly need the trig--I've done entire 3D commercial videogames in vectors, including all the camera moves. If you learn the relationship between vectors, matrices, and angles, you'll know how.


Edit to address the question's edit:

Do you have to take an entry physics class for game physics?

It can't hurt. It depends on how realistic you want your physics. There's a lot of fake physics in games and there's some "real" physics, too. I did a whole billiards game with just a couple equations. Let me address a couple of common areas.

  1. Collisions. Equations are simple. It's the implementation that's tough. You don't need the physics class.

  2. Friction & spin. This is hard in discrete time no matter how well you know textbook physics. Some of this you'll end up faking, but it helps to know the real stuff.

  3. Strings, pulleys, levers, stacked boxes, etc. Yeah, take the class.


Another consideration is how much of your game is physics-based and how much isn't. If a giant monster throws a building at another building, what happens? The building may have a falling animation that is not physical. What happens if a monster's tail sweeps through a building as a result of an artist's animation of the character? Very few games are 100% physical.

1
  • Also, given how expensive such math has been to calculate (in terms of the operators implemented by most processor instruction sets), many games approximate, cache or otherwise shortcut the calculations to reduce load as much as possible. Jul 11, 2009 at 18:04
5

The OReilly book Physics for Game Developers sounds like it's of use here

1

Your problem is one of physics, not math. Check out a basic physics textbook. Specifically sections on newtons laws of motion, collisions, projectile motion, and gravity. For a more detailed study in how things move, the topic you want is called dynamics. (Even entry level dynamics books can be a little intense, but they're in virtually any mechanical engineering curriculum)

The formulas you end up using in coding game physics are the end product of applying physical laws to a virtual model that you design to make up your game world.

2
  • There are different types of physics. Will the 101 text book do it? That's the one class I didn't take (yet). To ask another way. Is there a book I can use from the bookstore...for dummies without taking labs?
    – johnny
    Jul 11, 2009 at 15:28
  • I found my statics and dynamics textbooks very useful when programming a physics engine. Conservation of momentum (linear and angular) and conservation of energy are the basic equations that will produce the whole system.
    – markets
    Jul 11, 2009 at 16:04
1

I'd recommend Game Physics Engine Development. I've only read some of it so far, but it seems pretty good to someone who is happy with a bit of calculus.

A colleague of mine bought the O'Reilly book (mentioned by Brian), but he complained that there weren't enough actual "direct application" and usage examples. I haven't read it to compare it, so this is a second hand opinion!

1
  • I'd recommend Eberly's "3D Game Engine Design". That focusses a bit more on the collision detection rather than restitution, though.
    – markets
    Jul 11, 2009 at 16:05
1

If your goal is strictly to learn about game physics, your best bet is to stick with books on game physics and not take a real physics class.

Physics is a vast field, and the goal of any good teacher or intro book will be partly to introduce you to the beauty and depth of this field. This would probably be good for you to know in general, but not for programming games. For games you just want the basics so things look sort-of right. Math and algorithms seem more relevant to game programming.

That is, it seems much more relevant to have a good and working knowledge of what a sine is (since this is used all the time in circular motion and other geometric calculations involved in games), and where to apply it, etc, than to know the meaning of coefficient of friction or Archimedes principle or the electron-proton mass ratio.

0

Sometimes it is necessary to rearrange equations in order to use the trig function which will result in the least loss of floating point precision.

This page has a nice summary of how to make your calculations more robust.

0

Over the years I read quite a couple of books on the topic, but the one that stuck with me the most (because of it's clarity) is "Game Physics Engine Development".

It'll teach you most of the things you need to know, like mass-spring systems, rigid body mechanics, collision detection and simple particle systems. Other books, such as Game Physics are more comprehensive but are way harder to understand because it dives into the math more deeply.

0

Game physics is a pretty huge subject (just like real physics). Most problems like what you describe... objects at motion with simple colliding, bouncing, and the influence of gravity would be covered by an introductory highschool physics textbook. More advanced math/physics, used for things like rendering cloth and water generally aren't taught unless you're taking a specialized university degree focusing on Math or Physics.

Not the answer you're looking for? Browse other questions tagged or ask your own question.