可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 3 years ago.
Improve this question
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:
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.
Collisions. Equations are simple. It's the implementation that's tough. You don't need the physics class.
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.
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.
回答2:
The OReilly book Physics for Game Developers sounds like it's of use here
回答3:
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.
回答4:
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!
回答5:
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.
回答6:
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.
回答7:
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.
回答8:
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.