示例#1
0
			Matrix Matrix::Product(const double & b) const{
				Matrix a = *this;
				for(int i = 0 ; i < 3 ; i++)
					for(int j = 0 ; j < 3 ; j++)
						a.Element(i,j,a.Element(i,j)*b);
				return a;
			}
示例#2
0
			Matrix Matrix::Div(const double & b) const{
				if(b == 0)
					throw(Error(1,"Dividing by 0 !",0));
				Matrix a = *this;
				for(int i = 0 ; i < 3 ; i++)
					for(int j = 0 ; j < 3 ; j++)
						a.Element(i,j,a.Element(i,j)/b);
				return a;
			}
示例#3
0
Matrix Matrix::TranslationMatrix()
{
	Matrix result = Identity();

	// copy last column into result
	for (int i = 0; i < 3; i++)
		result.Element(i,3) = Element(i,3);
	return result;
}
示例#4
0
			Matrix Matrix::MatrixAdjoint()const {
				Matrix a;
				a.Element(0,0,(element[1][1]*element[2][2]-element[1][2]*element[2][1]));
				a.Element(0,1,-(element[1][0]*element[2][2]-element[1][2]*element[2][0]));
				a.Element(0,2,(element[1][0]*element[2][1]-element[1][1]*element[2][0]));

				a.Element(1,0,-(element[0][1]*element[2][2]-element[0][2]*element[2][1]));
				a.Element(1,1,(element[0][0]*element[2][2]-element[0][2]*element[2][0]));
				a.Element(1,2,-(element[0][0]*element[2][1]-element[0][1]*element[2][0]));

				a.Element(2,0,(element[0][1]*element[1][2]-element[0][2]*element[1][1]));
				a.Element(2,1,-(element[0][0]*element[1][2]-element[0][2]*element[1][0]));
				a.Element(2,2,(element[0][0]*element[1][1]-element[1][0]*element[0][1]));
				return a;
			}
示例#5
0
// routine to extract the rotation part of the matrix
// assumes no entries in perspective section of matrix
Matrix Matrix::RotationMatrix()
{
	Matrix result = Identity();

	// copy first three elements of first three columns into result
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			result.Element(i,j) = Element(i,j);
	return result;
}
示例#6
0
// multiply by another matrix
Matrix Matrix::operator* (Matrix otherMatrix)
{
	// make a temporary copy of the other
	Matrix result;

	// now do the standard loops: it's inefficient, but works
	for (int row = 0; row < 4; row++)
	{
		for(int col = 0; col < 4; col++)
		{
			result.Element(row, col) = 0.0;
			for (int entry = 0; entry < 4; entry++)
			{
				result.Element(row, col) += Element(row, entry) *
					otherMatrix.Element(entry, col);
			}
		}
	}
	return result;
}
示例#7
0
/// Re-arranges internal elements based on pre-configured or newly set options. Does not create or delete anything.
void UIMatrix::FormatContents()
{
	float labelHeightY = 0.0f;
//	if (label)
//		labelHeightY = label->sizeRatioY;
	float elementWidth = 1.0f / columns;
	float elementHeight = (1.0f - labelHeightY) / rows;

	Matrix<UIElement*> layoutMatrix; // Going downward in Y for each step.
	layoutMatrix.SetDefaultValue(NULL);
	layoutMatrix.SetSize(Vector2i(columns, rows));

	/// Create 'em.
	int formattedElements = 0;
	for (int y = 0; y < rows; ++y)
	{
		for (int x = 0; x < columns; ++x)
		{
			UIElement * element = matrixElements[formattedElements];
			layoutMatrix.Set(Vector2i(x, y), element);
			// Remove it first, if already there.
			RemoveChild(element);

			/// Give new alignments and size-ratios based on the matrix cell size.
			element->alignmentX = (x+0.5f) * elementWidth;
			element->alignmentY = 1.0f - (y + 0.5f) * elementHeight - labelHeightY;
			element->sizeRatioX = elementWidth;
			element->sizeRatioY = elementHeight;
			/// And add it!
			AddChild(element);
			// Make sure that the element is re-built next frame?
			++formattedElements;
			if (formattedElements >= matrixElements.Size())
				goto initialFormattingDone;
		}
	}
initialFormattingDone:
	/// After filling the matrix, set neighbour-elements accordingly.
	for (int i = 0; i < layoutMatrix.Elements(); ++i)
	{
		UIElement * element = layoutMatrix.Element(i);
		if (!element)
			continue;
		Vector2i matrixPos = layoutMatrix.GetLocationOf(element);
		/// Fetch right-left first.
		Vector2i leftPos = matrixPos + Vector2i(-1,0);
		if (layoutMatrix.ValidPosition(leftPos))
		{
			UIElement * left = layoutMatrix.GetItem(leftPos);
			if (left)
			{
				element->leftNeighbourName = left->name;
				left->rightNeighbourName = element->name;
			}
		}
		// Bottom-top neighbours
		Vector2i bottomPos = matrixPos + Vector2i(0, 1);
		if (layoutMatrix.ValidPosition(bottomPos))
		{
			UIElement * bottom = layoutMatrix.GetItem(bottomPos);
			if (bottom)
			{
				element->downNeighbourName = bottom->name;
				bottom->upNeighbourName = element->name;
			}
		}
	}

	;
}