com.jmex.effects.cloth
Class ClothPatch

java.lang.Object
  extended by com.jme.scene.Spatial
      extended by com.jme.scene.Geometry
          extended by com.jme.scene.TriMesh
              extended by com.jmex.effects.cloth.ClothPatch
All Implemented Interfaces:
Savable, 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 4383 2009-06-02 05:40:07Z mulova $
Author:
Joshua Slack
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme.scene.TriMesh
TriMesh.Mode
 
Nested classes/interfaces inherited from class com.jme.scene.Spatial
Spatial.CullHint, Spatial.LightCombineMode, Spatial.NormalsMode, Spatial.TextureCombineMode
 
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
indexBuffer, mode, triangleQuantity
 
Fields inherited from class com.jme.scene.Geometry
binormalBuf, bound, castsShadows, colorBuf, compVect, defaultColor, displayListID, enabled, fogBuf, hasDirtyVertices, normBuf, states, tangentBuf, texBuf, vboInfo, vertBuf, vertQuantity
 
Fields inherited from class com.jme.scene.Spatial
cullHint, frustrumIntersects, geometricalControllers, isCollidable, lightCombineMode, localRotation, localScale, localTranslation, LOCKED_BOUNDS, LOCKED_BRANCH, LOCKED_MESH_DATA, LOCKED_NONE, LOCKED_SHADOWS, LOCKED_TRANSFORMS, lockedMode, name, normalsMode, parent, queueDistance, renderQueueMode, renderStateList, textureCombineMode, worldBound, worldRotation, worldScale, worldTranslation, zOrder
 
Constructor Summary
ClothPatch()
           
ClothPatch(java.lang.String name, int nodesX, int nodesY, float springLength, float nodeMass)
          Public constructor.
ClothPatch(java.lang.String name, int nodesX, int nodesY, Vector3f upperLeft, Vector3f lowerLeft, Vector3f lowerRight, Vector3f upperRight, float nodeMass)
           
 
Method Summary
 void addForce(SpringPointForce 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(int vert1, int vert2, int 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.
protected  void initCloth(float nodeMass, Vector3f upperLeft, Vector3f lowerLeft, Vector3f lowerRight, Vector3f upperRight)
          Initialize the values of the vertex, normal and texture[0] arrays.
 void read(JMEImporter e)
           
 boolean removeForce(SpringPointForce force)
          Remove a force from the underlying SpringSystem.
 void setActive(boolean active)
          Whether or not to update cloth patch
 void setTimeDilation(float timeDilation)
          Set the timedilation factor used in updateWorldData(float) Normally this is set to 1.
 void setUpdateFrequency(float fps)
          set update frequency of flag motion
protected  void setupIndices()
          Setup the triangle indices for this cloth.
 void updateNormals()
          Update the normals in the system.
protected  void updateVertexBufferfer()
           
 void updateWorldData(float dt)
          Update the physics of this cloth.
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.scene.TriMesh
clearBuffers, draw, findCollisions, findTriangleCollision, findTrianglePick, getIndexBuffer, getMaxIndex, getMeshAsTriangles, getMeshAsTrianglesVertices, getMode, getTriangle, getTriangle, getTriangleCount, getTriangleIndices, getVertIndex, hasCollision, hasTriangleCollision, randomPointOnTriangles, recalcTriangleQuantity, reconstruct, setIndexBuffer, setMode, setTriangleQuantity
 
Methods inherited from class com.jme.scene.Geometry
addTextureCoordinates, addTextureCoordinates, applyRenderState, checkTextureCoordinates, clearTextureBuffers, copyTextureCoordinates, copyTextureCoordinates, findPick, getBinormalBuffer, getColorBuffer, getDefaultColor, getDisplayListID, getFogBuffer, getLightState, getModelBound, getNormalBuffer, getNumberOfUnits, getTangentBuffer, getTextureCoords, getTextureCoords, getVBOInfo, getVertexBuffer, getVertexCount, getWorldCoords, getWorldNormals, hasDirtyVertices, isCastsShadows, lockMeshes, postdraw, predraw, randomVertex, reconstruct, resizeTextureIds, rotateNormals, rotatePoints, scaleTextureCoordinates, scaleTextureCoordinates, setBinormalBuffer, setCastsShadows, setColorBuffer, setDefaultColor, setDisplayListID, setFogCoordBuffer, setHasDirtyVertices, setLightState, setModelBound, setNormalBuffer, setRandomColors, setSolidColor, setTangentBuffer, setTextureCoords, setTextureCoords, setTextureCoords, setVBOInfo, setVertexBuffer, setVertexCount, sortLights, translatePoints, translatePoints, unlockMeshes, updateModelBound, updateWorldBound
 
Methods inherited from class com.jme.scene.Spatial
addController, calculateCollisions, calculatePick, clearControllers, clearRenderState, clearRenderState, getClassTag, getController, getControllerCount, getControllers, getCullHint, getLastFrustumIntersection, getLightCombineMode, getLocalCullHint, getLocalLightCombineMode, getLocalNormalsMode, getLocalRenderQueueMode, getLocalRotation, getLocalScale, getLocalTextureCombineMode, getLocalToWorldMatrix, getLocalTranslation, getLocks, getName, getNormalsMode, getParent, getRenderQueueMode, getRenderState, getRenderState, getTextureCombineMode, getUserData, getWorldBound, getWorldRotation, getWorldScale, getWorldTranslation, getZOrder, hasAncestor, isCollidable, localToWorld, lock, lock, lockBounds, lockBranch, lockMeshes, lockShadows, lockTransforms, lookAt, onDraw, propagateBoundToRoot, propagateStatesFromRoot, removeController, removeController, removeFromParent, removeUserData, rotateUpTo, setCullHint, setIsCollidable, setLastFrustumIntersection, setLightCombineMode, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalTranslation, setLocalTranslation, setLocks, setLocks, setName, setNormalsMode, setParent, setRenderQueueMode, setRenderState, setTextureCombineMode, setUserData, setZOrder, setZOrder, toString, unlock, unlock, unlockBounds, unlockBranch, unlockMeshes, unlockShadows, unlockTransforms, updateGeometricState, updateRenderState, updateRenderState, updateWorldRotation, updateWorldScale, updateWorldTranslation, updateWorldVectors, updateWorldVectors, worldToLocal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.jme.util.export.Savable
getClassTag
 

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()

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.

ClothPatch

public ClothPatch(java.lang.String name,
                  int nodesX,
                  int nodesY,
                  Vector3f upperLeft,
                  Vector3f lowerLeft,
                  Vector3f lowerRight,
                  Vector3f upperRight,
                  float nodeMass)
Method Detail

addForce

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

Parameters:
force - SpringPointForce

removeForce

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

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

updateNormals

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


getTriangleNormal

protected Vector3f getTriangleNormal(int vert1,
                                     int vert2,
                                     int 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.

initCloth

protected void initCloth(float nodeMass,
                         Vector3f upperLeft,
                         Vector3f lowerLeft,
                         Vector3f lowerRight,
                         Vector3f upperRight)
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.
upperLeft - the upper left corner of the rectangle.
lowerLeft - the lower left corner of the rectangle.
lowerRight - the lower right corner of the rectangle.
upperRight - the upper right corner of the rectangle.

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

setUpdateFrequency

public void setUpdateFrequency(float fps)
set update frequency of flag motion

Parameters:
fps - frame per second

setActive

public void setActive(boolean active)
Whether or not to update cloth patch

Parameters:
active - if true, enable flag motion

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.

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

updateVertexBufferfer

protected void updateVertexBufferfer()

write

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

read

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