当前位置: 首页>>代码示例>>C++>>正文


C++ Vector3::ZeroOut方法代码示例

本文整理汇总了C++中math::Vector3::ZeroOut方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3::ZeroOut方法的具体用法?C++ Vector3::ZeroOut怎么用?C++ Vector3::ZeroOut使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math::Vector3的用法示例。


在下文中一共展示了Vector3::ZeroOut方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: UpdateMassAndLocalCentroid

void PolyhedronColliderGeometry::UpdateMassAndLocalCentroid(const ResolutionMaterial &material, float &mass, Math::Matrix3 &unitInertiaTensor, Math::Vector3 &localCentroid)
{
	auto &verts = mAdjacency.Verts();
	auto &edges = mAdjacency.Edges();
	auto &faces = mAdjacency.Faces();
	const Math::Vector3 &c = mAdjacency.Centroid();

	mass = 0.0f;
	unitInertiaTensor.ZeroOut();
	localCentroid.ZeroOut();

	float totalVolume = 0.0f;
	for (auto &face : faces)
	{
		if (!face.active)
			continue;

		// grab face verts
		int e = face.edge;
		const Math::Vector3 &v0 = verts[edges[e].vert].position;
		e = edges[e].next;
		const Math::Vector3 &v1 = verts[edges[e].vert].position;
		e = edges[e].next;
		const Math::Vector3 &v2 = verts[edges[e].vert].position;

		// volume of tetrahedron formed by face & centroid (not divided by 6)
		const float tetrahedronVolume = std::fabs((v0 - c).Dot((v1 - c).Cross(v2 - c)));

		// accumulate volume
		totalVolume += tetrahedronVolume;

		// accumulate weighted centroid
		const Math::Vector3 tetrahedronCentroid = 0.25f * (c + v0 + v1 + v2);
		localCentroid += tetrahedronVolume * tetrahedronCentroid;
	}
	if (totalVolume == 0)
		totalVolume = 1;
	localCentroid /= totalVolume;
	
	//mass = material.mDensity * totalVolume / 6.0f;
	mass = mParent->Parent().mParent->cphy->mMass * totalVolume / 6.0f;
	

	// compute inertia tensor
	for (auto &face : faces)
	{
		if (!face.active)
			continue;

		// grab face verts
		int e = face.edge;
		const Math::Vector3 &v0 = verts[edges[e].vert].position;
		e = edges[e].next;
		const Math::Vector3 &v1 = verts[edges[e].vert].position;
		e = edges[e].next;
		const Math::Vector3 &v2 = verts[edges[e].vert].position;

		// accumulate inertia tensor
		unitInertiaTensor += UnitInertiaTensorTetrahedron(c, v0, v1, v2, localCentroid);
	}
}
开发者ID:Reticulatas,项目名称:MochaEngineFinal,代码行数:61,代码来源:PolyheShape.cpp


注:本文中的math::Vector3::ZeroOut方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。