com.jme.math.spring
Class SpringSystem

java.lang.Object
  extended by com.jme.math.spring.SpringSystem
All Implemented Interfaces:
Savable

public class SpringSystem
extends java.lang.Object
implements Savable

SpringSystem is a set of springs and nodes that act and update as a cohesive unit.

Version:
$Id: SpringSystem.java 4131 2009-03-19 20:15:28Z blaine.dev $
Author:
Joshua Slack

Field Summary
protected  java.util.ArrayList<SpringPoint> nodes
          Array of SpringNodes in this system.
protected  java.util.ArrayList<Spring> springs
          Array of Springs in this system.
 
Constructor Summary
SpringSystem()
          Public constructor useful for creating custom SpringSystems.
 
Method Summary
 void addForce(SpringPointForce force)
          Add an external force to this system.
 void addNode(SpringPoint node)
          Add a SpringNode to this system.
 void addSpring(Spring spring)
          Add a Spring to this system.
 void addSpring(SpringPoint node1, SpringPoint node2)
          Create and add a Spring to this system given two nodes.
 void calcForces(float dt)
          Calculate all external forces to be applied on the system nodes.
static SpringSystem createRectField(int width, int height, java.nio.FloatBuffer verts, float particleMass)
          Convienence method for creating a rectangular system of springs and nodes.
 java.lang.Class getClassTag()
           
 SpringPoint getNode(int index)
          Grab a specific node from this system.
 int getNodeCount()
          Return the number of nodes in this system.
 int getRelaxLoops()
          Return how many times each spring is updated per SpringSystem update.
 Spring getSpring(int index)
          Grab a specific spring from this system.
 int getSpringCount()
          Return the number of springs in this system.
 void read(JMEImporter e)
           
 boolean removeForce(SpringPointForce force)
          Remove a force from this system.
 boolean removeNode(SpringPoint node)
          Remove a given SpringNode from this system.
 boolean removeSpring(Spring spring)
          Remove a given Spring from this system.
 void setRelaxLoops(int relaxLoops)
          Set how many times the springs are updated per SpringSystem update.
 void update(float dt)
          Update the SpringNodes and Springs in this System.
 void write(JMEExporter e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodes

protected java.util.ArrayList<SpringPoint> nodes
Array of SpringNodes in this system.


springs

protected java.util.ArrayList<Spring> springs
Array of Springs in this system.

Constructor Detail

SpringSystem

public SpringSystem()
Public constructor useful for creating custom SpringSystems.

Method Detail

getNode

public SpringPoint getNode(int index)
Grab a specific node from this system.

Parameters:
index - int
Returns:
SpringNode

getNodeCount

public int getNodeCount()
Return the number of nodes in this system.

Returns:
int

addNode

public void addNode(SpringPoint node)
Add a SpringNode to this system.

Parameters:
node - SpringNode

removeNode

public boolean removeNode(SpringPoint node)
Remove a given SpringNode from this system.

Parameters:
node - SpringNode
Returns:
true if SpringNode is found and removed.

getSpring

public Spring getSpring(int index)
Grab a specific spring from this system.

Parameters:
index - int
Returns:
Spring

getSpringCount

public int getSpringCount()
Return the number of springs in this system.

Returns:
int

addSpring

public void addSpring(SpringPoint node1,
                      SpringPoint node2)
Create and add a Spring to this system given two nodes.

Parameters:
node1 - SpringNode
node2 - SpringNode

addSpring

public void addSpring(Spring spring)
Add a Spring to this system.

Parameters:
spring - Spring

removeSpring

public boolean removeSpring(Spring spring)
Remove a given Spring from this system.

Parameters:
spring - Spring
Returns:
true if Spring is found and removed.

setRelaxLoops

public void setRelaxLoops(int relaxLoops)
Set how many times the springs are updated per SpringSystem update. More updates results in tighter more accurate springs at the cost of speed.

Parameters:
relaxLoops - int should be at least 2 for stability.

getRelaxLoops

public int getRelaxLoops()
Return how many times each spring is updated per SpringSystem update.

Returns:
int

addForce

public void addForce(SpringPointForce force)
Add an external force to this system.

Parameters:
force - SpringPointForce

removeForce

public boolean removeForce(SpringPointForce force)
Remove a force from this system.

Parameters:
force - SpringPointForce
Returns:
true if found and removed.

createRectField

public static SpringSystem createRectField(int width,
                                           int height,
                                           java.nio.FloatBuffer verts,
                                           float particleMass)
Convienence method for creating a rectangular system of springs and nodes. This system will contain approximately 4 structural, 4 shear and 4 bend springs per node (except for edge and corner nodes)

Parameters:
width - number of nodes wide
height - number of nodes high
verts - a precreated array of vertices. These should be setup from left to right, top to bottom.
normals - a precreated array to use as normals. Should be ordered the same as the verts array.
particleMass - a mass applied to each individual node. Total system mass would equals particleMass x width x height. (i.e. particale mass x getNodeCount())
Returns:
The newly created SpringSystem

calcForces

public void calcForces(float dt)
Calculate all external forces to be applied on the system nodes. This should be done before a call to update.

Parameters:
dt - change in time since last call to this function in ms.

update

public void update(float dt)
Update the SpringNodes and Springs in this System. Update the Springs multiple times as defined by setRelaxLoops() (default is 2)

Parameters:
dt - float

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Throws:
java.io.IOException

getClassTag

public java.lang.Class getClassTag()
Specified by:
getClassTag in interface Savable