Archived

This topic is now archived and is closed to further replies.

TroneX

General Question, or: The Zen of Optimized Code ,-)

Recommended Posts

I always wondered, how these physics engines work. I am aware of the fact, that a complete game consists of several parts working together. There is the Game Engine, the 3D Engine, The Sound Engine, something for the input and the Physics Engine, ... And furthermore, people expect a game to look realistic, sound realistic and above all: Behaves realistic. There are games going to be released in which you can throw a piece of wood against a wall and it will fly physically correct, hit the wall, fall down against some kind of metal barrel, whatever, ... and while it shows up this realistic behaviour it also sounds as if it were for real. How is this all supposed to work on a <1GHz system? How is this supposed to work anyway? Since I am into games as well as most all of you guys, I know, that there is a lot which is simply faked. But I have serious problems understanding how a vehicle is supposed to drive physically realistic above unevenly ground without implementing complex physical behaviour for almost every part of that vehicle and it''s surrounding area. So how does one fake here? Or is it even possible to create something like this completely realistic without a great loss of overall performance? Are there any free physics engines available for studying purpose? (Including samples...) Regards, TroneX
LightBrain website relaunched, BomberFUN only USD 9.99
visit http://www.lightbrain.de

Share this post


Link to post
Share on other sites
Yeah thats the challenge, is getting it to work at 60 FPS
Check out the old game carmageddon II, it ran on a 200 MHz machine and had great vehicle physics. In fact my favorite thing in the world was when your fender would start to come off, then in a tight turn it would go flying, tumbling end over end, and mow down some poor pedestrian... haha.

Also even before that was interstate76, which had heightmapped terrain that you could drive over.

As for HOW to do it? Hmmmmmm wish I knew! You just have to start simple, treating the car as a box to simplify things, then go from there. Probably calculate all the forces on it each frame, and have some fast way to translate that into reactions in the world.

Share this post


Link to post
Share on other sites
often, reality can be approximated by making some simplifications. the movements of an object can be simulated by treating it as a point mass, and defining how it starts to move and rotate if you apply a certain force at a certain point. you just need a position, momentum and mass for linear movement, and rotation, angular momentum and ínertia tensor for rotational stuff. just a few vectors and matrices.
this is not just a trick in programming, but in physics in general.
google for Open Dynamics Engine to find a sophisticated implementation of all this stuff.

i''m not sure about zen, though.

Share this post


Link to post
Share on other sites
I commend ya for your curiosity in such an important topic but none of the pros that know the ins-and-outs of gaming divulge their top secrets. Sure, some author to some game programming book may show you HOW to do something but they sure as hell ain''t gonna show you the BEST way to do something.

About 8 or 9 years ago, I bought "Tricks of the Game Programming Gurus" by Andre Lamothe. For it''s time it was a good book. However, it only showed you how to get off the ground and make something happen. The optimizations were up to the programmer. The section on Raycasting was absolutely pathetic! I was able to write a better raycaster in a matter of hours! (All game programming books that I''ve purchased since seem to follow suit)

Now, does this make me a better programmer than Lamothe? Absolutely not! (even tho at the time, in all my pride, I thought so) The reality of it is that Lamothe could have easily written a better raycaster but why should he divulge hid secrets that make him the Alpha programmer god (or some such)?

I recently bought "Physics for Game Developers" from O''Reilly & Associates... they so rule =) Anywho, they discuss everything on how to make something HAPPEN but they don''t give you the tricked-out optimized code. They just give a lot of formulas. It''s up to the programmer to decide how "optimized" they want to get.

If you create a game which involves only two moving objects at any one time, the code in the book is more than enough for you. Therefore, why should the author provide more? Now, in my case, where you need 5,000 to 15,000 moving objects at any given time, you need to make cut-backs and optimizations. That''s up to me, the programmer.

This is getting a lot longer than intended but my point is, the optimization is up to the programmer. No publication is going to give yout this. I''m not going to give you this. No one on these fora are going to give you this. We don''t know what you want to accomplish and where you need the optimization.

So, in closing, figure out what you want to do, make it happen on a small scale and then make optimizations as you increase the volume of activity. Then post it in the GD Showcase so we can play it =)

- Jay


[ Here, taste this ]

Share this post


Link to post
Share on other sites