本文整理汇总了C++中MFnNurbsCurve::tangent方法的典型用法代码示例。如果您正苦于以下问题:C++ MFnNurbsCurve::tangent方法的具体用法?C++ MFnNurbsCurve::tangent怎么用?C++ MFnNurbsCurve::tangent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MFnNurbsCurve
的用法示例。
在下文中一共展示了MFnNurbsCurve::tangent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getMatrixFromParamCurve
MMatrix ropeGenerator::getMatrixFromParamCurve( MFnNurbsCurve &curveFn, float param, float twist, MAngle divTwist )
{
MPoint pDivPos;
//Here we control the tangent of the rope
curveFn.getPointAtParam( param, pDivPos, MSpace::kWorld );
MVector vTangent( curveFn.tangent( param, MSpace::kWorld ).normal() );
MVector vNormal( curveFn.normal( param, MSpace::kWorld ).normal() );
if ( MAngle( PrevNormal.angle( vNormal ) ).asDegrees() > 90 )
//fprintf(stderr, "Angle = %g\n",MAngle( PrevNormal.angle( vNormal )).asDegrees());
vNormal = vNormal * -1;
PrevNormal = vNormal;
//if ( vNormal.angle( ) )
MQuaternion qTwist( twist * divTwist.asRadians(), vTangent );
vNormal = vNormal.rotateBy( qTwist );
MVector vExtra( vNormal ^ vTangent );
vNormal.normalize();
vTangent.normalize();
vExtra.normalize();
double dTrans[4][4] ={
{vNormal.x, vNormal.y, vNormal.z, 0.0f},
{vTangent.x, vTangent.y, vTangent.z, 0.0f},
{vExtra.x, vExtra.y, vExtra.z, 0.0f},
{pDivPos.x,pDivPos.y,pDivPos.z, 1.0f}};
MMatrix mTrans( dTrans );
return mTrans;
}
示例2: computeSlerp
void n_tentacle::computeSlerp(const MMatrix &matrix1, const MMatrix &matrix2, const MFnNurbsCurve &curve, double parameter, double blendRot, double iniLength, double curveLength, double stretch, double globalScale, int tangentAxis, MVector &outPos, MVector &outRot)
{
//curveLength = curve.length()
double lenRatio = iniLength / curveLength;
MQuaternion quat1;
quat1 = matrix1;
MQuaternion quat2;
quat2 = matrix2;
this->bipolarityCheck(quat1, quat2);
//need to adjust the parameter in order to maintain the length between elements, also for the stretch
MVector tangent;
MPoint pointAtParam;
MPoint finaPos;
double p = lenRatio * parameter * globalScale;
double finalParam = p + (parameter - p) * stretch;
if(curveLength * finalParam > curveLength)
{
double lengthDiff = curveLength - (iniLength * parameter);
double param = curve.knot(curve.numKnots() - 1);
tangent = curve.tangent(param, MSpace::kWorld);
tangent.normalize();
curve.getPointAtParam(param, pointAtParam, MSpace::kWorld);
finaPos = pointAtParam;
pointAtParam += (- tangent) * lengthDiff;
//MGlobal::displayInfo("sdf");
}
else
{
double param = curve.findParamFromLength(curveLength * finalParam);
tangent = curve.tangent(param, MSpace::kWorld);
tangent.normalize();
curve.getPointAtParam(param, pointAtParam, MSpace::kWorld);
}
MQuaternion slerpQuat = slerp(quat1, quat2, blendRot);
MMatrix slerpMatrix = slerpQuat.asMatrix();
int axisId = abs(tangentAxis) - 1;
MVector slerpMatrixYAxis = MVector(slerpMatrix(axisId, 0), slerpMatrix(axisId, 1), slerpMatrix(axisId, 2));
slerpMatrixYAxis.normalize();
if(tangentAxis < 0)
slerpMatrixYAxis = - slerpMatrixYAxis;
double angle = tangent.angle(slerpMatrixYAxis);
MVector axis = slerpMatrixYAxis ^ tangent;
axis.normalize();
MQuaternion rotationToSnapOnCurve(angle, axis);
MQuaternion finalQuat = slerpQuat * rotationToSnapOnCurve;
MEulerRotation finalEuler = finalQuat.asEulerRotation();
outRot.x = finalEuler.x;
outRot.y = finalEuler.y;
outRot.z = finalEuler.z;
outPos = pointAtParam;
}
示例3: preSolve
MStatus splineSolverNode::preSolve()
{
MStatus stat;
setRotatePlane(false);
setSingleChainOnly(true);
setPositionOnly(false);
//Get Handle
MIkHandleGroup * handle_group = handleGroup();
if (NULL == handle_group) {
return MS::kFailure;
}
MObject handle = handle_group->handle( 0 );
MDagPath handlePath = MDagPath::getAPathTo( handle );
fnHandle.setObject( handlePath );
//Get Curve
MPlug inCurvePlug = fnHandle.findPlug( "inCurve" );
MDataHandle curveHandle = inCurvePlug.asMDataHandle();
MObject inputCurveObject = curveHandle.asNurbsCurveTransformed();
curveFn.setObject( inputCurveObject );
float initCurveLength = curveFn.length();
MVector initNormal = curveFn.normal(0);
MVector initTangent = curveFn.tangent(0);
float stretchRatio = 1;
// Get the position of the end_effector
//
MDagPath effectorPath;
fnHandle.getEffector(effectorPath);
tran.setObject( effectorPath );
// Get the start joint position
//
MDagPath startJointPath;
fnHandle.getStartJoint( startJointPath );
joints.clear();
//Get Joints
while (true)
{
effectorPath.pop();
joints.push_back( effectorPath );
if (effectorPath == startJointPath)
break;
}
std::reverse(joints.begin(), joints.end());
if (!fnHandle.hasAttribute("str"))
{
//Add Custom Attributes to Handle
MFnNumericAttribute fnAttr;
MObject attr = fnAttr.create("stretchRatio", "str", MFnNumericData::kDouble, stretchRatio);
fnAttr.setKeyable(1);
fnAttr.setWritable(1);
fnAttr.setMin(0);
fnAttr.setMax(1);
fnAttr.setHidden(0);
fnAttr.setStorable(1);
fnAttr.setReadable(1);
fnHandle.addAttribute(attr, MFnDependencyNode::kLocalDynamicAttr);
attr = fnAttr.create("anchorPosition", "ancp", MFnNumericData::kDouble, 0.0);
fnAttr.setKeyable(1);
fnAttr.setWritable(1);
fnAttr.setMin(0);
fnAttr.setMax(1);
fnAttr.setHidden(0);
fnAttr.setStorable(1);
fnAttr.setReadable(1);
fnHandle.addAttribute(attr, MFnDependencyNode::kLocalDynamicAttr);
attr = fnAttr.create("curveLength", "cvLen", MFnNumericData::kDouble, initCurveLength);
fnAttr.setKeyable(0);
fnAttr.setWritable(1);
fnAttr.setHidden(1);
fnAttr.setStorable(1);
fnAttr.setReadable(1);
fnHandle.addAttribute(attr, MFnDependencyNode::kLocalDynamicAttr);
attr = fnAttr.create("initNormal", "norm", MFnNumericData::k3Double);
fnAttr.setDefault(initNormal.x, initNormal.y, initNormal.z);
fnAttr.setKeyable(0);
fnAttr.setWritable(1);
fnAttr.setHidden(1);
fnAttr.setStorable(1);
fnAttr.setReadable(1);
fnHandle.addAttribute(attr, MFnDependencyNode::kLocalDynamicAttr);
attr = fnAttr.create("initTangent", "tang", MFnNumericData::k3Double);
fnAttr.setDefault(initTangent.x, initTangent.y, initTangent.z);
fnAttr.setKeyable(0);
fnAttr.setWritable(1);
fnAttr.setHidden(1);
fnAttr.setStorable(1);
fnAttr.setReadable(1);
fnHandle.addAttribute(attr, MFnDependencyNode::kLocalDynamicAttr);
attr = fnAttr.create("jointsLength", "jsLen", MFnNumericData::kDouble, getJointsTotalLenght());
fnAttr.setKeyable(0);
fnAttr.setWritable(1);
fnAttr.setHidden(1);
fnAttr.setStorable(1);
fnAttr.setReadable(1);
fnHandle.addAttribute(attr, MFnDependencyNode::kLocalDynamicAttr);
attr = fnAttr.create("startTwist", "strtw", MFnNumericData::kDouble, 0.0);
fnAttr.setKeyable(1);
fnAttr.setWritable(1);
fnAttr.setHidden(0);
fnAttr.setStorable(1);
//.........这里部分代码省略.........