YOUR FEEDBACK
Gregor Rosenauer wrote: well, not what's your take on this? Did I miss a second page of this article or...


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


Star Trek Technology for Java3D
Building a particle system for Java3D

Emit New Particles
The particle system manager notifies the particle system that enough time has elapsed. This time is typically less than 50 milliseconds. The emitter determines how many particles need to be initialized and emitted based on the emission rate, emission rate variance, and the amount of time since the last notification. The speed of the particles is initialized based on the velocity and velocity variance while the generation shape determines the initial location. The generation shapes in the source code include point, line, disk, and radial shapes. Particles are assigned a lifetime using the same central value plus the variance approach used for other attributes.

Bury the Dead Particles
During the previous cycle, particles were aged based on the elapsed time. Now the particles that have exceeded their lifetime are collected and recycled for future emissions.

Update the Surviving Particles
The remaining particles are aged, changed by any external influences, moved, scaled, and rotated. Aging simply increments the age of the particle based on the elapsed time. External influences can affect visual characteristics such as color or transparency, or physical attributes such as scale, acceleration, velocity, or position. Updating physical attributes does involve a bit of physics, but hopefully it hasn't been too long since your last physics class.

As part of applying the influences, the accelerations are accumulated from each influence. For example, there may be a Gravity and Wind influence affecting the particles. Gravity would obviously apply a downward acceleration while wind would apply a horizontal acceleration. These accelerations and the existing velocity and position are used to move the particle. The particle is moved in the following method:


public void move(float dt) {
float[] position = getLocalPosition();
Vector3f v = getLocalVelocity();
Vector3f a = getLocalAcceleration();
v.scaleAdd(dt, a, v);
// Scale add not used with position
// to reduce number of objects created.
float x = position[0] + vx * dt;
float y = position[1] + vy * dt;
float z = position[2] + vz * dt;
setLocalPosition(x, y, z);
}

This implementation uses Euler's approach to numeric integration. This approach works for us provided the time differential (dt) between frames is small. The ParticleSystemManager controls the elapsed time so we can ensure the time differential is small. Other approaches to numeric integration such as Modified Euler, Heun, or Runge-Kutta could be used if we needed more accuracy for our particle simulation.

Because we are currently dealing with point particles, we'll skip scaling and rotation for now since these make little sense for points.

Render the Particles
This step is trivial in Java3D because the previous step changed the location of the points representing the particles. The previous step updated the geometry of the particle system shape using the GeometryUpdater interface and Java3D renders the new positions for us. As the particle system life cycle evolves, the position of the particles changes, creating the animation. Because we are dealing with points, some simulations can be disorienting unless we introduce motion blur.

It's All a Blur
You've probably seen motion blur when the Enterprise goes to light speed. Motion blur on film can occur when the subject moves quickly while the camera shutter is open. While you probably don't want the blur when taking photographs, motion blur makes animation look more lifelike and increases the perceived frame rate. How can we take our particle system to the next level and add motion blur?

Remember that each cycle of the particle system life cycle is repeated after a very short elapsed time. If we treat the elapsed time as an open camera shutter, then we want to blur the particle movement during this elapsed time. During the elapsed time, the particle moves from one location to the next. If a line segment is used instead of a point, we can connect the previous location with the new location and vary the transparency of the line to create the blur as depicted in Figure 4.

The MotionBlurredParticleSystem implements motion blurred points using the Java3D LineArray geometry array class. The ParticleEmitter supports both the previous and current location of the particle, enabling the particle system to use this information to create the line segments. The blurring is accomplished by assigning colors to the end points of the lines with different alpha values. The current location has a fully opaque alpha value while the previous location has a fully transparent alpha value. Java3D takes care of smoothly interpolating the transparency of the line, conveniently creating the motion blur for us.

Light Speed, Mr. Sulu!
Using points and motion-blurred lines for particles in Java3D performs very well. Several thousand particles can be used simultaneously on modest hardware with reasonable performance. I pushed my antiquated one-gigahertz machine to run three motion-blurred particle systems consisting of 8635 particles, gravity, and particle bouncing at 14 frames per second. The 14 frames per second is not stellar; it looks terrific with the blurring. Clearly the advantage of using points or lines is that they are fast and allow the use of thousands of particles. The disadvantage to using points or lines is the lack of scale. Each particle is one pixel in size regardless of the distance from the viewer. While you can change the pixel size of the particles via the PointAttributes and LineAttributes, the particles are still all the same size. Ideally our particles should have scale and, for performance sake, reduce the need for a large number of particles. An approach to solving these issues is to make the particles full-blown Java3D shapes. With this approach we can create fantastic effects like the tornado shown in Figure 5.

About Mike Jacobs
Mike Jacobs is a mild-mannered technical architect by day and recreational programmer by night. Mike works at the Mayo Clinic. Please provide feedback and guidance for future JDJ articles to mnjacobs.javadevelopersjournal.com.

YOUR FEEDBACK
indie technologies wrote: http://www.indietechnologies.com now has this Java 3D technology available as a commercial product.
indie technologies wrote: This technology is being commercialized for Java 3D game developers. Visit www.indietechnologies.com for more information.
Java Developer's Journal wrote: Star Trek Technology for Java3D. The Star Trek universe has inspired many technology ideas but I'm disappointed I don't have a transporter yet. One Star Trek technology that has been available for sometime is the particle system. No, this is not an exotic propulsion system for your flying car. The particle system was invented to animate the Genesis effect in Star Trek II: The Wrath of Khan. While the Genesis device was used to transform a barren planet into one full of life, we can adopt this technology for more modest effects in Java3D.
Mike Jacobs wrote: If you are looking for the source it is at the following link (my previous comment had a period at the end of the link). http://res.sys-con.com/story/jun05/99792/source.html
David Morris wrote: Mike, the stated link to the source code is invalid. Could you please update this link. Thanks, David
Mike Jacobs wrote: The web editor decided to do things a bit different than the past. The first mention of the listings (Listing 1) is a link to all of the code. The link is http://res.sys-con.com/story/jun05/99792/source.html. Mike
Michael Yankowski wrote: I can't find any links to the source code. Thanks, Mike
Mike Jacobs wrote: The source code is now current.
Mike Jacobs wrote: It looks like the source for this article is slightly down level. JDJ is working on it. Mike
LATEST JAVA STORIES & POSTS
JavaScript 2 is becoming increasingly important. Learn how to take advantage of JavaScript 2 while still running in today's browsers. Leverage your current JavaScript and HTML skills to build applications that run in Flash 7-9, DHTML and more with no code changes! OpenLaszlo 4.2 ...
GigaSpaces Technologies and GoGrid have announced the availability of the GigaSpaces eXtreme Application Platform (XAP) on GoGrid's enterprise-grade cloud computing service for Windows and Linux. The two companies’ joint offering enables enterprises to migrate existing and new ...
JavaScript is a language with more than its share of bad parts. It went from non-existence to global adoption in an alarmingly short period of time. It never had an interval in the lab when it could be tried out and polished. JavaScript has some extraordinarily good parts. In Jav...
Since its emergence, Web Service technology has gone a long way towards perfecting itself and finding its right application in the real world. With the maturity of the specifications, Web Service technology, with its power of interoperability, is now the major enabling technology...
Terracotta has announced the latest version of their open source Java clustering solution, Terracotta version 2.7. The new version builds on the adoption of Terracotta in specific vertical markets and applications such as reservation systems, online gaming, and information portal...
Microsoft said, “Going forward we’ll use jQuery as one of the libraries used to implement higher-level controls in the ASP.NET AJAX Control Toolkit, as well as to implement new AJAX server-side helper methods for ASP.NET MVC. New features we add to ASP.NET AJAX (like the new ...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

SPONSORED BY INFRAGISTICS
In every field of design one of the first things students do is learn from the work of others. They ...
There are many forces that influence technological evolution. After a decade of building enterprise ...
2008 is going to be an important year for Rich Internet Applications. Most organizations are deliver...
The OpenAjax Alliance is developing an Ajax industry wishlist for future browsers, using a dedicated...
Infragistics announced the availability of two Community Technology Preview (CTP) User Interface (UI...
The YUI development team has released version 2.5.2; you can download the new release from SourceFor...
ADS BY GOOGLE