Пример #1
0
void GetBarycentricCoordinates(const MPoint& P, const MPoint& A, const MPoint& B, const MPoint& C,
                               BaryCoords& coords) {
  // Compute the normal of the triangle
  MVector N = (B - A) ^ (C - A);
  MVector unitN = N.normal();

  // Compute twice area of triangle ABC
  double areaABC = unitN * N;

  if (areaABC == 0.0) {
    // If the triangle is degenerate, just use one of the points.
    coords[0] = 1.0f;
    coords[1] = 0.0f;
    coords[2] = 0.0f;
    return;
  }

  // Compute a
  double areaPBC = unitN * ((B - P) ^ (C - P));
  coords[0] = (float)(areaPBC / areaABC);

  // Compute b
  double areaPCA = unitN * ((C - P) ^ (A - P));
  coords[1] = (float)(areaPCA / areaABC);

  // Compute c
  coords[2] = 1.0f - coords[0] - coords[1];
}
void vixo_hairCacheExport::buildCache(int maxSpan,MObject& dynamicMeshObj,vector<vec3>& outCurveCacheData,map<int,MVectorArray>& inCurveShape,map<int,vector<outVIDCtrlInfo>>& outVertexControlData)
{
	MItMeshVertex iterMesh(dynamicMeshObj);
	int pre=0;
	for(int i=0;i<iterMesh.count();i++)
	{
		map<int,vector<outVIDCtrlInfo>>::iterator outcdIter=outVertexControlData.find(i);
		iterMesh.setIndex(i,pre);
		MVector normal;
		iterMesh.getNormal(normal,MSpace::kWorld);
		for(int ctrls=0;ctrls<outcdIter->second.size();ctrls++)
		{
			iterMesh.setIndex(outcdIter->second[ctrls].inVID,pre);
			MVector inNormal;
			iterMesh.getNormal(inNormal,MSpace::kWorld);
			map<int,MVectorArray>::iterator iterInCurve=inCurveShape.find(outcdIter->second[ctrls].inVID);
			MQuaternion quar=inNormal.rotateTo(normal);
			for(int j=0;j<maxSpan;j++)
			{
				MVector tempTan=iterInCurve->second[j].rotateBy(quar)*outcdIter->second[ctrls].percent;
				outCurveCacheData[i*maxSpan+j].x+=tempTan.x;
				outCurveCacheData[i*maxSpan+j].y+=tempTan.y;
				outCurveCacheData[i*maxSpan+j].z+=tempTan.z;
			}
		}
	}
	//output data
}
Пример #3
0
void unique(MVector<T>& s)
{
  s.sort();
  typename MVector<T>::Iter it1(s), it2(s,1);
  for ( ; it2(); ++it2) if (*it2 != *it1) { ++it1; *it1 = *it2; }
  s.setCnt(it1.getPos()+1,0);
}
Пример #4
0
MMatrix  sgLockAngleMatrix::getsgLockAngleMatrix( const MMatrix& inputMatrix, unsigned char axis, double angle )
{
	MStatus status;

	angle = angle/180 * PI;
	bool minusAxis = false;

	if( axis > 2 )
	{
		minusAxis = true;
		axis -= 3;
	}
	unsigned int upAxis = ( axis+1 ) % 3;
	unsigned int crossAxis = ( axis+2 ) % 3;

	MVector vDefault( 0,0,0 );
	vDefault[ axis ] = 1;
	MVector vAxis = inputMatrix[ axis ];
	vAxis.normalize();

	double dotValue = vAxis * vDefault;
	double cuAngle = acos( dotValue );

	if( angle > cuAngle ) angle = cuAngle;

	MVector vCross = vDefault ^ vAxis;
	MVector vUp    = vCross ^ vDefault;

	vUp.normalize();
	MVector vEdit = sin( angle ) * vUp + cos( angle ) * vDefault;

	if( minusAxis ) vEdit *= -1;

	MVector vUpEdit;
	vUpEdit[ axis ] = -vEdit[ upAxis ];
	vUpEdit[ upAxis ] = vEdit[ axis ];
	vUpEdit[ crossAxis ] = 0;

	MVector vCrossEdit = vEdit ^ vUpEdit;
	vUpEdit = vCrossEdit ^ vEdit;

	vEdit.normalize();
	vUpEdit.normalize();
	vCrossEdit.normalize();

	MMatrix returnMtx;

	returnMtx( axis, 0 ) = vEdit.x;
	returnMtx( axis, 1 ) = vEdit.y;
	returnMtx( axis, 2 ) = vEdit.z;
	returnMtx( upAxis, 0 ) = vUpEdit.x;
	returnMtx( upAxis, 1 ) = vUpEdit.y;
	returnMtx( upAxis, 2 ) = vUpEdit.z;
	returnMtx( crossAxis, 0 ) = vCrossEdit.x;
	returnMtx( crossAxis, 1 ) = vCrossEdit.y;
	returnMtx( crossAxis, 2 ) = vCrossEdit.z;

	return returnMtx;
}
Пример #5
0
void exportTerrain::printLightData(const MFnLight& theLight){
	fout << "Color: " << theLight.intensity()*theLight.color() << endl;

	MVector dir = theLight.lightDirection( 0, MSpace::kWorld);
	dir.normalize();
	fout << "Direction: " << dir << endl;

}
Пример #6
0
void splineSolverNode::gsOrthonormalize( MVector &normal, MVector &tangent )
{
    // Gram-Schmidt Orthonormalization
    normal.normalize();
    MVector proj = normal * ( tangent * normal ); // normal * dotProduct(tangent,normal)
    tangent = tangent - proj;
    tangent.normalize();

}
Пример #7
0
// COMPUTE ======================================
MStatus gear_uToPercentage::compute(const MPlug& plug, MDataBlock& data)
{
	MStatus returnStatus;
	// Error check
    if (plug != percentage)
        return MS::kUnknownParameter;

	// Curve
	MFnNurbsCurve crv( data.inputValue( curve ).asNurbsCurve() );

	// Sliders
	bool in_normU = data.inputValue( normalizedU ).asBool();
	double in_u = (double)data.inputValue( u ).asFloat();
	unsigned in_steps = data.inputValue( steps ).asShort();

	// Process
	if (in_normU)
		in_u = normalizedUToU(in_u, crv.numCVs());

	// Get length
	MVectorArray u_subpos(in_steps);
	MVectorArray t_subpos(in_steps);
	MPoint pt;
	double step;
	for (unsigned i = 0; i < in_steps ; i++){

		step = i * in_u / (in_steps - 1.0);
		crv.getPointAtParam(step, pt, MSpace::kWorld);
		u_subpos[i] = MVector(pt);

        step = i/(in_steps - 1.0);
		crv.getPointAtParam(step, pt, MSpace::kWorld);
		t_subpos[i] = MVector(pt);

	}
	
	double u_length = 0;
	double t_length = 0;
	MVector v;
	for (unsigned i = 0; i < in_steps ; i++){
		if (i>0){
			v = u_subpos[i] - u_subpos[i-1];
			u_length += v.length();
			v = t_subpos[i] - t_subpos[i-1];
			t_length += v.length();
		}
	}

	double out_perc = (u_length / t_length) * 100;
		
	// Output
    MDataHandle h = data.outputValue( percentage );
    h.setDouble( out_perc );
    data.setClean( plug );

	return MS::kSuccess;
}
Пример #8
0
MQuaternion splineSolverNode::quaternionFromVectors(MVector vec1, MVector vec2)
{
    MVector crosVec = vec1^vec2;
    float w = sqrt((vec1.length() * vec1.length()) * (vec2.length() * vec2.length())) + vec1*vec2;
    //float w = 1.0f + vBaseJoint*vFinalJoint;
    MQuaternion q(crosVec.x, crosVec.y, crosVec.z, w );
    q.normalizeIt();
    return q;
}
Пример #9
0
  bool BatchPrecip::PrecipBatchSS(double dTime, MVector & Prod, double CurLevel)
  {
  MIBayer & ProdB   = *Prod.GetIF<MIBayer>();
  MIPSD & ProdSz    = *Prod.FindIF<MIPSD>();
  MISSA & ProdSSA   = *Prod.FindIF<MISSA>();
  double TProd = Prod.getT();
  double gpl1 = ProdB.SolidsConc(TProd);
  double ProdVolFlow = Prod.Volume(MP_All);
  double SolidsInitial  = Prod.Mass(MP_Sol);

  double Sx;
  if (!sm_bCompletePopulation && sm_bUsePrevPSD)
    {
    MISSA & PrevSSA=*m_QProd.FindIF<MISSA>();// this is the SSA of the last Popul run to use in "NO POpul mode"
    if (IsNothing(PrevSSA))
      {
	   m_bPrevPSDUsed = 0;
      Sx=ProdSSA.SpecificSurfaceAreaMass(); //m^2/g//PROBLEM!!! Prev does not have SSA, use feed
      }
    else
      {
	  m_bPrevPSDUsed = 1;
      Sx=PrevSSA.SpecificSurfaceAreaMass(); //m^2/g
      }
    }
  else
    {
	m_bPrevPSDUsed = 0;
    Sx = m_dInTankSSA ; // the SSA value manually entered by the user in m^2/g
    }
  Sx=Range(0.020, Sx, 0.085);
 
  //=== mass balance ===
  double T0 = Prod.T;
  double Ain2 = ProdB.AluminaConc(C2K(25.0));
  double Cin2 = ProdB.CausticConc(C2K(25.0));
  double ASat2 = ProdB.AluminaConcSat(T0);
  double SSat2 = (Ain2-ASat2)/GTZ(Cin2);
  double NoPerSec2 = ProdSSA.PartNumPerSec();
  double enthIn = Prod.totCp(MP_All) * K2C(T0); // Enthalpie IN

  double PrecipRate1 = get_PrecipRate(Prod, Sx);
  gpl1 =  gpl1 - PrecipRate1 * dTime*156/102 ;

  bool CErr;
  const double Na2OFac = get_Na2OFactor(Prod);

  PerformAluminaSolubility(Prod, dNAN, dNAN, gpl1, 0, Na2OFac, SSat2, CErr);

  double T1 = Prod.T;
 
  double SolidsVariation =  (Prod.Mass(MP_Sol) - SolidsInitial); //* 0.97 ;// 0.97 is to compensate for the HYPROD error
  HeatBalance(Prod, SolidsVariation, enthIn, dTime, CurLevel);  // Éliminé pour vérifier la temp ?
  
  return true;
  }
Пример #10
0
MStatus AimNode::compute(const MPlug& plug, MDataBlock& dataBlock)
{
	MStatus	status;
	if ((plug == aOutputRotate) || (plug == aOutputRotateX) ||
		(plug == aOutputRotateY) || (plug == aOutputRotateZ))
	{
		// the matrix to aim at 
		MMatrix driverMatrix = dataBlock.inputValue(aDriverMatrix).asMatrix();
		// the matrix to use as the upVector
		MMatrix upVectorMatrix = dataBlock.inputValue(aUpVectorMatrix).asMatrix();
		MVector inputTranslate = dataBlock.inputValue(aInputTranslate).asVector();
		MMatrix parentInverse = dataBlock.inputValue(aParentInverseMatrix).asMatrix();

		driverMatrix *= parentInverse;
		upVectorMatrix *= parentInverse;
		//extract the translation from the matrices
		MVector driverMatrixPos(driverMatrix[3][0],
			driverMatrix[3][1],
			driverMatrix[3][2]);

		MVector upVectorMatrixPos(upVectorMatrix[3][0],
			upVectorMatrix[3][1],
			upVectorMatrix[3][2]);

		//get the vectors
		MVector aimVector = driverMatrixPos - inputTranslate;
		MVector upVector = upVectorMatrixPos - inputTranslate;
		
		//upVector *= parentInverse;
		aimVector.normalize();
		upVector.normalize();

		//perpendicter vector
		MVector cross = aimVector ^ upVector;
		upVector = cross ^ aimVector;

		//build rotationMatrix
		double tmpMatrix[4][4]{{aimVector.x, aimVector.y, aimVector.z, 0},
									{upVector.x, upVector.y, upVector.z, 0},
									{cross.x, cross.y, cross.z, 0},
									{inputTranslate[0], inputTranslate[1], inputTranslate[2], 1}};

		//eulerRotations
		MMatrix rotationMatrix(tmpMatrix);
		MTransformationMatrix matrixfn(rotationMatrix);
		MEulerRotation eular = matrixfn.eulerRotation();

		dataBlock.outputValue(aOutputRotate).set(eular.x, eular.y, eular.z);
		dataBlock.outputValue(aOutputRotate).setClean();

	}

	return MS::kSuccess;

}
Пример #11
0
char BCIViz::checkFirstFour(const MPointArray & p) const
{
	const MVector e01 = p[1] - p[0];
	const MVector e02 = p[2] - p[0];
	MVector nor = e01^e02;
	nor.normalize();
	const float d = -(MVector(p[0])*nor); // P.N + d = 0 , P = P0 + Vt, (P0 + Vt).N + d = 0, t = -(P0.N + d)/(V.N)
	const float t = MVector(p[3])*nor + d; // where V = -N
	if(t > -10e-5 && t < 10e-5) return 0;
	return 1;
}
Пример #12
0
MStatus sgHair_controlJoint::getJointPositionBaseWorld()
{
	MStatus status;

	if( !m_bStaticRotation )
	{
		MVector vAim;
		MVector vUp( m_mtxJointParentBase(1,0), m_mtxJointParentBase(1,1), m_mtxJointParentBase(1,2) );
		MVector vCross;
		MMatrix mtxLocal;
		MMatrix mtxWorld = m_mtxJointParentBase;

		m_mtxArrBase.setLength( m_cvs.length() );

		for( int i=0; i< m_cvs.length()-1; i++ )
		{
			vAim = ( m_cvs[i+1] - m_cvs[i] )*m_mtxBaseCurve;
			vCross = vAim ^ vUp;
			vUp = vCross ^ vAim;
			vAim.normalize();
			vUp.normalize();
			vCross.normalize();
			m_mtxArrBase[i] = buildMatrix( vAim, vUp, vCross, m_cvs[i]*m_mtxBaseCurve );
		}
		MPoint pointWorld = m_cvs[m_cvs.length()-1]*m_mtxBaseCurve;

		MMatrix mtxLastWorld;
		mtxLastWorld( 3, 0 ) = pointWorld.x;
		mtxLastWorld( 3, 1 ) = pointWorld.y;
		mtxLastWorld( 3, 2 ) = pointWorld.z;

		m_mtxArrBase[m_cvs.length()-1] = mtxLastWorld;
	}
	else
	{
		MVector aim( 1,0,0 );
		MVector up( 0,1,0 );
		MVector cross( 0,0,1 );

		m_mtxArrBase.setLength( m_cvs.length() );

		aim *= m_mtxJointParentBase;
		up *= m_mtxJointParentBase;
		cross *= m_mtxJointParentBase;

		for( int i=0; i< m_cvs.length(); i++ )
		{
			m_mtxArrBase[i] = buildMatrix( aim, up, cross, m_cvs[i]*m_mtxBaseCurve );
		}
	}

	return MS::kSuccess;
}
Пример #13
0
void CreateMatrix(const MPoint& origin, const MVector& normal, const MVector& up,
                  MMatrix& matrix) {
  const MPoint& t = origin;
  const MVector& y = normal;
  MVector x = y ^ up;
  MVector z = x ^ y;
  // Renormalize vectors
  x.normalize();
  z.normalize();
  matrix[0][0] = x.x; matrix[0][1] = x.y; matrix[0][2] = x.z; matrix[0][3] = 0.0;
  matrix[1][0] = y.x; matrix[1][1] = y.y; matrix[1][2] = y.z; matrix[1][3] = 0.0;
  matrix[2][0] = z.x; matrix[2][1] = z.y; matrix[2][2] = z.z; matrix[2][3] = 0.0;
  matrix[3][0] = t.x; matrix[3][1] = t.y; matrix[3][2] = t.z; matrix[3][3] = 1.0;
}
Пример #14
0
MStatus VolumePushCollider::compute(const MPlug& plug, MDataBlock& dataBlock)
{
	MStatus status;

	if (plug == aOutput)
	{
		// inCollider
		MArrayDataHandle hInCollider = dataBlock.inputArrayValue(aInCollider);
		// inVolume
		MArrayDataHandle hInVolume = dataBlock.inputArrayValue(aInVolume);
		// output
		MArrayDataHandle hOutput = dataBlock.inputArrayValue(aOutput);
		MDoubleArray daValues(hInVolume.elementCount());

		for (unsigned int c=0; c<hInCollider.elementCount(); c++)
		{
			// Calculate the total of every collider value for each volume
			status = hInCollider.jumpToArrayElement(c);
			CHECK_MSTATUS_AND_RETURN_IT(status);
			MMatrix mInCollider = hInCollider.inputValue().asMatrix();
			MTransformationMatrix tmInCollider(mInCollider);
			MPoint pInCollider = tmInCollider.getTranslation(MSpace::kWorld, &status);
			CHECK_MSTATUS_AND_RETURN_IT(status);

			for (unsigned int v=0; v<hInVolume.elementCount(); v++)
			{
				// pointMatrixMult
				status = hInVolume.jumpToArrayElement(v);
				CHECK_MSTATUS_AND_RETURN_IT(status);
				MMatrix mInVolume = hInVolume.inputValue().asMatrix();
				MVector vVolCollider = pInCollider * mInVolume;
				// condition
				if (vVolCollider.length() <= 1.0)
				{
					// reverse
					daValues[v] += abs(1.0 - vVolCollider.length());
				}
			}
		}
		for (unsigned int i=0; i<hInVolume.elementCount(); i++)
		{
			// set outputs
			status = hOutput.jumpToArrayElement(i);
			CHECK_MSTATUS_AND_RETURN_IT(status);
			hOutput.outputValue().set(daValues[i]);
		}
		dataBlock.setClean(plug);
	}
	return MS::kSuccess;
}
Пример #15
0
double MVector::innerProduct( MVector Vec_B )
{
	set<int> ID_AB = this->getKeys(); // get A-keys
	set<int> ID_B   = Vec_B.getKeys(); // get B-keys
	ID_AB.insert(ID_B.begin(), ID_B.end()); // merge AB-keys

	double result = 0.0;
	for (set<int>::iterator iter = ID_AB.begin(); iter != ID_AB.end(); iter++)
	{
		result += this->getElem(*iter) * Vec_B.getElem(*iter);
	}

	return result;
}
Пример #16
0
MVector MVector::subtract( MVector Vec_B )
{
	set<int> ID_AB = this->getKeys(); // get A-keys
	set<int> ID_B   = Vec_B.getKeys(); // get B-keys
	ID_AB.insert(ID_B.begin(), ID_B.end()); // merge AB-keys

	MVector result(this->DIM);
	for (set<int>::iterator iter = ID_AB.begin(); iter != ID_AB.end(); iter++)
	{
		double value = this->getElem(*iter) - Vec_B.getElem(*iter);
		result.setElem(*iter, value);
	}

	return result;
}
Пример #17
0
void sgHair_controlJoint::cleanMatrix( MMatrix& mtx )
{
	MVector vAim( mtx(0,0), mtx(0,1), mtx(0,2) );
	MVector vUp( mtx(1,0), mtx(1,1), mtx(1,2) );

	MVector vCross = vAim ^ vUp;
	vUp = vCross ^ vAim;

	vAim.normalize();
	vUp.normalize();
	vCross.normalize();

	mtx( 0, 0 ) = vAim.x; mtx( 0, 1 ) = vAim.y; mtx( 0, 2 ) = vAim.z;
	mtx( 1, 0 ) = vUp.x;  mtx( 1, 1 ) = vUp.y;  mtx( 1, 2 ) = vUp.z;
	mtx( 2, 0 ) = vCross.x;  mtx( 2, 1 ) = vCross.y;  mtx( 2, 2 ) = vCross.z;
}
Пример #18
0
MVector MG_poseReader::matrixToAxisMatrix (const int &aimAxis , const MMatrix &matrix,const int normalize){

	MVector toVec;
	switch ( aimAxis )
			{

				case 0:
					if (aimAxis==0)
					{
						toVec[0]=matrix[0][0];
						toVec[1]=matrix[0][1];
						toVec[2]=matrix[0][2];

					
					}

					
				case 1:
					if (aimAxis==1)
					{
						toVec[0]=matrix[1][0];
						toVec[1]=matrix[1][1];
						toVec[2]=matrix[1][2];
				
					
					}
				case 2:
					if (aimAxis==2)
					{
						toVec[0]=matrix[2][0];
						toVec[1]=matrix[2][1];
						toVec[2]=matrix[2][2];


					}

			 

				
				 }
	toVec.normalize();


	return toVec;


}
Пример #19
0
MStatus moveContext::doPress( MEvent & event )
{
	MStatus stat = MPxSelectionContext::doPress( event );
	MSpace::Space spc = MSpace::kWorld;

	// If we are not in selecting mode (i.e. an object has been selected)
	// then set up for the translation.
	//
	if ( !isSelecting() ) {
		event.getPosition( startPos_x, startPos_y );
		view = M3dView::active3dView();

		MDagPath camera;
		stat = view.getCamera( camera );
		if ( stat != MS::kSuccess ) {
			cerr << "Error: M3dView::getCamera" << endl;
			return stat;
		}
		MFnCamera fnCamera( camera );
		MVector upDir = fnCamera.upDirection( spc );
		MVector rightDir = fnCamera.rightDirection( spc );

		// Determine the camera used in the current view
		//
		if ( fnCamera.isOrtho() ) {
			if ( upDir.isEquivalent(MVector::zNegAxis,kVectorEpsilon) ) {
				currWin = TOP;
			} else if ( rightDir.isEquivalent(MVector::xAxis,kVectorEpsilon) ) {
				currWin = FRONT;
			} else  {
				currWin = SIDE;
			}
		}
		else {
			currWin = PERSP;
		}

		// Create an instance of the move tool command.
		//
		cmd = (moveCmd*)newToolCommand();

		cmd->setVector( 0.0, 0.0, 0.0 );
	}
	return stat;
}
Пример #20
0
	// used when ray does not intersect object
	// to account for perspective, all edges are flattened onto 
	// a plane defined by the raySource and rayDirection
	double gpuCacheIsectUtil::getEdgeSnapPointOnTriangle(const MPoint& raySource, const MVector& rayDirection, const MPoint& vert1, const MPoint& vert2, const MPoint& vert3, MPoint& snapPoint){
		MPointArray verts;
		verts.insert(vert1,0);
		verts.insert(vert2,1);
		verts.insert(vert3,2);

		int edgeIndices[3][2]={{0,1},{1,2},{2,0}};

		double minDistTri = std::numeric_limits<double>::max();

		for(int edge=0; edge<3;edge++){
			MPoint vertex1Org = verts[edgeIndices[edge][0]];
			MPoint vertex2Org = verts[edgeIndices[edge][1]];

			double coef_plane = rayDirection * raySource;
			double d = coef_plane - rayDirection * vertex1Org;
			MPoint vertex1 = vertex1Org + rayDirection * d;
			d = coef_plane - rayDirection * vertex2Org;
			MPoint vertex2 = vertex2Org + rayDirection * d;

			MVector edgeDir = vertex2 - vertex1;
			
			if (edgeDir.length()<0.0000001){
				double dist = vertex1.distanceTo(raySource);
				if (dist < minDistTri) {
					minDistTri = dist;
					snapPoint = vertex1Org;
				}
			} else {
				MPoint edgePt;
				// Compute the closest point from the edge to cursor Ray.
				double percent = gpuCacheIsectUtil::getClosestPointOnLine(raySource, vertex1, vertex2, edgePt);
				double dist = edgePt.distanceTo(raySource);                                                            
				if (dist < minDistTri) {
					minDistTri = dist;
					snapPoint =  (vertex1Org + percent * (vertex2Org - vertex1Org));
				}
			}
		}

		return minDistTri;
	}
Пример #21
0
void CLimnStream::ConvertToFracForm(MVector & M, bool ApplyScale)
  {
  if (!m_bIsMassForm)
    return;
  if (DoDbgCvt)
    Dump("ConvertToFracForm:Before", DoDbgCvt);

  MArrayI Tot;
  // Current Total
  for (int ii=0; ii<gs_DWCfg.m_SeqIndex.GetCount(); ii++)
    {
    int i=gs_DWCfg.m_SeqIndex[ii];
    Tot[gs_DWCfg.m_SpIds[i]] += m_Data[i];
    };
  
  if (ApplyScale)
    {
    for (int id=0; id<gs_MVDefn.Count(); id++)
      {
      M.M[id]=Tot[id]/gs_DWCfg.m_MassFactor[id];
      Tot[id]=GTZ(Tot[id]);
      }
    M.MarkStateChanged();
    }
  else
    {
    for (int id=0; id<gs_MVDefn.Count(); id++)
      {
      M.M[id]=Tot[id];
      Tot[id]=GTZ(Tot[id]);
      }
    M.MarkStateChanged();
    }
  for (int ii=0; ii<gs_DWCfg.m_SeqIndex.GetCount(); ii++)
    {
    int i  = gs_DWCfg.m_SeqIndex[ii];
    m_Data[i] = m_Data[i]/Tot[gs_DWCfg.m_SpIds[i]];
    };
  m_bIsMassForm = false;
  if (DoDbgCvt)
    Dump("ConvertToFracForm:After", DoDbgCvt);
  };
Пример #22
0
MMatrix retargetLocator::getAimMatrix( MMatrix inputAimMatrix )
{
	MVector aimVector( inputAimMatrix(3,0), inputAimMatrix(3,1), inputAimMatrix(3,2) );
	aimVector -= discOffset;

	MVector upVector( -aimVector.y - aimVector.z, aimVector.x, aimVector.x );
	MVector otherVector = aimVector^upVector;
	upVector = otherVector^aimVector;

	MVector normalizeAim = aimVector.normal();
	upVector.normalize();
	otherVector.normalize();

	aimVector += discOffset;
	double buildMatrix[4][4] = { normalizeAim.x, normalizeAim.y, normalizeAim.z, 0,
	                             upVector.x,  upVector.y,  upVector.z,  0,
	                             otherVector.x, otherVector.y, otherVector.z, 0,
								 aimVector.x, aimVector.y, aimVector.z, 1 };
	return MMatrix( buildMatrix );
}
Пример #23
0
void GetValidUp(const MDoubleArray& weights, const MPointArray& points,
                const MIntArray& sampleIds, const MPoint& origin, const MVector& normal,
                MVector& up) {
  MVector unitUp = up.normal();
  // Adjust up if it's parallel to normal or if it's zero length
  if (std::abs((unitUp * normal) - 1.0) < 0.001 || up.length() < 0.0001) {
    for (unsigned int j = 0; j < weights.length()-1; ++j) {
      up -= (points[sampleIds[j]] - origin) * weights[j];
      unitUp = up.normal();
      if (std::abs((unitUp * normal) - 1.0) > 0.001 && up.length() > 0.0001) {
        // If the up and normal vectors are no longer parallel and the up vector has a length,
        // then we are good to go.
        break;
      }
    }
    up.normalize();
  } else {
    up = unitUp;
  }
}
Пример #24
0
void MVGManipulator::getTranslatedWSEdgePoints(M3dView& view,
                                               const MVGManipulatorCache::EdgeData* originEdgeData,
                                               MPoint& originCSPosition, MPoint& targetWSPosition,
                                               MPointArray& targetEdgeWSPositions) const
{
    assert(originEdgeData != NULL);
    MVector edgeCSVector =
        MVGGeometryUtil::worldToCameraSpace(view, originEdgeData->vertex1->worldPosition) -
        MVGGeometryUtil::worldToCameraSpace(view, originEdgeData->vertex2->worldPosition);
    MVector vertex1ToMouseCSVector =
        originCSPosition -
        MVGGeometryUtil::worldToCameraSpace(view, originEdgeData->vertex1->worldPosition);
    float ratioVertex1 = vertex1ToMouseCSVector.length() / edgeCSVector.length();
    float ratioVertex2 = 1.f - ratioVertex1;

    MVector edgeWSVector =
        originEdgeData->vertex1->worldPosition - originEdgeData->vertex2->worldPosition;
    targetEdgeWSPositions.append(targetWSPosition + ratioVertex1 * edgeWSVector);
    targetEdgeWSPositions.append(targetWSPosition - ratioVertex2 * edgeWSVector);
}
Пример #25
0
MMatrix sgHair_controlJoint::getAngleWeightedMatrix( const MMatrix& targetMtx, double weight )
{
	MMatrix mtx;
	if( m_bStaticRotation )
	{
		mtx = MMatrix() * ( weight-1 ) + targetMtx * weight;
		cleanMatrix( mtx );
	}
	else
	{
		MVector vUpDefault( 0, 1, 0 );
		MVector vCrossDefault( 0,0,1 );
		MVector vUpInput( targetMtx(1,0), targetMtx(1,1), targetMtx(1,2) );

		double angleUp = vUpInput.angle( vUpDefault ) * weight;

		if( vUpInput.x == 0 && vUpInput.z == 0 ) vUpInput.x = 1;
		MVector direction( vUpInput.x, 0, vUpInput.z );
		direction.normalize();

		MVector vUp( sin( angleUp ) * direction.x, cos( angleUp ), sin( angleUp ) * direction.z );
		double dot = vUp * MVector( 0.0, 0.0, 1.0 );
		MVector vCross( 0.0, -dot, (dot+1) );
		MVector vAim = vUp ^ vCross;

		vAim.normalize();
		vUp.normalize();
		vCross = vAim ^ vUp;

		mtx( 0, 0 ) = vAim.x;
		mtx( 0, 1 ) = vAim.y;
		mtx( 0, 2 ) = vAim.z;
		mtx( 1, 0 ) = vUp.x;
		mtx( 1, 1 ) = vUp.y;
		mtx( 1, 2 ) = vUp.z;
		mtx( 2, 0 ) = vCross.x;
		mtx( 2, 1 ) = vCross.y;
		mtx( 2, 2 ) = vCross.z;
	}
	return mtx;
}
Пример #26
0
bool SysCADSystemHelper::SystemSolidsToSysCAD(MVector &SysCAD,RioTintoTS::PFlowStream1 &System)

//
// Copy System solids size data to SysCAD Size Data
//

{
	MIPSD & PSD=*SysCAD.GetIF<MIPSD>();
	if (!IsNothing(PSD))
	{  
		const int NumComps = PSD.getPSDVectorCount();
		const int NumSizes = PSD.getSizeCount();

		// Get a reference to the System solids Matrices.
		// copy these feed size distributions to the SysCAD solids size data
		RioTintoTS::MatrixView &SystemSolids = System->AccessSolidsMatrix();


		// For each component
		for (int c=0; c<NumComps; c++)
		{
			// Get the size data for component c
			// The size data is smallest to largest in units of kg/s

			// Index into SysCAD Component Masses
			const int SpId = PSD.getSpecieIndex(c);

			// Insert the resultant size data into the SysCAD Output Size Data
			RioTintoTS::VectorView iCompSize = SystemSolids.column(c);

			double m = 0.0;
			for (int s=0; s<NumSizes; s++)
			{
				// Accumulate each size fraction to the total mass for the component
				m += iCompSize[s];
			}
			SysCAD.putM(SpId, m*1000/3600);
			double f = 0.0;

			for (int s=0; s<NumSizes; s++)
			{
				const double d = m>0.0 ? iCompSize[s]/m : 0.0;
				f += d;
				PSD.putFrac(c,NumSizes-s-1, d);
			}

		}
		return true;
	}

	return false;
}
Пример #27
0
void NurbsCurveEmitter::Fill(const FieldRef& field)
{
	MFnNurbsCurve curve(mObject);

	// Get the range for U and V.
	MPlug minValuePlug = curve.findPlug("minValue");
	MPlug maxValuePlug = curve.findPlug("maxValue");

	const Double minValue = minValuePlug.asDouble();
	const Double maxValue = maxValuePlug.asDouble();

	const Double valueRange = maxValue - minValue;

	int i = 0;
	for (i = 0; i < static_cast<int>(mSample); ++ i)
	{
		double u = Stokes::Random::NextAsDouble();
		double v = Stokes::Random::NextAsDouble();
		double w = Stokes::Random::NextAsDouble();

		double param = u * valueRange + minValue;

		MPoint p;
		curve.getPointAtParam(param, p, MSpace::kWorld);
		MVector t = curve.tangent(param, MSpace::kWorld);
		t.normalize();
		MVector n = curve.normal(param, MSpace::kWorld);
		n.normalize();
		MVector b = n ^ t;

		double r = sqrt(v);
		double phi = w * 2.0 * M_PI;
		double x = r * cos(phi);
		double y = r * sin(phi);

		// TODO: No radius here.
		MPoint newP = p + n * x + b * y;

		MVector radialDirection = newP - p;
		radialDirection.normalize();
		
		Stokes::Vectorf noisedPoint(Random::NextAsFloat() * mScale.x - mOffset.x, Random::NextAsFloat() * mScale.y - mOffset.y, static_cast<Float>(u) * mScale.z - mOffset.z);
		Float displacement = Stokes::Noiser::FractalBrownianMotion(noisedPoint, mDisplacedH, mDisplacedLacunarity, mDisplacedOctave) * mDisplacedAmplitude;
		MPoint displacedP = newP + radialDirection * displacement;
		Stokes::Vectorf worldPoint(static_cast<Stokes::Float>(displacedP.x), static_cast<Stokes::Float>(displacedP.y), static_cast<Stokes::Float>(displacedP.z));

		Stokes::Vectoriu index;
		if (field->CalculateIndexFromWorldPoint(worldPoint, index))
		{
			Float density = Stokes::Noiser::FractalBrownianMotion(noisedPoint, mH, mLacunarity, mOctave) * mAmplitude;
			if (density > 0)
			{
				field->Access(index)[0] += density;
			}
		}
	}
}
Пример #28
0
void CylinderMesh::transform(MPointArray& points, MVectorArray& normals)
{
    MVector forward = mEnd - mStart;
    double s = forward.length();
    forward.normalize();

    MVector left = MVector(0,0,1)^forward;
    MVector up;
    if (left.length() < 0.0001)
    {
        up = forward^MVector(0,1,0);
        left = up^forward;
    }
    else
    {
        up = forward^left;
    }

    MMatrix mat;
    mat[0][0] = forward[0]; mat[0][1] = left[0]; mat[0][2] = up[0]; mat[0][3] = 0;
    mat[1][0] = forward[1];   mat[1][1] = left[1]; mat[1][2] = up[1]; mat[1][3] = 0;
    mat[2][0] = forward[2];   mat[2][1] = left[2]; mat[2][2] = up[2]; mat[2][3] = 0;
    mat[3][0] = 0;            mat[3][1] = 0;       mat[3][2] = 0;     mat[3][3] = 1;
    mat = mat.transpose();

    for (int i = 0; i < gPoints.length(); i++)
    {
        MPoint p = gPoints[i];
        p.x = p.x * s; // scale
        p = p * mat + mStart; // transform
        points.append(p);

        MVector n = gNormals[i] * mat;
        normals.append(n);
    }
}
MStatus lrutils::setLocation(MObject obj, MVectorArray location, MFnTransform& transformFn, bool translate, bool rotation, bool scale) {
    MStatus status = MS::kFailure;

    status = transformFn.setObject(obj);
    MyCheckStatusReturn(status, "invalid MObject provided for MFnTransform.setObject()");

    if( status == MS::kSuccess ) {
        if(translate) {
            MVector vTranslation = location[0] ;
            //stringstream text; text << "(" << vTranslation.x << ", " << vTranslation.y << ", " << vTranslation.z << ")";
            //MGlobal::displayInfo( text.str().c_str() );
            status = transformFn.setTranslation(vTranslation, MSpace::kTransform);
            stringstream text; text << "MFnTransform.setTranslation() failed, status code [" << status.errorString().asChar() << "]";
            MyCheckStatusReturn(status, text.str().c_str() ); 
            vTranslation = transformFn.getTranslation(MSpace::kWorld);
            //text.clear(); text << "(" << vTranslation.x << ", " << vTranslation.y << ", " << vTranslation.z << ")";
            //MGlobal::displayInfo( text.str().c_str() );
        }
        if(rotation) {
            MVector vRotation = location[1]*3.141592/180.0;
            MEulerRotation eRotation = MEulerRotation(vRotation);
            status = transformFn.setRotation(eRotation);
        }
        if(scale) {
            MVector vScale = location[2];
            double* scale = new double[3];
            vScale.get(scale);
            transformFn.setScale(scale);
            //make the scale of the controller the identity
            MGlobal::executeCommand("select -r "+transformFn.name()+";");
            MGlobal::executeCommand("makeIdentity -s true -apply true;");
        }
    }

    return status;
}
Пример #30
0
double MG_poseReader::projVector (MVector vec1,MVector vec2)

{

		double proj; 
		float dot = vec1*vec2;
		float vec2L = vec2.length();
		if (vec2L!=0)
		{
		 proj = dot/vec2L;
		}else{
		 proj=0;
		}

		if ((proj<0) || (proj==-0))
			proj=0;
		return proj;
}