osg解析系列-osg中Geode的Matrix 转换成IFC的TRS矩阵 源码

// Geode的Matrix 转换成IFC的TRS矩阵
bool DHWriteIfcObjectTrangle::ChangeGeoMatrixToIfcCTRS(osg::Matrixd mat, shared_ptr<IfcCartesianTransformationOperator3D> & pIfcCTRS)
{
	if (!pIfcCTRS) {return false;}
	if (mat.isIdentity())
	{
		pIfcCTRS.reset();
		return true;
	}

	const osg::Vec3d & vScale = mat.getScale();
	pIfcCTRS->m_Scale = shared_ptr<IfcReal>(new IfcReal(vScale.x()));

	double* matData = mat.ptr();

	shared_ptr<IfcCartesianPoint> pGeodeTrans(new IfcCartesianPoint(getIndexCount()));
	InsertObject(pGeodeTrans);
	{
		const osg::Vec3d& vTrans = mat.getTrans();

		shared_ptr<IfcLengthMeasure> pIfcLengthMeasure1(new IfcLengthMeasure(vTrans.x()));
		pGeodeTrans->m_Coordinates.push_back(pIfcLengthMeasure1);
		shared_ptr<IfcLengthMeasure> pIfcLengthMeasure2(new IfcLengthMeasure(vTrans.y()));
		pGeodeTrans->m_Coordinates.push_back(pIfcLengthMeasure2);
		shared_ptr<IfcLengthMeasure> pIfcLengthMeasure3(new IfcLengthMeasure(vTrans.z()));
		pGeodeTrans->m_Coordinates.push_back(pIfcLengthMeasure3);
	}
	pIfcCTRS->m_LocalOrigin = pGeodeTrans;

	shared_ptr<IfcDirection> pAxis1(new IfcDirection(getIndexCount()));
	InsertObject(pAxis1);
	{
		shared_ptr<IfcReal> Axisx(new IfcReal(matData[0 + 0* 4]/ vScale.x()));
		shared_ptr<IfcReal> Axisy(new IfcReal(matData[1 + 0* 4] / vScale.x()));
		shared_ptr<IfcReal> Axisz(new IfcReal(matData[2 + 0* 4] / vScale.x()));
		pAxis1->m_DirectionRatios.push_back(Axisx);
		pAxis1->m_DirectionRatios.push_back(Axisy);
		pAxis1->m_DirectionRatios.push_back(Axisz);
	}
	pIfcCTRS->m_Axis1 = pAxis1;

	shared_ptr<IfcDirection> pAxis2(new IfcDirection(getIndexCount()));
	InsertObject(pAxis2);
	{
		shared_ptr<IfcReal> Axisx(new IfcReal(matData[0 + 1* 4] / vScale.y()));
		shared_ptr<IfcReal> Axisy(new IfcReal(matData[1 + 1* 4] / vScale.y()));
		shared_ptr<IfcReal> Axisz(new IfcReal(matData[2 + 1* 4] / vScale.y()));
		pAxis2->m_DirectionRatios.push_back(Axisx);
		pAxis2->m_DirectionRatios.push_back(Axisy);
		pAxis2->m_DirectionRatios.push_back(Axisz);
	}

	shared_ptr<IfcDirection> pAxis3(new IfcDirection(getIndexCount()));
	InsertObject(pAxis3);
	{
		shared_ptr<IfcReal> Axisx(new IfcReal(matData[0 + 2* 4] / vScale.z()));
		shared_ptr<IfcReal> Axisy(new IfcReal(matData[1 + 2* 4] / vScale.z()));
		shared_ptr<IfcReal> Axisz(new IfcReal(matData[2 + 2* 4] / vScale.z()));
		pAxis3->m_DirectionRatios.push_back(Axisx);
		pAxis3->m_DirectionRatios.push_back(Axisy);
		pAxis3->m_DirectionRatios.push_back(Axisz);
	}

	pIfcCTRS->m_Axis2 = pAxis2;
	pIfcCTRS->m_Axis3 = pAxis3;

	return true;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值