com.jme.effects.cloth
Class ClothPatch

java.lang.Object
  extended bycom.jme.scene.Spatial
      extended bycom.jme.scene.Geometry
          extended bycom.jme.scene.TriMesh
              extended bycom.jme.effects.cloth.ClothPatch
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
CollidingClothPatch

public class ClothPatch
extends TriMesh

ClothPatch is a rectangular trimesh representing a piece of Cloth. It is backed up by and shares verts and normals with a SpringSystem.

Version:
$Id: ClothPatch.java,v 1.2 2005/03/08 01:30:55 renanse Exp $
Author:
Joshua Slack
See Also:
Serialized Form

Field Summary
protected  int clothNodesX
          width, number of nodes wide on x axis.
protected  int clothNodesY
          height, number of nodes high on y axis.
protected  float sinceLast
          Internal time watch used to track time since last update.
protected  float springLength
          The initial spring length of structural springs.
protected  SpringSystem system
          The underlying SpringSystem for this ClothPatch.
protected  float timeDilation
          Dilation factor to multiply elapsed time by for use in updating underlying system.
 
Fields inherited from class com.jme.scene.TriMesh
indices, triangleQuantity
 
Fields inherited from class com.jme.scene.Geometry
bound, color, colorBuf, normal, normBuf, texBuf, texture, vertBuf, vertex, vertQuantity
 
Fields inherited from class com.jme.scene.Spatial
currentStates, defaultStateList, forceCull, forceView, frustrumIntersects, geometricalControllers, lightCombineMode, localRotation, localScale, localTranslation, name, parent, queueDistance, renderQueueMode, renderStateList, textureCombineMode, worldBound, worldRotation, worldScale, worldTranslation, zOrder
 
Constructor Summary
ClothPatch(java.lang.String name, int nodesX, int nodesY, float springLength, float nodeMass)
          Public constructor.
 
Method Summary
 void addForce(SpringNodeForce force)
          Add an external force to the underlying SpringSystem.
protected  void calcForces(float sinceLast)
          Calculate the forces accting on this cloth.
protected  void doUpdate(float sinceLast)
          Update the spring system underlying this cloth.
 int getClothNodesX()
          Return how many nodes wide this cloth is.
 int getClothNodesY()
          Return how many nodes high this cloth is.
protected  int getIndex(int x, int y)
          Convienence method for calculating the array index of a given node given it's x and y coordiates.
 float getSpringLength()
          Return the preset length the structural springs are set to.
 SpringSystem getSystem()
          Return the underlying SpringSystem.
 float getTimeDilation()
          Get the time dilation factor.
protected  Vector3f getTriangleNormal(Vector3f vert1, Vector3f vert2, Vector3f vert3, Vector3f store)
          Get the normal of the triangle defined by the given vertices.
protected  void initCloth(float nodeMass)
          Initialize the values of the vertex, normal and texture[0] arrays.
 boolean removeForce(SpringNodeForce force)
          Remove a force from the underlying SpringSystem.
 void setTimeDilation(float timeDilation)
          Set the timedilation factor used in updateWorldData(float) Normally this is set to 1.
protected  void setupIndices()
          Setup the triangle indices for this cloth.
 void updateNormals()
          Update the normals in the system.
 void updateWorldData(float dt)
          Update the physics of this cloth.
 
Methods inherited from class com.jme.scene.TriMesh
clearBuffers, draw, drawBounds, findCollisions, findTriangleCollision, findTrianglePick, findWorldRotMat, getIndexAsBuffer, getIndices, getMeshAsTriangles, getTriangle, getTriangle, getTriangleQuantity, hasCollision, hasTriangleCollision, putClone, reconstruct, setIndexBuffer, setIndices, updateCollisionTree, updateIndexBuffer
 
Methods inherited from class com.jme.scene.Geometry
applyRenderState, applyStates, copyTextureCoords, findPick, getAllTextures, getCloneID, getColorAsFloatBuffer, getColors, getModelBound, getNormalAsFloatBuffer, getNormals, getNumberOfUnits, getTextureAsFloatBuffer, getTextureAsFloatBuffer, getTextures, getTextures, getVBOColorID, getVBONormalID, getVBOTextureID, getVBOVertexID, getVerticeAsFloatBuffer, getVertices, getVertQuantity, isVBOColorEnabled, isVBONormalEnabled, isVBOTextureEnabled, isVBOVertexEnabled, randomVertice, reconstruct, setAllTextures, setColor, setColors, setFloatBuffer, setForceView, setModelBound, setNormal, setNormalBuffer, setNormals, setRandomColors, setSolidColor, setTexture, setTexture, setTextureBuffer, setTextureCoord, setTextures, setTextures, setVBOColorEnabled, setVBOColorID, setVBONormalEnabled, setVBONormalID, setVBOTextureEnabled, setVBOTextureID, setVBOVertexEnabled, setVBOVertexID, setVertex, setVertexBuffer, setVertices, updateColorBuffer, updateColorBuffer, updateModelBound, updateNormalBuffer, updateNormalBuffer, updateTextureBuffer, updateTextureBuffer, updateTextureBuffer, updateVertexBuffer, updateVertexBuffer, updateWorldBound
 
Methods inherited from class com.jme.scene.Spatial
addController, applyDefaultStates, calculateCollisions, calculatePick, clearCurrentState, clearCurrentStates, clearRenderState, getController, getControllers, getCurrentState, getLastFrustumIntersection, getLightCombineMode, getLocalRotation, getLocalScale, getLocalTranslation, getName, getParent, getRenderQueueMode, getRenderStateList, getTextureCombineMode, getWorldBound, getWorldRotation, getWorldScale, getWorldTranslation, getZOrder, isForceCulled, isForceView, onDraw, onDrawBounds, propagateBoundToRoot, propagateStatesFromRoot, removeController, removeFromParent, setForceCull, setLightCombineMode, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalTranslation, setName, setParent, setRenderQueueMode, setRenderState, setTextureCombineMode, setWorldBound, setZOrder, toString, updateGeometricState, updateRenderState, updateRenderState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

clothNodesX

protected int clothNodesX
width, number of nodes wide on x axis.


clothNodesY

protected int clothNodesY
height, number of nodes high on y axis.


springLength

protected float springLength
The initial spring length of structural springs.


system

protected SpringSystem system
The underlying SpringSystem for this ClothPatch.


sinceLast

protected float sinceLast
Internal time watch used to track time since last update.


timeDilation

protected float timeDilation
Dilation factor to multiply elapsed time by for use in updating underlying system.

Constructor Detail

ClothPatch

public ClothPatch(java.lang.String name,
                  int nodesX,
                  int nodesY,
                  float springLength,
                  float nodeMass)
Public constructor.

Parameters:
name - String
nodesX - number of nodes wide this cloth will be.
nodesY - number of nodes high this cloth will be.
springLength - distance between each node
nodeMass - mass of an individual node in this Cloth.
Method Detail

addForce

public void addForce(SpringNodeForce force)
Add an external force to the underlying SpringSystem.

Parameters:
force - SpringNodeForce

removeForce

public boolean removeForce(SpringNodeForce force)
Remove a force from the underlying SpringSystem.

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

updateNormals

public void updateNormals()
Update the normals in the system.


getTriangleNormal

protected Vector3f getTriangleNormal(Vector3f vert1,
                                     Vector3f vert2,
                                     Vector3f vert3,
                                     Vector3f store)
Get the normal of the triangle defined by the given vertices. Please note that result is not normalized.

Parameters:
vert1 - triangle point #1
vert2 - triangle point #2
vert3 - triangle point #3
store - Vector3f to store result in
Returns:
normal of triangle, same as store param.

initCloth

protected void initCloth(float nodeMass)
Initialize the values of the vertex, normal and texture[0] arrays. Build a SpringSystem and call setupIndices(). Then update the various buffers.

Parameters:
nodeMass - mass of individual node.

getSystem

public SpringSystem getSystem()
Return the underlying SpringSystem.

Returns:
SpringSystem

getClothNodesY

public int getClothNodesY()
Return how many nodes high this cloth is.

Returns:
int

getClothNodesX

public int getClothNodesX()
Return how many nodes wide this cloth is.

Returns:
int

getSpringLength

public float getSpringLength()
Return the preset length the structural springs are set to. (ie. the springs running along the x and y axis connecting immediate neighbors.)

Returns:
float

getTimeDilation

public float getTimeDilation()
Get the time dilation factor. See setTimeDilation(float) for more.

Returns:
float

setTimeDilation

public void setTimeDilation(float timeDilation)
Set the timedilation factor used in updateWorldData(float) Normally this is set to 1. If set at 2, for example, every 25 ms of real time, the code will update the SpringSystem and cloth as if 50 ms had passed.

Parameters:
timeDilation - float

setupIndices

protected void setupIndices()
Setup the triangle indices for this cloth.


getIndex

protected int getIndex(int x,
                       int y)
Convienence method for calculating the array index of a given node given it's x and y coordiates.

Parameters:
x - int
y - int
Returns:
index

updateWorldData

public void updateWorldData(float dt)
Update the physics of this cloth. Updates at 40 FPS (every 25 ms)

Overrides:
updateWorldData in class Spatial
Parameters:
dt - time since last call to this method. Used to determine if enough time has passed to require an update of the SpringSystem and cloth data, normals, etc.

calcForces

protected void calcForces(float sinceLast)
Calculate the forces accting on this cloth. Called by updateWorldData(float)

Parameters:
sinceLast - float

doUpdate

protected void doUpdate(float sinceLast)
Update the spring system underlying this cloth. Called by updateWorldData(float)

Parameters:
sinceLast - float