simpleSpring.h
#include <maya/MIOStream.h>
#include <maya/MTime.h>
#include <maya/MVector.h>
#include <maya/MObject.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxSpringNode.h>
class MIntArray;
class MVectorArray;
#define McheckErr(stat, msg) \
if ( MS::kSuccess != stat ) \
{ \
cerr << msg; \
return MS::kFailure; \
}
class simpleSpring: public MPxSpringNode
{
public:
simpleSpring();
virtual ~simpleSpring();
static void *creator();
static MStatus initialize();
virtual MStatus compute( const MPlug& plug, MDataBlock& block );
virtual MStatus applySpringLaw( double stiffness,
double damping, double restLength,
double endMass1, double endMass2,
const MVector &endP1, const MVector &endP2,
const MVector &endV1, const MVector &endV2,
MVector &forceV1, MVector &forceV2 );
static MObject aSpringFactor;
static MTypeId id;
double end1WeightValue( MDataBlock& block );
double end2WeightValue( MDataBlock& block );
private:
double springFactor( MDataBlock& block );
double factor;
};
inline double simpleSpring::springFactor( MDataBlock& block )
{
MStatus status;
MDataHandle hValue = block.inputValue( aSpringFactor, &status );
double value = 0.0;
if( status == MS::kSuccess )
value = hValue.asDouble();
return( value );
}
inline double simpleSpring::end1WeightValue( MDataBlock& block )
{
MStatus status;
MDataHandle hValue = block.inputValue( mEnd1Weight, &status );
double value = 0.0;
if( status == MS::kSuccess )
value = hValue.asDouble();
return( value );
}
inline double simpleSpring::end2WeightValue( MDataBlock& block )
{
MStatus status;
MDataHandle hValue = block.inputValue( mEnd2Weight, &status );
double value = 0.0;
if( status == MS::kSuccess )
value = hValue.asDouble();
return( value );
}