views:

846

answers:

8

I need to write a very simple 3D physics simulator in Java, cube and spheres bumping into each other, not much more. I've never did anything like that, where should I start? Any documentation on how it is done? any libraries I could re-use?

+1  A: 

Assuming you want to get started on how to do it, best way to start is with a Pen and Paper. Start defining focal points of your app (like the entities sphere, cube etc, rules like gravity, collision etc, decide hierarchy of objects etc..)

If you know how to do this, and want a primer on the technology side, Swing is a good option to make UIs in Java.

Also take a look here: http://www.myphysicslab.com/

Swanand
+6  A: 

Physics for Game Programmers By Grant Palmer (not Java)

Phys2D (Java code)

TofuBeer
A: 

How about first defining a class for physical object? It has position, velocity, mass and maybe subclasses with other features like shape, elasticity etc.

Then create an universe (class) where to place these physical objects. Sounds like fun :)

Joonas Pulakka
A: 

If you all you need to simulate is spheres/circles and cubes then all you need is a bit of Vector math.

Eg to simulate a simple pool game each ball (sphere) would have a position, 3d linear velocity and 3d linear acceleration vector. Your simulation would involve many little frames which continually updates each and every ball. If two or more balls collide you simply sum the vectors and calculate the new velocities for all balls. If a ball hits a wall for instance all that is required is to flip the sign of the ball to have it bounce back...

mP
That's not physics: no gravity, no elasticity, etc. Fun to do as a starter, but limited.
PhiLho
Most of those are just additional vectors that get factored into each frame. Once you have the simple working its not too hard to add gravity, coR, etc.
mP
A: 

If you want to do this from scratch, meaning coding your own physics engine, you'll have to know the ins and outs of the math behind to accomplish this. If you have a fairly good math background you'll have a headstart otherwise a steep learning curve is ahead.

You can start on this community forum to gather information on how things are done: gamedev.net

Ofcourse you could use an opensource engine like Ogre if you don't want to code your own.

Mez
A: 

Check out bulletphysics. bulletphysics.com is the forum or check out the project on Sourceforge.

Nick
+1  A: 

NeHe's lesson 39 is a good starting point, it's in C++ but the theory is pretty easy to understand.

Ed Woodcock
A: 

A nice java physics library is jmephysics (http://www.jmonkeyengine.com/jmeforum/index.php?topic=6459); it is quite easy to use and sits on top of ODE (http://www.ode.org/) and jmonkeyengine (http://www.jmonkeyengine.com) which gives you a scenegraph (http://en.wikipedia.org/wiki/Scene_graph), again something that you'll need for anything beyond a very simple 3d application.

I haven't used it for some time though, and see that they haven't released since late 2007 so not sure how active the community is now.

bm212