Example #1
0
bool PoroElasticity::evalElasticityMatrices (ElmMats& elMat, const Matrix& B,
                                             const FiniteElement& fe,
                                             const Vec3& X) const
{
  SymmTensor eps(nsd), sigma(nsd);
  if (!B.multiply(elMat.vec[Vu],eps))
    return false;

  Matrix C; double U = 0.0;
  if (!material->evaluate(C,sigma,U,fe,X,eps,eps,iS))
    return false;

  // Integrate the (material) stiffness
  Matrix CB;
  if (CB.multiply(C,B).multiply(fe.detJxW).empty()) // CB = dSdE*B*|J|*w
    return false;

  if (elMat.A[uu_K].multiply(B,CB,true,false,true).empty()) // K_uu += B^T * CB
    return false;

  // Integrate the internal forces, if deformed configuration
  if (iS == 0 || eps.isZero(1.0e-16))
    return true;

  sigma *= fe.detJxW;
  return B.multiply(sigma,elMat.b[Fu],true,-1); // F_u -= B^T*sigma
}
Example #2
0
void Camera::updateViewMatrix()
{
	if (invalid)
	{	// 갱신해야 함
		// quaternion 구성
		Quaternion q, qx, qy, qz;
		qx.setFromAxisAngle(baseRight, rotation.getX());
		qy.setFromAxisAngle(baseUp, rotation.getY());
		qz.setFromAxisAngle(baseDirection, rotation.getZ());
		q = qy * qx * qz;

		// 변환 행렬 구성
		Matrix transform;
		q.getMatrix(transform);

		// 축의 변환
		transform.multiply(right, baseRight);
		transform.multiply(up, baseUp);
		transform.multiply(direction, baseDirection);

		// 뷰 행렬 구성
		viewMat.setViewMatrix(position, direction, up);

		invalid = false;
	}
}
Example #3
0
void CADSpline::transform( const Matrix& matrix )
{
    for( CADVector& pt : avertCtrlPoints )
        pt = matrix.multiply( pt );
    for( CADVector& pt : averFitPoints )
        pt = matrix.multiply( pt );
}
void WheelRotator::rotateBy( float degs, bool useLocalYaxis )
{
	float snapAmount = SnapProvider::instance()->angleSnapAmount();
	if (degs > 0 && degs < snapAmount)
		degs = snapAmount;
	if (degs < 0 && degs > -snapAmount)
		degs = -snapAmount;

	rotAmount_ += degs;

	Matrix rotMat;

	if ( (CurrentRotationProperties::properties().size() == 1) && useLocalYaxis )
	{
		Quaternion q;
		q.fromAngleAxis( DEG_TO_RAD(-rotAmount_), initialMatrixes_[0].applyToUnitAxisVector(1) );
		rotMat.setRotate( q );
	}
	else
		rotMat.setRotateY( DEG_TO_RAD(-rotAmount_) );

	// rotate around the centre point
	const Vector3 invCentrePoint(-centrePoint_);
	Matrix invCentrePointMatrix;
	invCentrePointMatrix.setTranslate(invCentrePoint);

	rotMat.translation(centrePoint_);
	rotMat.multiply(invCentrePointMatrix, rotMat);

	std::vector<GenRotationProperty*> props = CurrentRotationProperties::properties();
	int j;
	std::vector<GenRotationProperty*>::iterator i;
	for ( i = props.begin(), j = 0;
		i != props.end();
		++i, ++j)
	{
		Matrix newMatrix;
		newMatrix.multiply(initialMatrixes_[j], rotMat);

		Vector3 pos = newMatrix.applyToOrigin();
		Vector3 newPos = pos;
		if( SnapProvider::instance()->snapMode() != SnapProvider::SNAPMODE_OBSTACLE )
			SnapProvider::instance()->snapPosition( newPos );
		Matrix mover;
		mover.setTranslate( newPos - pos );
		newMatrix.postMultiply( mover );

		Matrix worldToChunk;
		(*i)->pMatrix()->getMatrixContextInverse( worldToChunk );
		newMatrix.multiply(newMatrix, worldToChunk);

		(*i)->pMatrix()->setMatrix( newMatrix );
	}
}
Example #5
0
void Picture::render(Pixel* pix)
{
	double eX, eY, eZ, aX, aY, aZ, fov, zMin, zMax;
	Vector *vUp;
	vUp = readCamera(&eX, &eY, &eZ, &aX, &aY, &aZ);
	readFOV(&zMax, &zMin, &fov);
	BasicObject* obj = readObject("sphere.txt");
	InstanceObject* io = buildInstanceObject("trs.txt", obj);
	Scene *sc;
	Matrix *windowTransform = AffineTransforms::getWindowTransform(pix->getWidth(), pix->getHeight());
	Matrix *aspectRatioTransform = AffineTransforms::getAspectTransform(pix->getWidth(), pix->getHeight(), fov);
	Matrix *normalTransform = AffineTransforms::getNormalTransform(zMin, zMax);
	Matrix *cameraTransform = AffineTransforms::getCameraTransform(eX, eY, eZ, aX, aY, aZ, vUp);
	Matrix *WNAC;

	/*printf("\nCamera: \n");
	cameraTransform->printMatrix();
	printf("\nNormal: \n");
	normalTransform->printMatrix();
	printf("\nAspect Ratio: \n");
	aspectRatioTransform->printMatrix();
	printf("\nWindow: \n");
	windowTransform->printMatrix();*/
	
	Matrix *temp = aspectRatioTransform->multiply(cameraTransform);
	Matrix *temp2 = normalTransform->multiply(temp);
	WNAC = windowTransform->multiply(temp2);

	
	//WNAC->printMatrix();

	delete temp;
	delete temp2;
	delete cameraTransform;
	delete normalTransform;
	delete windowTransform;
	delete aspectRatioTransform;
	
	sc = new Scene(WNAC);


	sc->addNode(io);

	sc->render(pix);

	delete sc;
	printf("\n\n");
}
Example #6
0
void CADPolyline3D::transform( const Matrix& matrix )
{
    for( CADVector& vertex : vertexes )
    {
        vertex = matrix.multiply( vertex );
    }
}
Example #7
0
void CADFace3D::transform( const Matrix& matrix )
{
    for( CADVector& corner : avertCorners )
    {
        corner = matrix.multiply( corner );
    }
}
Example #8
0
bool PoroElasticity::evalSol (Vector& s, const FiniteElement& fe,
                              const Vec3& X, const Vector& disp) const
{
  if (!material)
  {
    std::cerr <<" *** PoroElasticity::evalSol: No material data."<< std::endl;
    return false;
  }

  Matrix Bmat;
  if (!this->formBmatrix(Bmat,fe.dNdX))
    return false;

  SymmTensor eps(nsd), sigma(nsd);
  if (!Bmat.multiply(disp,eps))
    return false;

  Matrix Cmat; double U = 0.0;
  if (!material->evaluate(Cmat,sigma,U,fe,X,eps,eps))
    return false;

  s = eps;
  const RealArray& sig = sigma;
  s.insert(s.end(),sig.begin(),sig.end());

  return true;
}
Example #9
0
bool LagrangeFields2D::gradFE (const FiniteElement& fe, Matrix& grad) const
{
  grad.resize(nf,2,true);

  Vector N;
  Matrix dNdu;
  if (!Lagrange::computeBasis(N,dNdu,p1,fe.xi,p2,fe.eta))
    return false;

  const int nel1 = (n1-1)/p1;

  div_t divresult = div(fe.iel,nel1);
  int iel1 = divresult.rem;
  int iel2 = divresult.quot;
  const int node1 = p1*iel1-1;
  const int node2 = p2*iel2-1;

  const int nen = (p1+1)*(p2+1);
  Matrix Xnod(2,nen), Vnod(nf,nen);

  int locNode = 1;
  for (int j = node2; j <= node2+p2; j++)
    for (int i = node1; i <= node1+p1; i++, locNode++)
    {
      int node = (j-1)*n1 + i;
      Xnod.fillColumn(locNode,coord.getColumn(node));
      Vnod.fillColumn(locNode,values.ptr()+nf*(node-1));
    }

  Matrix Jac, dNdX;
  utl::Jacobian(Jac,dNdX,Xnod,dNdu);
  grad.multiply(Vnod,dNdX);

  return true;
}
Example #10
0
btTransform PhysicsConstraint::getTransformOffset(const Node* node, const Vector3& origin)
{
    GP_ASSERT(node);

    // Create a translation matrix that translates to the given origin.
    Matrix m;
    Matrix::createTranslation(origin, &m);

    // Calculate the translation and rotation offset to the rigid body
    // by transforming the translation matrix above into the rigid body's
    // local space (multiply by the inverse world matrix and extract components).
    Matrix mi;
    node->getWorldMatrix().invert(&mi);
    mi.multiply(m);

    Quaternion r;
    mi.getRotation(&r);
    
    Vector3 t;
    mi.getTranslation(&t);

    Vector3 s;
    node->getWorldMatrix().getScale(&s);

    t.x *= s.x;
    t.y *= s.y;
    t.z *= s.z;
    
    t = offsetByCenterOfMass(node, t);

    return btTransform(BQ(r), BV(t));
}
Example #11
0
Vector3 PhysicsConstraint::getTranslationOffset(const Node* node, const Vector3& point)
{
    GP_ASSERT(node);

    // Create a translation matrix that translates to the given origin.
    Matrix m;
    Matrix::createTranslation(point, &m);

    // Calculate the translation offset to the rigid body by transforming 
    // the translation matrix above into the rigid body's local space 
    // (multiply by the inverse world matrix) and extracting the translation.
    Matrix mi;
    node->getWorldMatrix().invert(&mi);
    mi.multiply(m);
    
    Vector3 t;
    mi.getTranslation(&t);

    Vector3 s;
    node->getWorldMatrix().getScale(&s);

    t.x *= s.x;
    t.y *= s.y;
    t.z *= s.z;
    
    t = offsetByCenterOfMass(node, t);

    return t;
}
/**
 * Program to multiply two square matrices and compare the computation time of that process for
 * automatic compiler vectorization and openMP parallelization.
 */
int main()
{
	int size = 4000;
	int** a;
	int** b;

	a = new int*[size];
	b = new int*[size];

	for (int i = 0; i < size; i++)
	{
		a[i] = new int[size];
		b[i] = new int[size];
	}

	fill(size, a, b);

	Matrix* A = new Matrix(size, a);
	Matrix* B = new Matrix(size, b);
	Matrix* C = A->multiply(*B);

//	cout << C->getValue(1,1) << endl;

	delete A;
	delete B;
	delete C;

	return 0;
}
void TransformationNode::before(Program& program, Matrix& model, Matrix& view,
        Matrix& projection) {
    // Save the current Matrix.
    mSavedModelMatrix.loadWith(model);
    // Apply transformation.
    model.multiply(*mMatrix, mSavedModelMatrix);
}
Example #14
0
// Pset08-865.
// Implement me!
Image autostitchN(vector<Image> ims, int refIndex, float blurDescriptor, float radiusDescriptor) {
  
  // calculate homographies to reference
  vector<Matrix> Hs = sequenceHs(ims,  blurDescriptor, radiusDescriptor);
  vector<Matrix> Hs_to_ref = stackHomographies(Hs, refIndex);
  vector<float> bbox = bboxN(Hs_to_ref, ims);


  // create blank output image
  int width = ceil(bbox[1]) - floor(bbox[0]);
  int height = ceil(bbox[3]) - floor(bbox[2]);
  Image output(width, height, ims[0].channels());
  Image sum_of_weights(width, height, 1);


  // add translated, morphed images to output
  Matrix translation = translate(bbox);
  for (unsigned int i=0; i < ims.size(); i++) {
    Matrix transform = translation.multiply(Hs_to_ref[i]);
    Image weight = blendingweight(ims[i].width(), ims[i].height());
    applyhomographyBlend(ims[i], weight, output, transform, true);
    // add to running total of sum of weights on output, for normalizing
    applyhomographyBlend(ims[i]*0 + 1.0, weight, sum_of_weights, transform, true);


  }

  // normalize output image by sum of weights
  normalizeByWeights(output, sum_of_weights);

  return output;
}
Example #15
0
// PSet 08 stitch using image weights.
// note there is no weight normalization.
Image stitchLinearBlending(const Image &im1, const Image &im2, const Image &we1, const Image &we2, Matrix H) {
  
  Matrix identity = eye(3);


  // compute bounding box and translation
  
  vector<float> bbox1 = computeTransformedBBox(im1.width(), im1.height(), H);
  vector<float> bbox2 = computeTransformedBBox(im2.width(), im2.height(), identity);

  vector<float> bbox = bboxUnion(bbox1, bbox2);

  Matrix translation = translate(bbox);
  Matrix im1_transform = translation.multiply(H);


  // create blank output image
  int width = ceil(bbox[1]) - floor(bbox[0]);
  int height = ceil(bbox[3]) - floor(bbox[2]);
  Image output(width, height, im1.channels());

  // apply appropriate homographies to input images, put them in output
  
  applyhomographyBlend(im2, we2, output, translation, true);
  applyhomographyBlend(im1, we1, output, im1_transform, true);
  


  return output;
}
// Inliers:  Detected corners are in green, reprojected ones are in red
// Outliers: Detected corners are in yellow, reprojected ones are in blue
vector<Image> visualizeReprojection(const Image &im1, const Image &im2, Matrix  H, vector<Correspondance> & corr, const vector<bool> & ins) {
  // Initialize colors
  vector<float> red(3,0);
  vector<float> green(3,0);
  vector<float> blue(3,0);
  vector<float> yellow(3,0);
  red[0] = 1.0f;
  green[1]= 1.0f;
  blue[2] = 1.0f;
  yellow[0] = 1.0f;
  yellow[1] = 1.0f;

  vector<Point> detectedPts1In;
  vector<Point> projectedPts1In;
  vector<Point> detectedPts1Out;
  vector<Point> projectedPts1Out;

  vector<Point> detectedPts2In;
  vector<Point> projectedPts2In;
  vector<Point> detectedPts2Out;
  vector<Point> projectedPts2Out;

  for (int i = 0 ; i < (int) corr.size(); i++) {
    Point pt1 = corr[i].feature(0).point();
    Point pt2 = corr[i].feature(1).point();
    Matrix P1 = pt1.toHomogenousCoords();
    Matrix P2 = pt2.toHomogenousCoords();
    Matrix P2_proj = H.multiply(P1);
    Matrix P1_proj = H.inverse().multiply(P2);
    Point reproj1 = Point(P1_proj(0,0)/P1_proj(0,2), P1_proj(0,1)/P1_proj(0,2));
    Point reproj2 = Point(P2_proj(0,0)/P2_proj(0,2), P2_proj(0,1)/P2_proj(0,2));
    if (ins[i]) { // Inlier
      detectedPts1In.push_back(pt1);
      projectedPts1In.push_back(reproj1);
      detectedPts2In.push_back(pt2);
      projectedPts2In.push_back(reproj2);
    } else { // Outlier
      detectedPts1Out.push_back(pt1);
      projectedPts1Out.push_back(reproj1);
      detectedPts2Out.push_back(pt2);
      projectedPts2Out.push_back(reproj2);
    }
  }
  vector<Image> output;
  Image vim1(im1);
  Image vim2(im2);
  vim1 = visualizeCorners(im1, detectedPts1In,2, green);
  vim1 = visualizeCorners(vim1, projectedPts1In,1, red);
  vim1 = visualizeCorners(vim1, detectedPts1Out,2, yellow);
  vim1 = visualizeCorners(vim1, projectedPts1Out,1, blue);

  vim2 = visualizeCorners(im2, detectedPts2In,2, green);
  vim2 = visualizeCorners(vim2, projectedPts2In,1, red);
  vim2 = visualizeCorners(vim2, detectedPts2Out,2, yellow);
  vim2 = visualizeCorners(vim2, projectedPts2Out,1, blue);

  output.push_back(vim1);
  output.push_back(vim2);
  return output;
}
bool PassPointList::estimateNonIsometricSimilarityTransform(QTransform* out)
{
	auto num_pass_points = int(size());
	Q_ASSERT(num_pass_points >= 3);
	
	// Create linear equation system and solve using the pseuo inverse
	
	// Derivation: see comment in estimateSimilarityTransformation().
	// Here, the resulting matrices look a bit different because the constraint
	// to have isotropic scaling is omitted:
	//
	// | x  y  1  0  0  0|   |a|   |X|
	// | 0  0  0  x  y  1| * |b| = |Y|
	//                       |c|
	//                       |d|
	//                       |e|
	//                       |f|
	
	Matrix mat(2*num_pass_points, 6);
	Matrix values(2*num_pass_points, 1);
	for (int i = 0; i < num_pass_points; ++i)
	{
		PassPoint* point = &at(i);
		mat.set(2*i, 0, point->src_coords.x());
		mat.set(2*i, 1, point->src_coords.y());
		mat.set(2*i, 2, 1);
		mat.set(2*i, 3, 0);
		mat.set(2*i, 4, 0);
		mat.set(2*i, 5, 0);
		mat.set(2*i+1, 0, 0);
		mat.set(2*i+1, 1, 0);
		mat.set(2*i+1, 2, 0);
		mat.set(2*i+1, 3, point->src_coords.x());
		mat.set(2*i+1, 4, point->src_coords.y());
		mat.set(2*i+1, 5, 1);
		
		values.set(2*i, 0, point->dest_coords.x());
		values.set(2*i+1, 0, point->dest_coords.y());
	}
	
	Matrix transposed;
	mat.transpose(transposed);
	
	Matrix mat_temp, mat_temp2, pseudo_inverse;
	transposed.multiply(mat, mat_temp);
	if (!mat_temp.invert(mat_temp2))
		return false;
	mat_temp2.multiply(transposed, pseudo_inverse);
	
	// Calculate transformation parameters
	Matrix output;
	pseudo_inverse.multiply(values, output);
	
	out->setMatrix(
		output.get(0, 0), output.get(1, 0), 0,
		output.get(3, 0), output.get(4, 0), 0,
		output.get(2, 0), output.get(5, 0), 1);
	return true;
}
Example #18
0
void CADMLine::transform( const Matrix& matrix )
{
    CADPoint3D::transform( matrix );
    for( CADVector& vertex : avertVertexes )
    {
        vertex = matrix.multiply( vertex );
    }
}
//fast exponentiation for fibonacci
Matrix fib(unsigned long long N) {
    
    if (N == 0) {
        return base;        
    }
    if (N == 1) {
        return exp;
    }
    
    Matrix part = fib(N/2);
    Matrix ret = part.multiply(part);
    if (N % 2 == 1) {
        return ret.multiply(exp);            
    }
    return ret;
    
}
Example #20
0
void BlockMatrix::multiply(BlockMatrix & m1, Matrix * m2, double factor)
{
  if( m1.nGlobCols != m2->nGlobRows )
  {
    misc.error("Error: An internal error was happened. Block matrices with a discrepant number of rows and columns cannot be multiplied.", 0);
  }
  if( m1.nBlockRows == 0 || m1.nBlockCols == 0 )
  {
    misc.error("Error: An internal error was happened. Empty block matrices cannot be multiplied.", 0);
  }
  if( m1.nGlobRows == 0 || m1.nGlobCols == 0 || m2->nGlobRows == 0 || m2->nGlobCols == 0)
  {
    misc.error("Error: An internal error was happened. Empty block matrices cannot be multiplied.", 0);
  }
  
  clear();
  
  std::vector<Matrix*> m2Blocks;
  int rowShift = 0;
  for(int m1c = 0; m1c < m1.nBlockCols; m1c++)
  {
    Matrix * m2Block = new Matrix(MATRIX_DEFAULT_DISTRIBUTION, m1.m[0][m1c]->nGlobCols, m2->nGlobCols);
    m2Block->fillWithConstant(0.);
    subMatrix smDest(m2Block);
    subMatrix smSrc(rowShift, 0, m1.m[0][m1c]->nGlobCols, m2->nGlobCols);
    m2Block->add(m2, 1., 1., smDest, smSrc);
    m2Blocks.push_back(m2Block);
    rowShift += m1.m[0][m1c]->nGlobCols;
  }
  
  for(int m1r = 0; m1r < m1.nBlockRows; m1r++)
  {
    std::vector<Matrix*> blockRow;
    Matrix * resultBlock = NULL;
    for(int m1c = 0; m1c < m1.nBlockCols; m1c++)
    {
      Matrix * temp = new Matrix();
      temp->multiply(m1.m[m1r][m1c], 'N', m2Blocks[m1c], 'N', factor);
      if(resultBlock == NULL)
      {
        resultBlock = temp;
      }
      else
      {
        resultBlock->add(temp);
        delete temp;
      }
    }
    blockRow.push_back(resultBlock);
    addBlockRow(blockRow);
  }
  
  for(int m1c = 0; m1c < m1.nBlockCols; m1c++)
  {
    delete m2Blocks[m1c];
  }
  m2Blocks.clear();
}
    Matrix power(int n){
        if(n == 1) return (*this);
        Matrix P;
        P = power(n/2);
        P = P.multiply(P);
        if(n & 1) P = multiply(P);
        return P;
 
    }
Example #22
0
bool SplineFields2D::gradFE (const FiniteElement& fe, Matrix& grad) const
{
  if (!basis) return false;
  if (!surf)  return false;

  // Evaluate the basis functions at the given point
  Go::BasisDerivsSf spline;
#pragma omp critical
  surf->computeBasis(fe.u,fe.v,spline);

  const int uorder = surf->order_u();
  const int vorder = surf->order_v();
  const size_t nen = uorder*vorder;

  Matrix dNdu(nen,2), dNdX;
  for (size_t n = 1; n <= nen; n++)
  {
    dNdu(n,1) = spline.basisDerivs_u[n-1];
    dNdu(n,2) = spline.basisDerivs_v[n-1];
  }

  std::vector<int> ip;
  ASMs2D::scatterInd(surf->numCoefs_u(),surf->numCoefs_v(),
		     uorder,vorder,spline.left_idx,ip);

  // Evaluate the Jacobian inverse
  Matrix Xnod, Jac;
  Vector Xctrl(&(*surf->coefs_begin()),surf->coefs_end()-surf->coefs_begin());
  utl::gather(ip,surf->dimension(),Xctrl,Xnod);
  utl::Jacobian(Jac,dNdX,Xnod,dNdu);

  // Evaluate the gradient of the solution field at the given point
  if (basis != surf)
  {
    // Mixed formulation, the solution uses a different basis than the geometry
    basis->computeBasis(fe.u,fe.v,spline);

    const size_t nbf = basis->order_u()*basis->order_v();
    dNdu.resize(nbf,2);
    for (size_t n = 1; n <= nbf; n++)
    {
      dNdu(n,1) = spline.basisDerivs_u[n-1];
      dNdu(n,2) = spline.basisDerivs_v[n-1];
    }
    dNdX.multiply(dNdu,Jac); // dNdX = dNdu * Jac

    ip.clear();
    ASMs2D::scatterInd(basis->numCoefs_u(),basis->numCoefs_v(),
		       basis->order_u(),basis->order_v(),
		       spline.left_idx,ip);
  }

  utl::gather(ip,nf,values,Xnod);
  grad.multiply(Xnod,dNdX); // grad = Xnod * dNdX

  return true;
}
/**
 *	This function checks the state and data of the Action to decide if it is in
 *	a valid state.
 *	To be in a valid state the Action must satisfy the following:
 *	- Have a name
 *	- Reference an animation that exists in the model
 *	- If the Action is a movement action then the referenced animation must
 *		have an overall translation that is non-zero.
 *
 *	@param	model	The model that owns the action. The action need not be yet
 *					added to the model.
 *
 *	@return			Returns true if the Action is in a valid state.
 */
bool ModelAction::valid( const ::Model & model ) const
{
	if (name_.empty())
	{
		//ERROR_MSG(	"Invalid Action: of model '%s'\n"
		//			"    Action has no name\n",
		//			model.resourceID().c_str());
		return false;
	}

	int animationIndex = model.getAnimation( animation_ );
	if (animationIndex == -1)
	{
		//ERROR_MSG(	"Invalid Action: '%s' of model '%s'\n"
		//			"    Referenced animation '%s' not found\n",
		//			name_.c_str(),
		//			model.resourceID().c_str(),
		//			animation_.c_str());
		return false;
	}

	SmartPointer<ModelAnimation> modelAnimation = model.animations_[animationIndex];
	SmartPointer<Moo::Animation> mooAnimation = modelAnimation->getMooAnim();

	if (isMovement_)
	{
		Moo::ChannelBinder * channelBinder = mooAnimation->itinerantRoot();

		Matrix firstFrameTransform;
		Matrix finalFrameTransform;

		channelBinder->channel()->result( 0, firstFrameTransform );
		channelBinder->channel()->result(	mooAnimation->totalTime(),
											finalFrameTransform );

		finalFrameTransform.invert();
		Matrix animationDisplacement;
		animationDisplacement.multiply(	finalFrameTransform,
										firstFrameTransform );

		if (almostZero(animationDisplacement.applyToOrigin().length()))
		{
			//ERROR_MSG(	"Invalid Action: '%s' of model '%s'\n"
			//			"    Action is marked as 'isMovement' but animation\n"
			//			"    '%s' has no overall translation of itinerant\n"
			//			"    root bone '%s'\n",
			//			name_.c_str(),
			//			model.resourceID().c_str(),
			//			animation_.c_str(),
			//			channelBinder->channel()->identifier().c_str());
			return false;
		}
	}

	return true;
}
void UnitTest::matrixTest(){
    //    TopOpt t(45,30,0.5,3.0,1.5);
    Matrix A (2,3);
    A.set(0, 0, 2);
    A.set(0, 1, 3);
    A.set(0, 2, 4);
    A.set(1, 0, 1);
    
    Matrix B(3,2);
    B.set(0,1,1000);
    B.set(1,0,1);
    B.set(1,1,100);
    B.set(2,1,10);
    
    A.print();
    B.print();
    printf("\n");
    Matrix C = A.multiply(B);
    
    C.print();
    printf("\n");
    Matrix D(2,2);
    D.set(0,0,2);
    D.set(1,0,9);
    D.set(0,1,95);
    D.set(1,1,985);
    tfloat vector[] = {8,2};
    printf("vTMv %f\n",D.vTransposeMultMMultV(vector));
    assertEqualFloat(5732,D.vTransposeMultMMultV(vector));
    
    Matrix AA(3,3);
    AA.set(0, 0, 2);
    AA.set(1, 0,-1);
    AA.set(2, 0, 0);
    AA.set(0, 1,-1);
    AA.set(1, 1, 2);
    AA.set(2, 1,-1);
    AA.set(0, 2, 0);
    AA.set(1, 2,-1);
    AA.set(2, 2, 1);
    
    tfloat b[] = {0,0,1};
    tfloat x[] = {0,0,0};
    bool res = AA.solve(b, x);
    assert(res);
    
    assertEqualFloat(x[0], 1);
    assertEqualFloat(x[1], 2);
    assertEqualFloat(x[2], 3);
    tfloat bExpectedValue[] = {0,0,1};
    for (int i=0;i<3;i++){
        assertEqualFloat(b[i], bExpectedValue[i]);
    }
    
    x[0] = x[1] = x[2] = 0;
}
Example #25
0
float* Matrix::leastSquares(Matrix* a, Matrix* b) {
    Matrix* at = a->transpose();
    Matrix* a2 = at->multiply(a);
    Matrix* b2 = at->multiply(b);
    float* x = solve(a2, b2);
    delete at;
    delete a2;
    delete b2;
    return x;
}
Example #26
0
bool PoroElasticity::evalCouplingMatrix (Matrix& mx, const Matrix& B,
                                         const Vector& N, double scale) const
{
  Matrix K(N.size(), nsd * (nsd + 1) / 2);
  for (size_t i = 1; i <= N.size(); i++)
    for (size_t j = 1; j <= nsd; j++)
      K(i,j) = scale * N(i);

  return !mx.multiply(B,K,true,true,true).empty();
}
Example #27
0
bool BulletSmash::update( ) {
	_exist_time++;
	if ( _exist_time < WAIT_TIME  ) {
		return true;
	}
	Matrix mat = Matrix::makeTransformRotation( Vector( 0, 0, 1 ), PI2 / PARTICLE );
	Vector radius_dir = Vector( 0, 1, 0 );
	attackEnemy( _pos, _power );
	for ( int i = 0; i < PARTICLE; i++ ) {
		radius_dir = mat.multiply( radius_dir );
		for ( int j = 1; j < RADIUS + 1; j++ ) {
			Vector pos = _pos + radius_dir * j;
			attackPlayer( pos, _power );
		}
	}
	return false;
}
Example #28
0
void BlockMatrix::multiply(BlockMatrix & m1, BlockMatrix & m2, double factor)
{
  if( m1.nBlockCols != m2.nBlockRows )
  {
    misc.error("Error: An internal error was happened. Block matrices with a discrepant number of block rows and block columns cannot be multiplied.", 0);
  }
  if( m1.nGlobCols != m2.nGlobRows )
  {
    misc.error("Error: An internal error was happened. Block matrices with a discrepant number of rows and columns cannot be multiplied.", 0);
  }
  if( m1.nBlockRows == 0 || m1.nBlockCols == 0 || m2.nBlockRows == 0 || m2.nBlockCols == 0)
  {
    misc.error("Error: An internal error was happened. Empty block matrices cannot be multiplied.", 0);
  }
  if( m1.nGlobRows == 0 || m1.nGlobCols == 0 || m2.nGlobRows == 0 || m2.nGlobCols == 0)
  {
    misc.error("Error: An internal error was happened. Empty block matrices cannot be multiplied.", 0);
  }
  
  clear();
  
  for(int m1r = 0; m1r < m1.nBlockRows; m1r++)
  {
    std::vector<Matrix*> blockRow;
    for(int m2c = 0; m2c < m2.nBlockCols; m2c++)
    {
      Matrix * resultBlock = NULL;
      for(int m1c = 0; m1c < m1.nBlockCols; m1c++)
      {
        Matrix * temp = new Matrix();
        temp->multiply(m1.m[m1r][m1c], 'N', m2.m[m1c][m2c], 'N', factor);
        if(resultBlock == NULL)
        {
          resultBlock = temp;
        }
        else
        {
          resultBlock->add(temp);
          delete temp;
        }
      }
      blockRow.push_back(resultBlock);
    }
    addBlockRow(blockRow);
  }
}
Example #29
0
Quaternion PhysicsConstraint::getRotationOffset(const Node* node, const Vector3& point)
{
    // Create a translation matrix that translates to the given origin.
    Matrix m;
    Matrix::createTranslation(point, &m);

    // Calculate the rotation offset to the rigid body by transforming 
    // the translation matrix above into the rigid body's local space 
    // (multiply by the inverse world matrix) and extracting the rotation.
    Matrix mi;
    node->getWorldMatrix().invert(&mi);
    mi.multiply(m);
    
    Quaternion r;
    mi.getRotation(&r);

    return r;
}
Example #30
0
/**
*    multiply
*
*    Preconditions:
*        
*    Postconditions:
*
*/
Vector* Vector::multiply( Matrix* mtrx )
{
    Vector* vrt = new Vector( 0, 0, 0 );
    
    Matrix* inv = mtrx->inverse();
    Matrix* trans = inv->transpose();
    delete inv;
    
    Matrix* tmp = trans->multiply( vector );
    delete trans;
    
    vrt->setX( tmp->getElement(1, 1) );
    vrt->setY( tmp->getElement(2, 1) );
    vrt->setZ( tmp->getElement(3, 1) );

    delete tmp;
    return vrt;
}