Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Yay, physics!

This thread is locked; no one can reply to it. rss feed Print
Yay, physics!
hazul
Member #4,338
February 2004
avatar

I have very little knowledge about physics and even less knowledge about how to incorporate it in games (3D). So here I go with more questions.

Bouncing
How do you calculate the bounce of an object when it hits a surface? You have to have some numbers that depend on the materials (bounce-factor?), and the gravity should affect all of this.

Friction
Here's a tough one... I think the correct term is "sliding friction", this just means that if you e.g. push a box along the floor, it'll slow down and eventually stop, again depending on the materials. Also, getting more advanced, friction should cause a ball to roll on the floor, correct? How does all this work?

Rigid-body and soft-body dynamics
What are these? How are they used in games?

Thanks for any help. I know these big questions and that Google is my friend, but I can't seem to find the stuff I'm looking for.

* * * * *
"Multiplayer is actually the best way of not programming a good AI" -ReyBrujo

Tobi Vollebregt
Member #1,031
March 2001

Read this. IMO it's a really good article about particle physics and physics of bodies that are made of particles connected by infinitely stiff springs. It doesn't cover friction however.

________________________________________
website || Zipfile reader @ Allegro Wiki || Download zipfile reader

Kanzure
Member #3,669
July 2003
avatar

Typo.

Quote:

Yay, physucks

There we go. ;D

I can't provide any other help. Just thought to point that out..;)

A J
Member #3,025
December 2002
avatar

Quote:

How do you calculate the bounce of an object when it hits a surface?

what is bounce?
if you can define what bounce is, there is your answer.
for every action there is an equal and opposite reaction. (some smart dude said that). just account for all the energy in your system, and it will all work out, when bodies hit each other, they balance out each others energy in proportion to there mass, a rubber ball will squish, some of that energy will turn into heat.. some pushes the wall.

just account for all your energy and you will be fine.
all the enegry the 'environment' accepts (into the walls/floor/heat etc) should be re-cycled and be available for/from your main character. that way your system never has too much energy in it (chaos), and never has too little (order).

___________________________
The more you talk, the more AJ is right. - ML

gillius
Member #119
April 2000

While AJ is right, bounce is usually measured with a constant of elasticity -- how elastic is the collision. A good number for balls made of reasonable materials is around 80% (20% heat/deformation, 80% reflected energy). A formula you can use is to take the dot product of the ball with the floor normal, then multiply the floor normal by that dot product and (-1 - e), where e is the constant of elasticity (0 to 1), then add the resulting vector to the ball. What I just said should be right or close to it -- I could draw it on a paper but it is harder to explain in text. Play with the constant to get what you are going for. A rubber ball or a tennis ball might be near 90% or higher while a beach ball will be around 10 or 20%, and a velcro ball would be 0% (sticks to surface).

Gillius
Gillius's Programming -- https://gillius.org/

Steve Terry
Member #1,989
March 2002
avatar

If you use vectors it's a simple as a vector multiply in the direction of the gravity, or elasticity if you want to call it that. You don't have to use complex physics equations to make a ball bounce, simply reverse the direction and decrease the velocity by some factor (say .5) or if you want it to bounce longer .95. Heavy objects may have an elasticity of around .05, they just go "thud" ;D

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

gillius
Member #119
April 2000

That's pretty much what I said Steve, except you can't just "reverse the direction". You will have to do all of the math I did to get it to work, and there are no shortcuts and no other way. You can specialize your math, but just because you don't see the constants they are still there, and I believe it is important to know what you are doing. Just like when most progammers here do "x += velocity;" they should know they are actually doing Euler integration where dt is equal to 1 and the true equation is "x += velocity * 1;" If one doesn't know the true math behind things then that person will always have to result to coming to forums to have other people do math equations for them.

EDIT: However, if you want the simple answer, then if all of your floors are horizontal, and you are using dx and dy for the ball and no other forces or anything to consider, then you can simplify the math as you know the results already, and then this should work: "vy = vy * -e;" since the dot product becomes the identity function, and since no other forces exist you don't need to sum things up.

Gillius
Gillius's Programming -- https://gillius.org/

Steve Terry
Member #1,989
March 2002
avatar

Well of course you don't reverse the direction but I didn't go into calculating normals or dot product or anything, just that you can simulate a bounce easily be multiplyign a vector by a constant > 1.0.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

gillius
Member #119
April 2000

Steve, if and only if you make lots of assumptions the original poster did not even imply. The real math is the way I described it. If they have the special case as I said of all walls are axis aligned and they are programming another pong clone, then the simple suggestion will work, but giving the math will allow the OP to do what he wants and optimize it for his situation.

Since he said 3D environment I have a feeling his world is going to be more than the completely flat infinite plane you are trying to simplify it to be.

Gillius
Gillius's Programming -- https://gillius.org/

decsonic
Member #4,150
December 2003

Something i remember from a few days ago(Wierd, i hardly remember things) said:

By Newton: "For every action, there is an equal and opposite reaction."

;)

Programmer's paranoia: Don't trust anybody's code, not even your own.

Human Modeling Tutorials

Gnatinator
Member #2,330
May 2002
avatar

Hey thank you hazul. Indirectly at least.

Because of reading your thread and rereading the article posted by Tobi, I now understand how to do this stuff! I previously looked over that article a few months ago but didnt understand it very well, I put it down and kind of walked away from it.. This morning I reread the thing on my break and now completley understand what they are saying (It like finally clicked) Hurrah! Physics in some of my games now! ;D

Ps: I now reccomend that article aswell ;)

Indeterminatus
Member #737
November 2000
avatar

If you're interested in any way, I can recommend the book "Game Physics" by David H. Eberly. It's quite mathematical, but covers almost every aspect you need for building a realistic 3d physics engine.

Indeterminatus.
-si tacuisses, philosophus mansisses-

_______________________________
Indeterminatus. [Atomic Butcher]
si tacuisses, philosophus mansisses

Karadoc ~~
Member #2,749
September 2002
avatar

Quote:

Typo.

Quote:
Yay, physucks
There we go.

I just thought I'd point out that you wouldn't have a computer at all if it weren't for the great physicists of the past. Yes, I suppose you realise that, but physics is a great think to know about and to understand. Your life will always be better for it once you've come to know physics...

-----------

Go to: