Torque 3D Dynamic Particle Mod
Sunday, December 30, 2012 at 4:54PM
Tim in C, C++, Dynamic, Dynamic Particles, Mod, Particle, Torque 3D, Torque 3D Dynamic Particle Mod, Torque3D, engine, game, inheritance

Torque3D Particle Mod from Tim Lake on Vimeo.

Most modern engines have dynamic particles but Torque is an older engine. The particles in Torque are considered an effect so they completely ignore everything in the scene and instead run based on a script. I wanted to learn a game engine and changing the behavior of the particles was a great way to learn.

I knew that I needed a general understanding of how the engine worked so I went to work with tracing the execution path of the engine. Using Visual Studio, I set a breakpoint in the main function and got a picture of the first important function calls. I followed those functions and learned about what was assigned and how. I used Visual Studio and Windows Grep to help navigate the code and find connections between classes like function calls and inherited classes.

During this learning process I discovered the basic classes and found documentation in those core classes. The documentation showed me what functions to call to setup the particles the way that they needed to be. I placed breakpoints in functions to make sure the functions were being called in the right order.

Later I used Doxygen and Graphviz to help fill in the gaps where the developers did not comment their code or it was not clear what they had done in their code. I wish I had used Doxygen and Graphviz earlier. It would have been a big help and it was still very helpful later in the project. It helped me see the layers better like where the developers had code that helped them to develop across platform or what was similar or different between the different classes. It helped to visualize what was going on especially since some files contained multiple classes that in some cases were named very similarly so initially I did not realize that they were different. A visualization would have helped catch this sooner. Basically, every main class representing some physical entity in the game had a data class associated with them and the data class was used within the related main class. The realization of these two classes per file pattern helped clear up a lot about the structure of these classes representing in game entities. In the future I will be sure to pay better attention to the whole and not get as lost in the details.

 The key to dynamic particles was to change the inheritance of the particle class so that the right functions would be called automatically and could be called within the particle class. I realized this when I analyzed the classes that interacted with the physical zones that applied a force to them. I copied the same core pattern with changes that applied exclusively to particles. A big difference is the fact that the particles run locally on the client and do not communicate across the network because maintaining that consistency is not vital to gameplay. Network communication can be added in later because the underlying structure is in the parent classes. I wanted to keep the particle class as lightweight as possible because there would be so many generated during the game so I did not want to inherit from an already existing class that did everything I wanted and more unnecessary things.

Once I got the inheritance worked out, I realized that it still was not working. I used breakpoints to quickly locate the point where the code was skipping checks against the physical zones. I had to enable the checks and then setup the correct bit mask within the particle class. Still the force from the physical zone was not being applied. I realized that the parent class had a position variable inside of it which is what the physical zone was checking against so I assigned the position from the particle class to the parent class and it worked.

I chose to use forces instead of gravity because gravity is multiplied in the gravity equations so if the developers wanted zero gravity then it would zero out any other forces of gravity within that physical zone. The forces are summed so they would not be zeroed out by a zero gravity environment. The particle class covers all essentials and nothing more. It interacts accurately with the physical zones. The particles still generate from a particle emitter and still have scripting if desired.

Please contact me if you have any questions about my work at

Article originally appeared on Tim Lake (
See website for complete article licensing information.