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


C++ Polyhedron::Centroid方法代码示例

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


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

示例1: PolyhedronIntersectsAABB_OBB

bool PolyhedronIntersectsAABB_OBB(const Polyhedron &p, const T &obj)
{
	if (p.Contains(obj.CenterPoint()))
		return true;
	if (obj.Contains(p.Centroid()))
		return true;

	// Test for each edge of the AABB/OBB whether this polyhedron intersects it.
	for(int i = 0; i < obj.NumEdges(); ++i)
		if (p.Intersects(obj.Edge(i)))
			return true;

	// Test for each edge of this polyhedron whether the AABB/OBB intersects it.
	for(size_t i = 0; i < p.f.size(); ++i)
	{
		assert(!p.f[i].v.empty()); // Cannot have degenerate faces here, and for performance reasons, don't start checking for this condition in release mode!
		int v0 = p.f[i].v.back();
		float3 l0 = p.v[v0];
		for(size_t j = 0; j < p.f[i].v.size(); ++j)
		{
			int v1 = p.f[i].v[j];
			float3 l1 = p.v[v1];
			if (v0 < v1 && obj.Intersects(LineSegment(l0, l1))) // If v0 < v1, then this line segment is the canonical one.
				return true;
			l0 = l1;
			v0 = v1;
		}
	}

	return false;
}
开发者ID:360degrees-fi,项目名称:tundra,代码行数:31,代码来源:Polyhedron.cpp

示例2: Intersects

/** The algorithm for Polyhedron-Polyhedron intersection is from Christer Ericson's Real-Time Collision Detection, p. 384.
	As noted by the author, the algorithm is very naive (and here unoptimized), and better methods exist. [groupSyntax] */
bool Polyhedron::Intersects(const Polyhedron &polyhedron) const
{
	if (polyhedron.Contains(this->Centroid()))
		return true;
	if (this->Contains(polyhedron.Centroid()))
		return true;

	// This test assumes that both this and the other polyhedron are closed.
	// This means that for each edge running through vertices i and j, there's a face
	// that contains the line segment (i,j) and another neighboring face that contains
	// the line segment (j,i). These represent the same line segment (but in opposite direction)
	// so we only have to test one of them for intersection. Take i < j as the canonical choice
	// and skip the other winding order.

	// Test for each edge of this polyhedron whether the other polyhedron intersects it.
	for(size_t i = 0; i < f.size(); ++i)
	{
		assert(!f[i].v.empty()); // Cannot have degenerate faces here, and for performance reasons, don't start checking for this condition in release mode!
		int v0 = f[i].v.back();
		float3 l0 = v[v0];
		for(size_t j = 0; j < f[i].v.size(); ++j)
		{
			int v1 = f[i].v[j];
			float3 l1 = v[v1];
			if (v0 < v1 && polyhedron.Intersects(LineSegment(l0, l1))) // If v0 < v1, then this line segment is the canonical one.
				return true;
			l0 = l1;
			v0 = v1;
		}
	}

	// Test for each edge of the other polyhedron whether this polyhedron intersects it.
	for(size_t i = 0; i < polyhedron.f.size(); ++i)
	{
		assert(!polyhedron.f[i].v.empty()); // Cannot have degenerate faces here, and for performance reasons, don't start checking for this condition in release mode!
		int v0 = polyhedron.f[i].v.back();
		float3 l0 = polyhedron.v[v0];
		for(size_t j = 0; j < polyhedron.f[i].v.size(); ++j)
		{
			int v1 = polyhedron.f[i].v[j];
			float3 l1 = polyhedron.v[v1];
			if (v0 < v1 && Intersects(LineSegment(l0, l1))) // If v0 < v1, then this line segment is the canonical one.
				return true;
			l0 = l1;
			v0 = v1;
		}
	}

	return false;
}
开发者ID:360degrees-fi,项目名称:tundra,代码行数:52,代码来源:Polyhedron.cpp


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