AaronB









Level 2 Aaron's Particle Space - a physics sandbox based on particles « on: January 02, 2017, 11:07:45 PM »



The blurb:



“Aaron's Particle Space is a sandbox world that revolves around each individual particle. If you enjoy building objects with real physical properties, solving puzzles, learning more about physical interactions, exploring immense and microscopic worlds, creating dynamic art or even just shooting or blowing things up, then Aaron's Particle Space is for you.”



DOWNLOAD ALPHA v0.20.01



















Quote from: AaronB on December 01, 2016, 07:58:17 PM One of the things I noticed about this software was how rapidly it would slow down once it reached a certain number of particles. A bit of thought made me realize that this was due the nature of having to check each particle against every other particle, this being a classical O(x^ 2 ) relationship (10 particles = 10x10 = 100 calculations, a 100 particles = 100x100 = 10000 calculations. Obviously not linear. So I got to thinking wouldn't it be neat to implement something like OE-cake on modern graphics hardware, where the immense parallel processing power would help reduce this computational bottle neck. Was it possible to have a stable physics simulator with all particles interacting simultaneously? Maybe the answer has been found elsewhere, but I always like to work things out for myself, so I have spent a good part of 2016 developing such an engine. Which is why I am writing this introduction. Over the next week or so I will be asking for feedback on the engine – which I hope will be of interest to the TIGSource community.

There is a physics engine demonstration called OE-cake https://www.reddit.com/r/oeCake/ that held a great amount of fascination for me - I love physics simulationsOne of the things I noticed about this software was how rapidly it would slow down once it reached a certain number of particles. A bit of thought made me realize that this was due the nature of having to check each particle against every other particle, this being a classical O(x^ 2 ) relationship (10 particles = 10x10 = 100 calculations, a 100 particles = 100x100 = 10000 calculations. Obviously not linear. So I got to thinking wouldn't it be neat to implement something like OE-cake on modern graphics hardware, where the immense parallel processing power would help reduce this computational bottle neck. Was it possible to have a stable physics simulator with all particles interacting simultaneously? Maybe the answer has been found elsewhere, but I always like to work things out for myself, so I have spent a good part of 2016 developing such an engine. Which is why I am writing this introduction. Over the next week or so I will be asking for feedback on the engine – which I hope will be of interest to the TIGSource community.

How it works (geeky stuff)



The particle / physics engine runs entirely on the GPU using compute shaders. This allows each particle to be processed simultaneously using the massive parallel processing capabilities of the GPU. The upshot of this is we can get closer to mimicking real life by treating physical objects not as a whole, but by concentrating on the behavior of each individual component (particle) that make up the object. In other words, the rubbery, brittle, stretchy, rigid etc, characteristics of an object can be defined entirely by how each particle interacts with it's neighbor.



So what are the particle interactions we need to focus on? Well it turns out to be relatively simple. There are two fundamental interactions, how the particles collide with each other, and how they are attracted to each other. The entire physics engine can be derived from two formulas, one that defines the forces resulting from a collision, and one that defines the forces of attraction (or repulsion).



For the collision formula there are many web resources, discussions, etc that cover particle collisions, particularly if those particles are round. I chose to use a formula that calculates an impulse collision force using not only mass and velocity, but also using friction and rotation.



For the forces of attraction I reasoned as follows:

What exactly is happening when I hold a solid object in my hand ? My fingers are pressing against the sides of the object, coming into direct contact with the surface atoms/molecules. When I rotate that object, my fingers are applying a force to those surface atoms, which in turn causes those atoms to move. This movement will naturally mean that the underlying atoms, the ones just below the surface, will also have to move. So the force from my fingers is being transmitted through all the particles, causing an overall net movement of the object.



This force is traveling as a wave through the object, with each particle momentarily pushing against it's neighbor. The wave continues until all the particles come back to a state of equilibrium that represents the shape of the object.







If we define the position of each particle in terms of distance and orientation to it's neighbors, then if a particle moves, we need only to calculate the force required to re-position the neighbors back into the correct distance and orientation. By changing the behavior of the restoring force we can define the properties of the object. A weak force will result in a rubbery or stretchy material, a strong force will give a rigid or solid material.



Rigid Body Rotation

APC takes a unique approach when it comes to rotation. Most physics engines will determine the torque based on center of mass and body topology. In APC the total mass and the center of mass remain unknown. There is in fact only one aggregate value used, the total torque of all interacting particles. The torque is averaged and applied to a global angular velocity for the body. This angular velocity is then applied to all join vectors in the next frame, resulting in stable rotation of the body.



All the weird and wonderful things you can do in APC are derived from these principles. The particle / physics engine runs entirely on the GPU using compute shaders. This allows each particle to be processed simultaneously using the massive parallel processing capabilities of the GPU. The upshot of this is we can get closer to mimicking real life by treating physical objects not as a whole, but by concentrating on the behavior of each individual component (particle) that make up the object. In other words, the rubbery, brittle, stretchy, rigid etc, characteristics of an object can be defined entirely by how each particle interacts with it's neighbor.So what are the particle interactions we need to focus on? Well it turns out to be relatively simple. There are two fundamental interactions, how the particles collide with each other, and how they are attracted to each other. The entire physics engine can be derived from two formulas, one that defines the forces resulting from a collision, and one that defines the forces of attraction (or repulsion).For the collision formula there are many web resources, discussions, etc that cover particle collisions, particularly if those particles are round. I chose to use a formula that calculates an impulse collision force using not only mass and velocity, but also using friction and rotation.For the forces of attraction I reasoned as follows:What exactly is happening when I hold a solid object in my hand ? My fingers are pressing against the sides of the object, coming into direct contact with the surface atoms/molecules. When I rotate that object, my fingers are applying a force to those surface atoms, which in turn causes those atoms to move. This movement will naturally mean that the underlying atoms, the ones just below the surface, will also have to move. So the force from my fingers is being transmitted through all the particles, causing an overall net movement of the object.This force is traveling as a wave through the object, with each particle momentarily pushing against it's neighbor. The wave continues until all the particles come back to a state of equilibrium that represents the shape of the object.If we define the position of each particle in terms of distance and orientation to it's neighbors, then if a particle moves, we need only to calculate the force required to re-position the neighbors back into the correct distance and orientation. By changing the behavior of the restoring force we can define the properties of the object. A weak force will result in a rubbery or stretchy material, a strong force will give a rigid or solid material.APC takes a unique approach when it comes to rotation. Most physics engines will determine the torque based on center of mass and body topology. In APC the total mass and the center of mass. There is in fact only one aggregate value used, the total torque of all interacting particles. The torque is averaged and applied to a global angular velocity for the body. This angular velocity is then applied to all join vectors in the next frame, resulting in stable rotation of the body.All the weird and wonderful things you can do in APC are derived from these principles. « Last Edit: June 09, 2018, 06:54:43 PM by AaronB » Logged Aaron's Particle Space