Particle Generation

I know there has been a long time since I did any updates, and I am behind my made up schedule for this project. The good news is though that I have managed to create C++ code for generating particles. Given a mesh, which I read from an OBJ-file, I take all the vertices making up the triangles and use these to generate particles on the CPU. I found inspiration for my own solution by the short amount of text described on GPU-Gems 3 chapter 29. GPU-Gems mainly focused on a solution that generated particles with the GPU and Cuda (which only NVIDIA graphics cards can use). Since I am not used to graphics programming, don't have a NVIDIA graphics card on my laptop, and want the code to work on any computer, I decided to generate the particles using normal C++ code. I sort of got stuck on how to generate particles, since I had some bugs in my code. But after discovering and fixing these bugs I got much better result.

I know that I haven't explained HOW yet, but here is a short explanation: I create a discretized 3D space with voxels, where each voxel is of uniform size. I check each triangle for intersections with lines, and if there is an intersection at all, I store only the z-value in a 2D array, 1 dimension for x-values and 1 dimension for y values. Each line is for every x and y value in the 2D array and the line go through the entire discretized space while checking for intersections. Lastly I loop through all non-empty z-values in the 2D array (where each index store an additional array for z-values). I sort these z-values in increasing order. Then for each voxel in the discretized space, if the number of z-values representing intersections before the voxels z-value is odd numbered, then there must be a particle there. This worked surpisingly well. Altough, I have skipped describing a lot of details in this post that exists in my code. The code is available publicly on GitHub. Please also see the videos/images that comes along with this post.



Kommentarer

Populära inlägg i den här bloggen

Collisions

Optimizing Particles With VBO