Find the answer to your Linux question:
Results 1 to 9 of 9
Hi Guys, I am writing a game in c++ for which I need a physics engine for a more natural and universal behavior of the objects in the game...I have ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5

    writing physics engine in c++


    Hi Guys,

    I am writing a game in c++ for which I need a physics engine for a more natural and universal behavior of the objects in the game...I have searched a lot on the net but i couldnt find any good tutorial on how to develop a physics engine in c++.

    Please help me out as I am unable to proceed further.

    As this is my first game...I have attached the files so that you can point out improvements in my code or possible design deffects. I am still learning C++ so your comments will be very valuable for me.

    Thanks

    LinuxGuy
    Attached Files Attached Files
    Last edited by linuxguy2011; 05-19-2011 at 03:41 PM.

  2. #2
    Linux Newbie user-f11's Avatar
    Join Date
    Feb 2011
    Location
    Sofia, BG
    Posts
    185

    RE: What does 'psychic engine' mean?

    You should be kidding asking this forum about this. Before writing the code, you should make a conceptualization of what you call a 'psychic engine' (maybe an expert system in psychology) ... and this is usually done before writing the software, not after.

    Actually what do you mean by 'psychic engine'?
    By definition: A psychic is a person who professes an ability to perceive information hidden from the normal senses through extrasensory perception (ESP).
    Most probably you don't intend to make a computer simulation of a master psychic.

    In my view connecting 'online' the senses of the people playing on a computer with the computer program (if you want to do this) is not entirely safe ... both to the people and to the computer (not to talk about their extra senses and instincts).

    If you want to make 'offline' mocking mirrors of the game participants as 'image and resemblance' of their everyday behavior when playing the game (as types of behavior, without connecting their actual senses and instinct reactions to the computer) - this is another story. Ask an expert in psychology about this and make jointly with him a conceptualization of the domain (emotional reactions to particular situations).

    BTW the software code is your least problem.

  3. #3
    Linux User
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    260
    Quote Originally Posted by user-f11 View Post
    Actually what do you mean by 'psychic engine'?
    User-f11, I believe he said PHYSICS engine, not psychic engine! Its actually really easy to make a psychic engine. Just write an infinite loop that takes a line of user input, ignores the input, then outputs variations of this statement: "Hmmmm... I see! But I foresee that you will face terrible hardship and disaster in the very near future, but I can help you avoid it if you pay me more money." -- Bonus points if your output can be tuned to respond to certain keywords in the user's input statement.
    Quote Originally Posted by user-f11 View Post
    BTW the software code is your least problem.
    You are definitely correct about this, User-f11.

    You ask, "how can I develop a physics engine in C++?" The answer is simple: learn physics and mathematics!!!. Learn C++ too. Actually, in my experience, learning a programming language is a good way to learn math. But if you don't know the math, you cannot develop a good physics engine, no matter how good you get at C++. Learning about linear algebra, integral calculus, and differential equations is essential. Then, get a good matrix computing C++ library, and a differential equations solving C++ library, and learn how to use them. You will become a reasonably competent physicist and software developer in 6 to 10 years, depending on how committed you are. I am not exaggerating.

    It is better to just use an existing physics engine anyway. A good physics engine takes hundreds of skilled and learned physicists and programmers years to make it work well. They need to write the code, debug it, test it, debug it some more, optimize it (to make sure it doesn't slow your computer to a halt), and then debug some more. It is very hard to do! One person working alone simply cannot do better, no matter how smart they are. It takes a very long time to learn to use an existing software, but not as long as developing one.

    Take a look at Open Dynamics Engine (ODE). An even better one is the Bullet physics engine. Bullet is licensed under the zlib license which is just as good and free and open as the GPL.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,601
    Re. ramin.honary's answer.

    Couldn't put it better myself! To write a physics engine, you need to know the physics. Case in point: back in the early 1980's when the first PC came out, my friend Dale Jurich (author of the first PC fortran compiler) wrote the first pool game for the IBM PC (published by IBM). Even on a 64K PC, the graphics and interactions were truly real-time, even though the PC could not process the computations that fast. How? Because he pre-computed the physics of how the balls and "English" would work and stored them in data structures so that most of the work was just simple data lookups.

    As ramin.honary said, the first thing you need is to understand the physics (and math). Then, you can decide on a reasonable approach to solve the problems you are going to face. Some parts can be pre-computed. Other parts will need to be computed dynamically, in real-time. As my signature says: "Sometimes, real fast is almost as good as real-time"...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Linux Newbie user-f11's Avatar
    Join Date
    Feb 2011
    Location
    Sofia, BG
    Posts
    185
    In the capacity of getting understanding (at last) what the question actually is I would like to add something.
    Yes, learning physics after mathematical modeling is not entirely bad idea, but if you learn the three classes of impossibility in physics (the books of Prof. Michio Kaku) some day you may become without competition in the region.

  6. #6
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5
    Hmmm....I am good at maths and physics, specially physics. I dont usually like to use code which i can write myself. In this case since both of you have suggested that writing physics engine is going to be like chewing iron balls...still i want to taste the pie.

    Rubberman pointed out a good strategy to pre compute some cases.

    Anyway I am determined to write a physics engine of my own. I just need a simple physics engine which obeys Newtons laws and is light weight and fast.

    I have been sitting all days and trying to write something and dont yet know how to proceed. Right now i have created a generic sort of object list (which you can see in the source code provided). I can save any sort of objects in the list which have similar properties like position, mass, etc. etc.

    One change i want to make to my code is to add vectors.

    My plan is to feed this list to the physics engine which can then do calculations of all the forces acting on an object and determine the path the object will follow...Is that hard I dont think so...but finding how to start is definatly hard.

    I will post some code if i have written something significant. Please let me know if anyone has any good ideas. Writing a physics engine is going to be a great experience...after all..

    No man's knowledge can go beyond his experience.

  7. #7
    Linux Newbie user-f11's Avatar
    Join Date
    Feb 2011
    Location
    Sofia, BG
    Posts
    185
    RE: '...writing physics engine is going to be like chewing iron balls...'

    You don't really believe this and think the doing physics is something like fckng around.
    Let me tell you something.
    In ancient Rome there were people building 6000 km of aqua-ducts ... because of not knowing an elementary law of physics (the Law of Archimedes for the interconnected vessels).
    In the last century there were people waging over 25 wars and conflicts worldwide among which 2 world wars ... because of not knowing an elementary law of physics (the class of impossibility of the compound interest).
    Nowadays there are people who mislaid the global financial system in the Dimension X ('out of control and beyond recovery') ... because of not knowing an elementary contradiction of the infinite power series (of the Modern Money Mechanics) and the behavior of the recursive function (future value of money calls itself) with the constraints of the physical world.
    How far will you go?

    Dude, take an expert in physics with you and ask him the proper questions (for expert knowledge acquisition): What if ..? How to ...? How far will this go ...? Is it possible ... ? What happens when ... ?

    ... in that direction.

  8. #8
    Just Joined!
    Join Date
    Sep 2011
    Posts
    1
    Hi Linuxguy,

    I posted this earlier but it did not appear in the thread. ??

    I agree with the other posts that building a full fledged physics engine is a huge task. However building a light weight simple physics engine may be difficult but not impossible. Certainly worth an attempt if for no other reason than the huge wealth of knowledge that you will come away with.

    I am new to this forum so can't post links to some excellent material so you will have to search for them. Google searches for the phrases in bold will get you to the material.


    gaffergames game-physics Covers the basic of 3D Physics objects with straight forward clean and simple sample code with examples that you can get up and running very quickly. A good point to start covers vectors etc.

    olivier renault SAT Collision Demo
    look for the listing labled _oli You will have to put up with some garbage on this website but the downloadable zip files are invaluable resources on SAT Collision Detection in 3d with working examples. A search for his name plus sat collision detection will also turns up some very useful threads on Gamedev.

    jameswells REngine Simple Game engine with basic physics and collision detection designed by James Wells from scratch, working code and excellent information. explains all you need to know in terms for those without a degree in physics or math. A demonstration that a simple physics game engine can be built.

    Enjoy and learn.
    Milosav

  9. #9
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,601
    A google search on the terms "source code for physics engine" returns a number of useful links as well.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •