j3d.org Code

org.j3d.geom.spring
Class SpringSystem

java.lang.Object
  extended by org.j3d.geom.spring.SpringSystem

public class SpringSystem
extends java.lang.Object

An implementation of a spring system, particularly useful for modelling cloth dynamics.

The spring system assumes that it is operating over the top of some underlying geometry. As such, it tries to minimise the performance impacts by directly operating on the same array that is used by the geometry itself during rendering. The arrays that are passed to the system are not copied, just directly referenced and each node in the system acts as a .

Version:
$Revision: 1.2 $
Author:
Justin Couch

Constructor Summary
SpringSystem()
          Create a new default spring system.
 
Method Summary
 void addRectField(int width, int height, float[] pos, float[] norm)
          Add a retangular field of spring node location points to this field.
 void evaluateNormals()
          Update the normals now following in any post-processing after the update.
 void getGravity(float[] grav)
          Get the currently set gravity strength and direction vector.
 SpringNode getNode(int index)
          Get the node at the given index.
 int getNodeCount()
          Get the number of nodes that this system is currently maintaining.
 float getSpringConstant()
          Get the currently set spring constant setting.
 void resetNaturalLengths()
          Regenerate the natural lengths between the various nodes based on the current separation between each node's current position and it's connections.
 void setCustomSpringField(SpringNode[] nodes, int numValid)
          Create a custom spring field to be evaluated.
 void setGravity(float[] grav)
          Set a new gravity strength and direction vector.
 void setSpringConstant(float val)
          Set a new value for how stretchy the springs are.
 void update(float dTime)
          Time to update all the interactions between the springs and nodes.
 void update(float dTime, SpringEvaluatorCallback callback)
          Time to update all the interactions between the springs and nodes.
 void update(float dTime, SpringEvaluatorCallback callback, float[] attribs)
          Time to update all the interactions between the springs and nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringSystem

public SpringSystem()
Create a new default spring system. Gravity is pointed downwards with a value of -9.8 and spring constant of 200.

Method Detail

addRectField

public void addRectField(int width,
                         int height,
                         float[] pos,
                         float[] norm)
Add a retangular field of spring node location points to this field. Each node in the field is connected to the 4 surrounding nodes.

Parameters:
width - The number of points in the width of the field
height - The number of points in the height of the field
pos - An array of positions, one per location to work on
norm - An array of normals, one per location to work on

setCustomSpringField

public void setCustomSpringField(SpringNode[] nodes,
                                 int numValid)
Create a custom spring field to be evaluated. A null value or zero length will clear the current field so that there is nothing to evaluate.

Parameters:
nodes - The list of nodes to use
numValid - The number of valid entries in the list to use

resetNaturalLengths

public void resetNaturalLengths()
Regenerate the natural lengths between the various nodes based on the current separation between each node's current position and it's connections. The direction information on each spring is reset to zero too.


update

public void update(float dTime)
Time to update all the interactions between the springs and nodes.

Parameters:
dTime - The delta in time between the last update and this

update

public void update(float dTime,
                   SpringEvaluatorCallback callback)
Time to update all the interactions between the springs and nodes.

Parameters:
dTime - The delta in time between the last update and this
callback - A per-node extra processing if needed callback

update

public void update(float dTime,
                   SpringEvaluatorCallback callback,
                   float[] attribs)
Time to update all the interactions between the springs and nodes.

Parameters:
dTime - The time delta from last evaluation
callback - A per-node extra processing if needed callback
attribs - Any per-node attribute info that is useful for the callback

evaluateNormals

public void evaluateNormals()
Update the normals now following in any post-processing after the update.


getNode

public SpringNode getNode(int index)
Get the node at the given index.

Parameters:
index - The index of the spring node to fetch
Returns:
The node at that index or null if index > getNodeCount()

getNodeCount

public int getNodeCount()
Get the number of nodes that this system is currently maintaining.

Returns:
a Value >= 0

setGravity

public void setGravity(float[] grav)
Set a new gravity strength and direction vector.

Parameters:
grav - The new values to use for gravity

getGravity

public void getGravity(float[] grav)
Get the currently set gravity strength and direction vector.

Parameters:
grav - an array to copy the values into

setSpringConstant

public void setSpringConstant(float val)
Set a new value for how stretchy the springs are. Any value is OK but negative values are likely to cause interesting visual effects. The greater the number, the more still the springs are.

Parameters:
val - The new values to use for the constant

getSpringConstant

public float getSpringConstant()
Get the currently set spring constant setting.

Returns:
The current setting value

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org