org.jocl.cloth
Class ClothSimulationMethods

java.lang.Object
  extended by org.jocl.cloth.ClothSimulationMethods

 class ClothSimulationMethods
extends java.lang.Object

Basic methods that are common to most types of cloth simulations.


Method Summary
(package private) static void collisionDetection(int numParticles, float[] candidatePositions, float sphereRadius)
          Perform a simple ... well, a trivial collision detection: Particles that are inside a virtual sphere with the specified radius will be moved out of the sphere on the shortest way.
(package private) static void collisionDetection(int numParticles, int minIndex, int maxIndex, float[] candidatePositions, float sphereRadius)
          Perform a simple ... well, a trivial collision detection: Particles that are inside a virtual sphere with the specified radius will be moved out of the sphere on the shortest way.
(package private) static void computeCandidateState(int numParticles, float[] positions, float[] candidatePositions, float[] velocities, float[] accelerations, float damping, float dt)
          Compute the candidate state for the simulation, by advancing the simulation by one time step, integrating the accelerations to update the velocities, and the velocities to update the positions.
(package private) static void computeCandidateState(int numParticles, int minIndex, int maxIndex, float[] positions, float[] candidatePositions, float[] velocities, float[] accelerations, float damping, float dt)
          Compute the candidate state for the simulation, by advancing the simulation by one time step, integrating the accelerations to update the velocities, and the velocities to update the positions.
(package private) static java.lang.String debugCandidatePosition(ParticleData s, int i)
          Debugging method
(package private) static float debugDistance(ParticleData s, int pi0, int pi1)
          Debugging method
(package private) static java.lang.String debugPosition(ParticleData s, int i)
          Debugging method
(package private) static void enforceConstraints(EdgeData[] e, float[] candidatePositions, float[] invMasses, float deviation, int numIterations)
          Perform the specified number of iterations for the edge constraint enforcement.
(package private) static void enforceConstraintsSingleIteration(int numEdges, int[] edgeVertexIndices, float[] edgeRestLengths, float[] candidatePositions, float[] invMasses, float deviation)
          Perform a single iteration of the edge constraint enforcement.
(package private) static void enforceGlobalConstraints(int numConstraints, int[] constraints, float[] constraintPositions, float[] positions, float[] candidatePositions, float[] velocities)
          Enforce the global constraints.
(package private) static void initAccelerations(int numParticles, float[] accelerations)
          Initialize the accelerations to be only the gravity (-9.81 in negative y-direction)
(package private) static void initConstraintMasses(int numConstraints, int[] constraints, float[] invMasses)
          Initialize the inverse particle masses of the particles specified by the given constraints to a "large" number (theoretically, it should be "positive infinity", but #INF should be avoided)
(package private) static void updateVelocities(int numParticles, float[] positions, float[] candidatePositions, float[] velocities, float dt)
          Update the velocities of the particles.
(package private) static void updateVelocities(int numParticles, int minIndex, int maxIndex, float[] positions, float[] candidatePositions, float[] velocities, float dt)
          Update the velocities of the particles.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

computeCandidateState

static void computeCandidateState(int numParticles,
                                  float[] positions,
                                  float[] candidatePositions,
                                  float[] velocities,
                                  float[] accelerations,
                                  float damping,
                                  float dt)
Compute the candidate state for the simulation, by advancing the simulation by one time step, integrating the accelerations to update the velocities, and the velocities to update the positions. Thus, this is one simple Euler integration step.

Parameters:
numParticles - The number of particles
positions - The particle positions
candidatePositions - The candidate positions
velocities - The particle velocities
accelerations - The particle accelerations
damping - The damping factor
dt - The time step size

computeCandidateState

static void computeCandidateState(int numParticles,
                                  int minIndex,
                                  int maxIndex,
                                  float[] positions,
                                  float[] candidatePositions,
                                  float[] velocities,
                                  float[] accelerations,
                                  float damping,
                                  float dt)
Compute the candidate state for the simulation, by advancing the simulation by one time step, integrating the accelerations to update the velocities, and the velocities to update the positions. Thus, this is one simple Euler integration step.

Parameters:
numParticles - The number of particles
minIndex - The minimum particle index to treat here
maxIndex - The maximum particle index to treat here
positions - The particle positions
candidatePositions - The candidate positions
velocities - The particle velocities
accelerations - The particle accelerations
damping - The damping factor
dt - The time step size

enforceConstraints

static void enforceConstraints(EdgeData[] e,
                               float[] candidatePositions,
                               float[] invMasses,
                               float deviation,
                               int numIterations)
Perform the specified number of iterations for the edge constraint enforcement. Simply calls enforceConstraintsSingleIteration(int, int[], float[], float[], float[], float) the specified number of times for each EdgeData

Parameters:
e - The EdgeData
candidatePositions - The candidate positions
invMasses - The inverse vertex masses
deviation - The deviation from the rest length that an edge must hat so that a correction is applied
numIterations - The number of iterations

enforceConstraintsSingleIteration

static void enforceConstraintsSingleIteration(int numEdges,
                                              int[] edgeVertexIndices,
                                              float[] edgeRestLengths,
                                              float[] candidatePositions,
                                              float[] invMasses,
                                              float deviation)
Perform a single iteration of the edge constraint enforcement. For each edge, the particles will be moved along the direction of the edge so that the edge has its rest length.

Parameters:
numEdges - The number of edges
edgeVertexIndices - The edge vertex indices
candidatePositions - The candidate positions
invMasses - The inverse vertex masses
edgeRestLengths - The edge rest lengths
deviation - The deviation from the rest length that an edge must hat so that a correction is applied

collisionDetection

static void collisionDetection(int numParticles,
                               float[] candidatePositions,
                               float sphereRadius)
Perform a simple ... well, a trivial collision detection: Particles that are inside a virtual sphere with the specified radius will be moved out of the sphere on the shortest way.

Parameters:
numParticles - The number of particles
candidatePositions - The candidate positions
sphereRadius - The sphere radius

collisionDetection

static void collisionDetection(int numParticles,
                               int minIndex,
                               int maxIndex,
                               float[] candidatePositions,
                               float sphereRadius)
Perform a simple ... well, a trivial collision detection: Particles that are inside a virtual sphere with the specified radius will be moved out of the sphere on the shortest way.

Parameters:
numParticles - The number of particles
minIndex - The minimum particle index to treat here
maxIndex - The maximum particle index to treat here
candidatePositions - The candidate positions
sphereRadius - The sphere radius

updateVelocities

static void updateVelocities(int numParticles,
                             float[] positions,
                             float[] candidatePositions,
                             float[] velocities,
                             float dt)
Update the velocities of the particles. The velocities will be computed from the difference of the position and the candidate position, assuming the given time step.

Parameters:
numParticles - The number of particles
positions - The positions
candidatePositions - The candidate positions
velocities - The velocities
dt - The time step size

updateVelocities

static void updateVelocities(int numParticles,
                             int minIndex,
                             int maxIndex,
                             float[] positions,
                             float[] candidatePositions,
                             float[] velocities,
                             float dt)
Update the velocities of the particles. The velocities will be computed from the difference of the position and the candidate position, assuming the given time step.

Parameters:
numParticles - The number of particles
minIndex - The minimum particle index to treat here
maxIndex - The maximum particle index to treat here
positions - The positions
candidatePositions - The candidate positions
velocities - The velocities
dt - The time step size

enforceGlobalConstraints

static void enforceGlobalConstraints(int numConstraints,
                                     int[] constraints,
                                     float[] constraintPositions,
                                     float[] positions,
                                     float[] candidatePositions,
                                     float[] velocities)
Enforce the global constraints. That is, sets the positions and candidate positions of all constrained particles to the given constraint positions, and their velocities to zero.

Parameters:
numConstraints - The number of constraints
constraints - The constraints (indices of constrained particles)
constraintPositions - The constraint positions
positions - The positions
candidatePositions - The candidate positions
velocities - The velocities

initConstraintMasses

static void initConstraintMasses(int numConstraints,
                                 int[] constraints,
                                 float[] invMasses)
Initialize the inverse particle masses of the particles specified by the given constraints to a "large" number (theoretically, it should be "positive infinity", but #INF should be avoided)

Parameters:
numConstraints - The number of constraints
constraints - The constraints (indices of constrained particles)
invMasses - The inverse particle masses

initAccelerations

static void initAccelerations(int numParticles,
                              float[] accelerations)
Initialize the accelerations to be only the gravity (-9.81 in negative y-direction)

Parameters:
numParticles - The number of particles
accelerations - The accelerations

debugDistance

static float debugDistance(ParticleData s,
                           int pi0,
                           int pi1)
Debugging method

Parameters:
s -
pi0 -
pi1 -
Returns:
distance

debugPosition

static java.lang.String debugPosition(ParticleData s,
                                      int i)
Debugging method

Parameters:
s -
i -
Returns:
string

debugCandidatePosition

static java.lang.String debugCandidatePosition(ParticleData s,
                                               int i)
Debugging method

Parameters:
s -
i -
Returns:
string