Package toxi.physics2d
Class VerletParticle2D
java.lang.Object
toxi.geom.Vec2D
toxi.physics2d.VerletParticle2D
- All Implemented Interfaces:
Comparable<ReadonlyVec2D>
,ReadonlyVec2D
An individual 3D particle for use by the VerletPhysics and VerletSpring
classes. A particle has weight, can be locked in space and its position
constrained inside an (optional) axis-aligned bounding box.
-
Nested Class Summary
Nested classes/interfaces inherited from class toxi.geom.Vec2D
Vec2D.Axis
-
Field Summary
Modifier and TypeFieldDescriptionBounding box, by default set to null to disableAn optional particle constraints, called immediately after a particle is updated (and only used if particle is unlocked (default) -
Constructor Summary
ConstructorDescriptionVerletParticle2D
(float x, float y) Creates particle at position xyzVerletParticle2D
(float x, float y, float w) Creates particle at position xyz with weight wCreates particle at the position of the passed in vectorVerletParticle2D
(ReadonlyVec2D v, float w) Creates particle with weight w at the position of the passed in vectorCreates a copy of the passed in particle -
Method Summary
Modifier and TypeMethodDescriptionaddBehavior
(ParticleBehavior2D behavior) addBehavior
(ParticleBehavior2D behavior, float timeStep) addBehaviors
(Collection<ParticleBehavior2D> behaviors) addBehaviors
(Collection<ParticleBehavior2D> behaviors, float timeStemp) Adds the given constraint implementation to the list of constraints applied to this particle at each time step.addConstraints
(Collection<ParticleConstraint2D> constraints) addVelocity
(Vec2D v) void
void
getForce()
final float
Returns the particle's position at the most recent time step.final float
final boolean
isLocked()
lock()
Locks/immobilizes particle in spaceRemoves any currently applied constraints from this particle.boolean
boolean
removeBehaviors
(Collection<ParticleBehavior2D> behaviors) boolean
Attempts to remove the given constraint instance from the list of active constraints.boolean
removeConstraints
(Collection<ParticleConstraint2D> constraints) scaleVelocity
(float scl) void
setWeight
(float w) unlock()
Unlocks particle againvoid
update()
Methods inherited from class toxi.geom.Vec2D
abs, add, add, add, addSelf, addSelf, angleBetween, angleBetween, bisect, clear, compareTo, constrain, constrain, constrain, copy, cross, distanceTo, distanceToSquared, dot, equals, equals, equalsWithTolerance, floor, frac, fromTheta, getAbs, getCartesian, getComponent, getComponent, getConstrained, getConstrained, getFloored, getFrac, getInverted, getLimited, getMapped, getNormalized, getNormalizedTo, getPerpendicular, getPolar, getReciprocal, getReflected, getRotated, getRoundedTo, getSignum, hashCode, heading, interpolateTo, interpolateTo, interpolateTo, interpolateTo, interpolateToSelf, interpolateToSelf, invert, isInCircle, isInRectangle, isInTriangle, isMajorAxis, isZeroVector, jitter, jitter, jitter, jitter, jitter, jitter, limit, magnitude, magSquared, max, max, maxSelf, min, min, minSelf, normalize, normalizeTo, perpendicular, positiveHeading, randomVector, randomVector, reciprocal, reflect, rotate, roundTo, scale, scale, scale, scale, scaleSelf, scaleSelf, scaleSelf, set, set, set, setComponent, setComponent, setX, setY, signum, snapToAxis, sub, sub, sub, subSelf, subSelf, tangentNormalOfEllipse, to3DXY, to3DXZ, to3DYZ, toArray, toCartesian, toPolar, toString, x, y
-
Field Details
-
bounds
Bounding box, by default set to null to disable -
constraints
An optional particle constraints, called immediately after a particle is updated (and only used if particle is unlocked (default) -
behaviors
-
-
Constructor Details
-
VerletParticle2D
public VerletParticle2D(float x, float y) Creates particle at position xyz- Parameters:
x
-y
-
-
VerletParticle2D
public VerletParticle2D(float x, float y, float w) Creates particle at position xyz with weight w- Parameters:
x
-y
-w
-
-
VerletParticle2D
Creates particle at the position of the passed in vector- Parameters:
v
- position
-
VerletParticle2D
Creates particle with weight w at the position of the passed in vector- Parameters:
v
- positionw
- weight
-
VerletParticle2D
Creates a copy of the passed in particle- Parameters:
p
-
-
-
Method Details
-
addBehavior
-
addBehavior
-
addBehaviors
-
addBehaviors
-
addConstraint
Adds the given constraint implementation to the list of constraints applied to this particle at each time step.- Parameters:
c
- constraint instance- Returns:
- itself
-
addConstraints
-
addForce
-
addVelocity
-
applyBehaviors
public void applyBehaviors() -
applyConstraints
public void applyConstraints() -
clearForce
-
clearVelocity
-
getForce
-
getInvWeight
public final float getInvWeight()- Returns:
- the inverse weight (1/weight)
-
getPreviousPosition
Returns the particle's position at the most recent time step.- Returns:
- previous position
-
getVelocity
-
getWeight
public final float getWeight()- Returns:
- the weight
-
isLocked
public final boolean isLocked()- Returns:
- true, if particle is locked
-
lock
Locks/immobilizes particle in space- Returns:
- itself
-
removeAllBehaviors
-
removeAllConstraints
Removes any currently applied constraints from this particle.- Returns:
- itself
-
removeBehavior
-
removeBehaviors
-
removeConstraint
Attempts to remove the given constraint instance from the list of active constraints.- Parameters:
c
- constraint to remove- Returns:
- true, if successfully removed
-
removeConstraints
-
scaleVelocity
-
setPreviousPosition
-
setWeight
public void setWeight(float w) -
unlock
Unlocks particle again- Returns:
- itself
-
update
public void update()
-