views:

576

answers:

8

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?

+2  A: 

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

Brian Agnew
+1  A: 

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.

Ryan
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
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.
Mark Santesson
+5  A: 

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.

Nosredna
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.
GalacticCowboy
+1  A: 

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!

Rob Levine
I'd recommend Eberly's "3D Game Engine Design". That focusses a bit more on the collision detection rather than restitution, though.
Mark Santesson
A: 

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.

Alex Peck
A: 

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.

Jasper Bekkers
A: 

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.

patros
A: 

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.

tom10