Basic Physics Engine

I’m finally at the point where I’m feel secure enough with Java3D to start creating my physics engine.

(I went to gamedev.net and almost shot myself to head due the fact that every 14-year-old is creating a mmorpg.)

For now, I start with flat grid-landscape where I drop items. My attempt is to implements Newtons 3 first laws of dynamics.

  1. Object in uniform motion keeps its velocity if no force affects it. Same with objects with velocity of 0.

  2. Acceleration is directly porpotional to the sum of new forces divided by mass.

  3. If object excerts force on another object, equal force is excerted back.

I believe these all can be done with the simple collision detection thingies provided by Java3D.

One thing I need to know is though, how do I handle objects moving on rough ground? Should I put all the objects “glide” on top of the surface and just give the illusion that they are gliding/moving on it?

How do I implement multiple forces on one object? Lets say I take my cube up to 20 pixels high and drop it from there, but also give it initial velocity with a bearing of 45 degrees. While the gravity would be certainly moving it downwards, how does I set movement with the vi in 45 degrees. I believe I need to calculate the relative velocity. Isn’t that correct?

I have thought about the code in following way:

interface PhysicalConstants
-mass
-distance
-time(I’m not sure about this)
-velocity
-acceleration
-force

Now this interface would be the core of any object, whether it is geometry or model.

Could someone who has little knowledge in physics to revieve the list as I wrote it at my (soon to be girl)friends party when others were doing drugs and performing pre-marriatal sex. If I’m missing some basic element please tell me.

[quote]… as I wrote it at my (soon to be girl)friends party when others were doing drugs and performing pre-marriatal sex. If I’m missing some basic element please tell me.
[/quote]
I’ll let you form your own opinions on drugs but you’re definatly missing out on the pre-marriatal sex.

If you’re every at a party again and you’re thinking about Java please stop and try this pick up line on the first girl you see:

[quote]Hey baby, wanna import my package? It’s dynamically extensible.
[/quote]
If you’re bored go to this page at Monzy Central and read the Wednesday, February 17, 1999 entry. (Doing a find in page for “Java Versus Sex” will get you there too.)

Newtons laws describe the physics of a point mass. Luckily, points can never collide and cannot spin. That nice for computation. Ah, and they live in continous time!

Real-world objects have a finite volume and an orientation and therefor have inertia. For a sphere with equally distributed mass, this can be a number. Generally it is a tensor. Welcome to the world of tensor algebra.

So add at least two properties to your interface:

  • inertia (Matrix3f)
  • spin (Vector3f)

The critical point is to calculate the forces!! There are constant ones like

G=new Vector3f(0f,-9.81f,0f)  

and easy-to calculate ones like air-resistance

draw=new Vector3f(0f,0f, v*v)

(all in their resp. coordinate systems, of course).

And there are the complex ones resulting from object interaction. As long as your objects are elastic spheres, that not a very big problem (if you can determing EXACTLY where the spheres collide) e.g. in a billiard game.

But if you have interconnected object (a swinging bridge, a skeleton) - don’t do it at home. There are specialists necessary to deal with. People who know how to do the integration.

If you need to be real physical, you have to observe conservation of energy - which turns out to be very hard when doing numerics…

Basically, there are 3 laws, … but…

Ok, now lets talk about dissipative forces like friction, elasticity,…

Only if you want aids.

[quote] Only if you want aids.
[/quote]
Aids have nothing to do with social status. Where do you get that from?

Negative, you use protection

Protection is a joke. Condoms don’t work half the time.

Where did you get social status from? Read the what I quoted. :stuck_out_tongue:

People, walk away from this thread. Nothing more of benefit to anyone will come from it.

http://www.java-gaming.org/cgi-bin/JGOForums/YaBB.cgi?board=suggestions;action=display;num=1035576631

interesting so this 14 yearold guys do run a server farm 2? creating a stable mmorpg is hard.

First earn some money, buy some big servers ( 4 or 5 Sun Enterprise will do ) get a T1 line and write server and write client.

If u can earn money after spending $200.000 dollars or more u are lucky otherwise …

i have seen so many so called mmorpg,forget it, crap, written by so called professionals.

maybe in 10 or 15 years that 14 year old boy has the skills and the experience to create a small mmorpg, but now all these projects will fail !

maximum players online seen in those mmorpg are not more than 100.

we have 4000 chatters simultaneus online in our system right now and we earn money. we earn a lot of money and we have 10 years experience in online business

Thanks for hijacking my thread. You could have opened up somewhere else… ^^

an open source physics engine, is it possible port to Java?

http://ode@q12.org/ode/ode.html

first you have to find the result of all forces on your object (if they apply on the same point), just sum up all your forces vectors and use this to find the acceleration. (F=ma, you divide your force vector by mass and you find acceleration, but it’s a vector).

Now you need to integrate this over time. For this step, you need an accurate timer and the difference of time between your current frame and the last one (delta_time). Multiply your acceleration vector by this delta_time and add this new vector to your object velocity. Now take this freshly updated velocity vector and multiply it by delta_time. Add this vector to your object position and you get the updated object position. This is the Euler integrator which is not THAT accurate but still good for simple stuff.

I wrote an article in french about (basic) particles physics :

http://www.programmationworld.com/site/Cours.asp?Action=cours&Numero=278

There’s some code in the middle of the article that performs this integration, you should be able to understand it, it’s C. For advanced motion, you’ll have to read some docs about torque and momentum. (Chris Hecker series are a good start : http://www.d6.com/users/checker/dynamics.htm)

[quote]an open source physics engine, is it possible port to Java?

http://ode@q12.org/ode/ode.html
[/quote]
have a look at http://odeforjava.sourceforge.net/

Hey, was really excited when you posted it…

But it’s only a ODE-JNI-wrapper for Java? Not so good.

Yeah, it’s only a wrapper for ODE rather than a port, but it’s the only option at the moment. I’d be happy to help if there’s sufficient interest in porting the entire thing to java.

I’ve been looking at the ODE source code and have decided to make a Java port of the code.

I’d be interested to know if 1) anyone would be interesting in helping out with the port and 2) interested in using the code once finished.

Here’s my email address:
stevecparker@comcast.net

I’d love to use it - best if it’s nicely integrated with Java3D, so that I don’t have to transfer bounds/geometry from here to there…

Actually they just finished unintegrating it from Java3D so that it is framework independant. :slight_smile:

Since the future of 3D in Java is unsure, probably the best way to go…