Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Physics and Programming

Name: Anonymous 2010-12-16 12:59

Implementing physics in programs is fuck easy.  Let me illustrate:

Each object has an x, y, and z coordinate.  Per frame it exists in a particular x,y,z coordinate.  To model forces acting on that object, we need two attributes for each coordinate: current velocity (v), and change in velocity per frame aka acceleration (a).

For each frame, using x as an example, do this:
 x.v = x.v + x.a
 x = x + x.v

When forces act on an object, you have to modify a and v accordingly.  Velocites are reduced by division, and directions are reversed by a sign change.  So, say object A and B collide, you can model that like this:
 
 A.[coordinate].v = - (A.[coordinate].v / 1.5)
 and same for B
 
You might want to divide by a factor dependent on the objects weight or mass, so you could define that as well, a w or whatever.

Gravity is easy too.  Just do something like this per frame
 [object].y.v = [object].y.v + .05
 for .05 substitue a weight factored value or other value that works depending on the types of objects

IT'S THAT EASY.

------------------------
Can someone elaborate more on this. Or give more examples.

Name: Anonymous 2010-12-16 13:06

This is all rather naive. Don't do it per frame, do it per second, so you have smooth animation if the framerate jumps around. For example:
Gravity
obj.y.v += sec_diff * 9.80665
where sec_diff is the time-delta since the last frame, in seconds.

Name: Anonymous 2010-12-16 13:12

>>2
Teach me more please.

Name: Anonymous 2010-12-16 13:48

>>3
Change all the other formulae to similar things involving sec_diff.
Except the collision one, scrap that entirely and take an AS-level physics course. Or just use one of the countless thousands of collision models out there.

Name: Anonymous 2010-12-21 17:08

Name: Anonymous 2010-12-21 21:47

Name: Anonymous 2011-02-04 11:34

Don't change these.
Name: Email:
Entire Thread Thread List