Skip to main content
gamedev.net
🔒 Locked

[java] Java particle engine

Started by j14rk1n 7 replies 5.7k views
Original Post
j14rk1n
j14rk1n
I've been programming in java for around 6 months, and just got into graphics. (Finally!) I finished a particle engine, in which there's simulated gravity that affects the particles in different ways. I've been able to get basic physics working(bouncing/reflection), but that's where I'm stuck. I'd like to start on a physics engine/particle editor now, but I'm lost when it comes to the math behind it all. I have a few questions before I start though: Do physics engines run on timers or a timing system? If so, I guess that's what I'd use to calculate motion and properties. Are there any good physics sites with computer-oriented formulas? Like... stuff I'd find in a physics 101 textbook. Do you like my particle engine? You can use the directional keys to set the gravity, and space resets it all. http://johnlarkin.f2g.net/CrazyParticles/main.html Thanks in advance for answers :)
phaelax
phaelax
I got this error from it: (could just be my browser)

java.lang.UnsupportedClassVersionError: ParticleTester (Unsupported major.minor version 49.0)

Volume 10 issue 6 of the magazine JDJ (http://jdj.sys-con.com/) had an article on building a particle system for java3d.

I wrote a tutorial on building a particle engine which used a time value to determine position. I wrote it for DarkBasic users though. Here's the basic equation I used:

x = v*cos(a)*t
y = v*sin(a)*t - ½gt²

If you wanted to do this in 3D, "x" would basically be the distance from the emitter, so you'd have:

d = v*cos(a)*t
x = cos(da)*d
y = v*sin(a)*t - ½gt²
z = sin(da)*d

Not a very fancy particle engine, but gives a nice fountain effect. Angles "a" and "da" control the angle of elevation and Y-rotation around the emitter, respectively.
Son of Cain
Son of Cain
Quote:
Original post by j14rk1n
Do physics engines run on timers or a timing system? If so, I guess that's what I'd use to calculate motion and properties.


Yes, they rely heavily on that. On most cases, you "preview" what's going to happen in a space, spliting your time variable in fixed intervals, checking each one of them to identify if a certain phenomenon (?) happens. Geez, my english is terrible...

Quote:
Original post by j14rk1n
Are there any good physics sites with computer-oriented formulas? Like... stuff I'd find in a physics 101 textbook.


Not sure about sites, but there's one engine called jME that has physics support. You might want to take a look at it.

Quote:
Original post by j14rk1n
Do you like my particle engine? You can use the directional keys to set the gravity, and space resets it all.
http://johnlarkin.f2g.net/CrazyParticles/main.html

Thanks in advance for answers :)


Hey, nice work! Congrats! ;)

Son Of Cain
a.k.a javabeats at yahoo.ca
j14rk1n
j14rk1n
Thanks for the info and compliments.

As for the 'java.lang.UnsupportedClassVersion' error:
I compiled it all with Java 5 (1.5), which if pretty new still, so you may need that to run it. Also, if you're on a mac, that could be an issue. I don't own one, so I've been asking my friends to test it on theirs with overall success.
Thanks again :)

[Edited by - j14rk1n on September 15, 2005 6:51:21 PM]
honey
honey
i like your particle system, but i couldn't get the gravity thing working. using the keys didn't result in any change of the particle system only moving the mouse over the applet changed the source of the particles. apart from that, nice work :)
j14rk1n
j14rk1n
You have to click anywhere inside the applet first, and then use the keys to mess around with the gravity.
indie technologies
indie technologies
When it comes to computing velocity and position in a particle system, be sure to research Euler's approach. Essentially your particle system manipulates particles in terms of the acceleration. Your particle system updates the particles every frame or every X milliseconds. The external forces like gravity should be applied to the particles in the form of accelerations. You then compute the new velocity of the particles using this short time differential (dt) like this:

vx = vx + ax*dt; // vx = velocity in x direction, ax = acceleration in x dir
vy = vy + ay*dt;

after figuring out the new velocity, you can calculate the new position:

x = x + vx*dt;
y = y + vy*dt;

Rotation is a another set of equations, but these are the basic linear equations.

Mike
indie technologies - particle effects for java games
Mike
j14rk1n
j14rk1n
Yeah, I know. It's such a hack, but it looks cool.

I should be updating position based on DeltaT, but whatever.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.