Aligning particles to the mesh surface
In this recipe, we are going to use a 3D version of the particles' code base from the Creating a particle system in 2D recipe. To navigate in 3D space, we will use MayaCamUI
covered in the Using MayaCamUI recipe in Chapter 2, Preparing for Development.
Getting ready
To simulate repulsion, we are using the code from the Applying repulsion and attraction forces recipe with slight modifications for three-dimensional space. For this example, we are using the ducky.mesh
mesh file that you can find in the resources
directory of the Picking3D sample inside the Cinder package. Please copy this file to the assets
folder in your project.
How to do it…
We will create particles aligned to the mesh. Perform the following steps to do so:
Add an
anchor
property to theParticle
class in theParticle.h
file.ci::Vec3f anchor;
Set the
anchor
value at the end of theParticle
class constructor in theParticle.cpp
source file.anchor = position;
Add the necessary headers in your...