# BodyParticles Class

BodyParticles is a base class for BodyCloth and BodyRope classes. It uses a mass-spring simulation model, i.e. particles that are connected by inner joints. The particles are of sphere shape and characterized by a position, mass and velocity. The total mass of the whole cloth is distributed among them. Particles can be acted upon by a force or an impulse. The inner joints can be stretched (linear and angular separately), or linear joints can also be scaled, which provides the same stretching effect. When stretched to the specified distance, joins are torn (the distance is set separately for linear and angular joints).

## intgetNumParticles ()

Returns the total number of particles that constitute the body.

### Return value

The number of particles.

## floatgetAngularRestitution ()

Returns the current restitution of the body's inner joints, when triangles formed by particles are folded angularly relative to each other.

### Return value

Joints angular restitution.

## floatgetLinearRestitution ()

Returns the current restitution of the body's inner joints by linear stretching.

### Return value

Joints linear restitution.

## floatgetRigidity ()

Returns the current rigidity of the body's inner joints movement, i.e. how much interpolated linear and angular velocities of all joints corrects velocities of each separate joint.

### Return value

Rigidity of joints movement:
• By the value of 0, joints move independently.
• By the value of 1, joints move uniformly, as interpolated velocity greatly changes velocities of each joint.

## floatgetLinearDamping ()

Returns a value indicating how much the linear velocity of the particles decreases over time.

### Return value

Linear damping value.

## voidaddParticleImpulse (int num, const Math::vec3 & impulse)

Applies an impulse to the given particle. Impulses immediately affect particles velocities.

### Arguments

• int num - Particle number.
• const Math::vec3 & impulse - Amount of impulse to apply.

## voidsetLinearRestitution (float restitution)

Sets the restitution of the body's inner joints by linear stretching.

### Arguments

• float restitution - Joints linear restitution. Provided value is saturated in range [0;1.0].

## voidsetDistance (float distance)

Sets the distance of body simulation.

### Arguments

• float distance - Distance of simulation. If a negative value is provided, 0 will be used instead.

## floatgetFriction ()

Returns the current friction of the body by its contact with other surfaces.

Body friction.

## voidsetLinearStretch (float stretch)

Sets the scale for the length of linear joints (relative the source mesh topology).

### Arguments

• float stretch - Stretch scale for linear joints. If a negative value is provided, 0 will be used instead.

Sets a collision bit mask for the body. Two objects collide, if they both have matching masks.

### Arguments

• int mask - Integer, each bit of which is a mask.

## floatgetLinearStretch ()

Returns the current scale for the length of linear joints (relative the source mesh topology).

### Return value

Stretch scale for linear joints.

## Math::Vec3getParticlePosition (int num)

Returns the current position of the specified particle.

### Arguments

• int num - Particle number.

### Return value

Particle position in world coordinates.

## floatgetParticleMass (int num)

Returns the current mass of the specified particle.

### Arguments

• int num - Particle number.

Particle mass.

## voidsetParticleVelocity (int num, const Math::vec3 & velocity)

Sets the velocity of the specified particle.

### Arguments

• int num - Particle number.
• const Math::vec3 & velocity - Particle velocity.

## voidsetLinearDamping (float damping)

Sets a value indicating how much the linear velocity of the particles decreases over time.

### Arguments

• float damping - Linear damping value. If a negative value is provided, 0 will be used instead.

Returns a collision bit mask for the body. Two objects collide, if they both have matching masks.

### Return value

Integer, each bit of which is a mask.

## voidsetAngularThreshold (float threshold)

Sets the threshold for angular folding of particles triangles connected by inner joints. When passing this threshold, the joints tear up.

### Arguments

• float threshold - Joints angular folding threshold. If a negative value is provided, 0 will be used instead.

## voidsetParticleMass (int num, float mass)

Sets the mass for the specified particle.

### Arguments

• int num - Particle number.
• float mass - Particle mass.

## floatgetDistance ()

Returns the current distance of body simulation.

### Return value

Distance of simulation.

## floatgetLinearThreshold ()

Returns the current linear stretching of the body's inner joints. When passing this threshold, the joints tear up.

### Return value

Joints linear stretching threshold.

Sets the radius of the particles forming the body and represented as sphere shapes.

## voidsetLinearThreshold (float threshold)

Sets the threshold for linear stretching of the body's inner joints. When passing this threshold, the joints tear up.

### Arguments

• float threshold - Linear stretching threshold. If a negative value is provided, 0 will be used instead.

## floatgetRestitution ()

Returns the current restitution of the body by bouncing.

### Return value

Body restitution.

## floatgetAngularThreshold ()

Returns the current threshold for angular folding of particles triangles connected by inner joints. When passing this threshold, the joints tear up.

### Return value

Joints angular folding threshold.

## voidsetFriction (float friction)

Sets the friction of the body by its contact with other surfaces.

### Arguments

• float friction - Body friction. If a negative value is provided, 0 will be used instead.

## Math::vec3getParticleVelocity (int num)

Returns the current velocity of the specified particle.

### Arguments

• int num - Particle number.

### Return value

Particle velocity.

## intgetCollision ()

Returns a value indicating if collision with a body is enabled or not.

### Return value

Positive value if collision is enabled, 0 if disabled.

## voidsetNumIterations (int iterations)

Sets the number of iterations used to solve inner joints between the particles. Note that if this value is too low, the precision of calculations will suffer.

### Arguments

• int iterations - Number of iterations. If a non-positive value is provided, 1 will be used instead.

## voidaddParticleForce (int num, const Math::vec3 & force)

Applies a force to the given particle. Integrated forces are applied after calling the update.

### Arguments

• int num - Particle number.
• const Math::vec3 & force - Amount of force to apply.

## floatgetMass ()

Returns the current mass of the body.

### Return value

Mass of the body.

## voidsetParticlePosition (int num, const Math::Vec3 & position)

Sets the position of the specified body's particle.

### Arguments

• int num - Particle number.
• const Math::Vec3 & position - Particle position in world coordinates.

Returns the current radius of the particles forming the body and represented as sphere shapes.

## voidsetAngularRestitution (float restitution)

Sets the restitution of the body's inner joints, when triangles formed by particles are folded angularly relative to each other.

### Arguments

• float restitution - Joints angular restitution. Provided value is saturated in range [0;1.0].

## voidsetRigidity (float rigidity)

Sets rigidity of the body's inner joints movement, i.e. how much interpolated linear and angular velocities of all joints corrects velocities of each separate joint.

### Arguments

• float rigidity - Rigidity of joints interaction. Provided value is saturated in range [0;1.0]:
• By the value of 0, joints move independently.
• By the value of 1, joints move uniformly, as interpolated velocity greatly changes velocities of each joint.

## voidsetCollision (int collision)

Sets a value indicating if collision with a body is enabled or not.

### Arguments

• int collision - Positive value to enable collision, 0 to disable it.

## voidsetMass (float mass)

Sets a mass of the body.

### Arguments

• float mass - Mass of the body. If a negative value is provided, 0 will be used instead.

## intgetNumIterations ()

Returns the current number of iterations used to solve inner joints between particles.

### Return value

Number of iterations.

## voidsetRestitution (float restitution)

Sets the restitution of the body by bouncing.

### Arguments

• float restitution - Body restitution. Provided value is saturated in range [0;1.0].
Last update: 2017-07-03