Package toxi.physics2d
Class VerletPhysics2D
java.lang.Object
toxi.physics2d.VerletPhysics2D
3D particle physics engine using Verlet integration based on:
http://en.wikipedia.org/wiki/Verlet_integration
http://www.teknikus.dk/tj/gdc2001.htm
-
Field Summary
Modifier and TypeFieldDescriptionfinal List<ParticleBehavior2D>
final List<ParticleConstraint2D>
List of particlesList of spring/stick connectors -
Constructor Summary
ConstructorDescriptionInitializes a Verlet engine instance using the default values.VerletPhysics2D
(Vec2D gravity, int numIterations, float drag, float timeStep) Initializes an Verlet engine instance with the passed in configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBehavior
(ParticleBehavior2D behavior) void
addConstraint
(ParticleConstraint2D constraint) static void
Adds a particle to the listAdds a spring connectorclear()
float
getDrag()
getIndex()
int
Attempts to find the spring element between the 2 particles suppliedfloat
boolean
boolean
static void
boolean
Removes a particle from the simulation.boolean
Removes a spring connector from the simulation instance.boolean
Removes a spring connector and its both end point particles from the simulationvoid
setDrag
(float drag) void
setIndex
(SpatialIndex<Vec2D> index) void
setNumIterations
(int numIterations) void
setTimeStep
(float timeStep) setWorldBounds
(Rect world) Sets bounding boxupdate()
Progresses the physics simulation by 1 time step and updates all forces and particle positions accordingly
-
Field Details
-
particles
List of particles -
springs
List of spring/stick connectors -
behaviors
-
constraints
-
-
Constructor Details
-
VerletPhysics2D
public VerletPhysics2D()Initializes a Verlet engine instance using the default values. -
VerletPhysics2D
Initializes an Verlet engine instance with the passed in configuration.- Parameters:
gravity
- 3D gravity vectornumIterations
- iterations per time step for verlet solverdrag
- drag value 0...1timeStep
- time step for calculating forces
-
-
Method Details
-
addConstraintToAll
-
removeConstraintFromAll
-
addBehavior
-
addConstraint
-
addParticle
Adds a particle to the list- Parameters:
p
-- Returns:
- itself
-
addSpring
Adds a spring connector- Parameters:
s
-- Returns:
- itself
-
clear
-
getCurrentBounds
-
getDrag
public float getDrag() -
getIndex
- Returns:
- the index
-
getNumIterations
public int getNumIterations()- Returns:
- the numIterations
-
getSpring
Attempts to find the spring element between the 2 particles supplied- Parameters:
a
- particle 1b
- particle 2- Returns:
- spring instance, or null if not found
-
getTimeStep
public float getTimeStep()- Returns:
- the timeStep
-
getWorldBounds
- Returns:
- the worldBounds
-
removeBehavior
-
removeConstraint
-
removeParticle
Removes a particle from the simulation.- Parameters:
p
- particle to remove- Returns:
- true, if removed successfully
-
removeSpring
Removes a spring connector from the simulation instance.- Parameters:
s
- spring to remove- Returns:
- true, if the spring has been removed
-
removeSpringElements
Removes a spring connector and its both end point particles from the simulation- Parameters:
s
- spring to remove- Returns:
- true, only if spring AND particles have been removed successfully
-
setDrag
public void setDrag(float drag) -
setIndex
- Parameters:
index
- the index to set
-
setNumIterations
public void setNumIterations(int numIterations) - Parameters:
numIterations
- the numIterations to set
-
setTimeStep
public void setTimeStep(float timeStep) - Parameters:
timeStep
- the timeStep to set
-
setWorldBounds
Sets bounding box- Parameters:
world
-- Returns:
- itself
-
update
Progresses the physics simulation by 1 time step and updates all forces and particle positions accordingly- Returns:
- itself
-