void MatrixDisplayDlg::fillDialogWith(const ccGLMatrix& mat)
{
	m_mat = ccGLMatrixd(mat.data());

	int precision = ccGui::Parameters().displayedNumPrecision;

	//display as 4x4 matrix
	maxTextEdit->setText(mat.toString(precision));

	//display as rotation vector/angle
	{
		PointCoordinateType angle_rad;
		CCVector3 axis3D, t3D;
		mat.getParameters(angle_rad, axis3D, t3D);

		fillDialogWith(CCVector3d::fromArray(axis3D.u),angle_rad,CCVector3d::fromArray(t3D.u),precision);
	}
}
Beispiel #2
0
void CleanMatrix(ccGLMatrixd& mat)
{
	//make the transform a little bit cleaner (necessary as it's read from ASCII!)
	{
//#ifdef QT_DEBUG
//		//test the matrix quality
//		ccGLMatrixd before = mat;
//		CCVector3d X0(before.getColumn(0));
//		CCVector3d Y0(before.getColumn(1));
//		CCVector3d Z0(before.getColumn(2));
//		double normX0 = X0.norm();
//		double normY0 = Y0.norm();
//		double normZ0 = Z0.norm();
//#endif
		CCVector3d X(mat.getColumn(0));
		CCVector3d Y(mat.getColumn(1));
		CCVector3d Z(mat.getColumn(2));
		CCVector3d T = mat.getTranslationAsVec3D();
		Z = X.cross(Y);
		Y = Z.cross(X);
		X.normalize();
		Y.normalize();
		Z.normalize();
		mat = ccGLMatrixd(X,Y,Z,T);
//#ifdef QT_DEBUG
//		double dot = CCVector3d(X).dot(X0);
//		dot /= (normX0 * CCVector3d(X).norm());
//		double alpha = acos(dot);
//
//		dot = CCVector3d(Y).dot(Y0);
//		dot /= (normY0 * CCVector3d(Y).norm());
//		double beta = acos(dot);
//
//		dot = CCVector3d(Z).dot(Z0);
//		dot /= (normZ0 * CCVector3d(Z).norm());
//		double gamma = acos(dot);
//#endif
	}
}
bool ccViewportParameters::fromFile(QFile& in, short dataVersion, int flags)
{
	//base modelview matrix (dataVersion>=20)
	if (dataVersion >= 36) //we now save the camera matrix in double precision
	{
		if (!viewMat.fromFile(in, dataVersion, flags))
			return false;
	}
	else
	{
		//camera matrix was saved in standard (float) precision
		ccGLMatrix _viewMat;
		if (!_viewMat.fromFile(in, dataVersion, flags))
			return false;
		viewMat = ccGLMatrixd(_viewMat.data());
	}

	//other parameters (dataVersion>=20)
	QDataStream inStream(&in);
	inStream >> pixelSize;
	//before version 25, we were saving the inverse of 'pixelSize' ('globalZoom')
	if (dataVersion < 25)
		pixelSize = (pixelSize> ZERO_TOLERANCE ? 1.0f/pixelSize : 1.0f);
    inStream >> zoom;
    inStream >> defaultPointSize;
    inStream >> defaultLineWidth;
	inStream >> perspectiveView;
	inStream >> objectCenteredView;
	if (dataVersion >= 36) //we now save the camera center and pivot point in double precision
	{
		inStream >> pivotPoint.x;
		inStream >> pivotPoint.y;
		inStream >> pivotPoint.z;
		inStream >> cameraCenter.x;
		inStream >> cameraCenter.y;
		inStream >> cameraCenter.z;
	}