Java IoT Authors: Elizabeth White, Liz McMillan, Pat Romanski, Yeshim Deniz, Mehdi Daoudi

Related Topics: Java IoT

Java IoT: Article

Star Trek Technology for Java3D

Building a particle system for Java3D

We Need More Power, Scotty!
Let's extend our particle system design to incorporate Shape3D particles. We still want to easily add the particle system to the Java3D scene, and reuse as much of what we've done up to this point. Recall that our particle systems use an emitter to control the initial position and velocity of the particles. The point and motion blurred particle systems deal with pixel size particles so we'll have to create a new type of particle system to handle Java3D shapes. So far, the particle systems have been Shape3D objects, so how can particles be any Shape3D object? Java3D supports the aggregation of shapes into a Group.

As you can see from Figure 6, the Shape3DParticle-System is a subclass of the Java3D Group class to allow shapes to be grouped together into a particle system. By implementing the IParticleSystem interface, the Shape3DParticleSystem can use the particle emitter unchanged. To help organize and control the shapes, the shape particle system maintains a scene graph segment for each shape in the particle system. Each shape has a scene graph segment consisting of a branch group to maintain membership in the particle system and a transform group to control the location, scale, and rotation of the shape.

Because particles are born and die during the particle system life cycle, shapes must be added and removed from the scene during the animation. Java3D limits the changes to the content of live scene graphs to branch groups. Provided the group (the particle system) has the ALLOW_CHILDREN_EXTEND and the ALLOW_CHILDREN_WRITE capabilities set and the branch group has the ALLOW_DETACH capability set, the branch group and its children can be added or removed from the scene. For our purposes, the only child of the branch group is a transform group. The transform group maintains the standard Java3D translation, scale, and rotation attributes of its child shape in a Transform3D object. With this structure in place, let's briefly review the Reeves life cycle for our new shape particle system.

Emit New Particles
From Figure 6 you can see that the shape particle system implements the IParticleLifeCycleListener interface. The particle emitter notifies listeners as particles evolve through their lifetime. This notification can be used to create additional effects such as spawning additional particle systems. Just before particles are emitted, the aboutToEmit() method is called on the listener, passing a list of particles to be emitted. The shape particle system reflects the initial particle position in the transform group and adds the branch group, transform group, and shape to the scene.

Bury the Dead Particles
When the particle emitter is ready to bury dead particles, it notifies listeners of their impending demise by calling the aboutToDie() method. The shape particle system takes the news pretty well by removing the branch group for the particles from the particle system, removing the shapes from the scene. To reduce object creation, the shape, transform group, and branch group are recycled for a future reincarnation.

Update the Surviving Particles
While particles are alive, the particle emitter applies the influences and the particles are moved, scaled, and rotated. After the particles have been updated by the particle emitter, it notifies the listeners by calling the updated() method. The shape particle system reflects the new particle position, scale, and rotation in the transform group. We discussed how linear acceleration and velocity of a particle can affect its new position, but how about rotation?

Slicker Than Euler
Realistic rotation of Shape3D particles with Euler angles can be mathematically intensive and computationally expensive. I'll try to keep the math to a minimum but if you are interested in the details, have a look at the references. If you have read much about three-dimensional graphics, you've probably already heard of Euler angles. An example of Euler angles is the yaw, pitch, and roll used to describe the orientation of an airplane. There are a few problems with using Euler angles that make them difficult to use for animation.

The order in which Euler angle rotations are applied can result in different orientations. While applying the rotations, a degree of freedom can be lost to something called a "gimbal lock". Over the course of multiple rotations, numeric corrections are often needed to keep the rotational animation looking good. Too make matters worse, it's computationally expensive to interpolate between orientations. Chris Hecker summed it up pretty well: "It's possible to prove that no three-scalar parameterization of 3D orientation exists that doesn't suck, for some suitably mathematically rigorous definition of suck." I did say that I would try to keep the math to a minimum. While Euler angles are easy to understand, we need something that overcomes the weaknesses of using Euler angles for rotational animation. This is where something called a quaternion can save the day (see the sidebar: Pop Quiz Hot Shot).

A quaternion is an extension to complex numbers consisting of a vector and a scalar. There's no use trying to picture a quaternion because it exists in four-dimensional space. In the spirit of keeping the math to a minimum, let's review the key features of quaternions. A unit length quaternion is perfect for representing a rotational orientation of an object. Java3D supports a unit quaternion with the Quat4f class. As the name implies, it consists of four floating-point numbers to make up the vector and scalar components of the quaternion. It's straightforward to convert Euler angles to a quaternion as shown in Figure 7.

Performing successive rotations with quaternions is as easy as multiplying them together. When compared to the traditional rotational matrix approach, quaternion multiplication (the details of which we won't cover here) and orientation interpolation is much more efficient, making it ideal for animating our rotating particle shapes. To animate the rotation, we need to specify the angular velocity in the vector portion of a quaternion. The angular velocity quaternion used to calculate the time differential of a quaternion is shown in Figure 7. The time differential can be used to interpolate quaternions, which helps us spin objects. That was probably the world's shortest description of quaternions, so be sure to review the references if you need more detail. Let's put this new knowledge to work in our shape particle system.

When shape particles are about to be emitted, the orientation is assigned through the use of Euler angles. The angular velocity is also assigned using the now familiar central value and variance approach discussed above. The orientation and angular velocity is converted into quaternions by the particle. When the particle is updated, the quaternion differential is calculated using the time interval of the particle system manager as described in Figure 7. Finally, the new orientation quaternion is set on the Transform3D of the shape along with the new position and scale and Java3D rotates the shape.

Vector3f translation = new Vector3f();
translation, aParticle.getScale());

More Stories By Mike Jacobs

Mike Jacobs is technology architect and Technology Fellow focused on using technology to improve health care.

Comments (10)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

IoT & Smart Cities Stories
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Druva is the global leader in Cloud Data Protection and Management, delivering the industry's first data management-as-a-service solution that aggregates data from endpoints, servers and cloud applications and leverages the public cloud to offer a single pane of glass to enable data protection, governance and intelligence-dramatically increasing the availability and visibility of business critical information, while reducing the risk, cost and complexity of managing and protecting it. Druva's...
BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.
The Jevons Paradox suggests that when technological advances increase efficiency of a resource, it results in an overall increase in consumption. Writing on the increased use of coal as a result of technological improvements, 19th-century economist William Stanley Jevons found that these improvements led to the development of new ways to utilize coal. In his session at 19th Cloud Expo, Mark Thiele, Chief Strategy Officer for Apcera, compared the Jevons Paradox to modern-day enterprise IT, examin...
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO and DXWorldEXPO are two of the most important technology events of the year. Since its launch over eight years ago, @CloudEXPO and DXWorldEXPO have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, we provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading...
DSR is a supplier of project management, consultancy services and IT solutions that increase effectiveness of a company's operations in the production sector. The company combines in-depth knowledge of international companies with expert knowledge utilising IT tools that support manufacturing and distribution processes. DSR ensures optimization and integration of internal processes which is necessary for companies to grow rapidly. The rapid growth is possible thanks, to specialized services an...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
Scala Hosting is trusted by 50 000 customers from 120 countries and hosting 700 000+ websites. The company has local presence in the United States and Europe and runs an internal R&D department which focuses on changing the status quo in the web hosting industry. Imagine every website owner running their online business on a fully managed cloud VPS platform at an affordable price that's very close to the price of shared hosting. The efforts of the R&D department in the last 3 years made that pos...