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


C++ ConvexHull::getVertexCount方法代码示例

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


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

示例1:

	void Light2D::findEdges(LightProperties light, ConvexHull object, int *index0, int *index1)
	{
		float m1, n1, m2, n2, cx;
		float x1 = light.position.x, y1 = light.position.y;
		int nextIndex, index, prevIndex;
		int nV = object.getVertexCount();
		Vector2 p1, p2, p3, p4;

		Vector2 edges[2];
		int curEdge = 0;
		float al;

		bool u = 0;

		int in[2];

		bool isBackFacing[CONVEX_HULL_MAX_VERTEX_COUNT];

		for(int i = 0; i < CONVEX_HULL_MAX_VERTEX_COUNT; ++i) isBackFacing[i] = 0;

		//int backFacingCount = 0;

		for(int i = 0; i < nV + 1; ++i)
		{
			Vector2 firstVertex = Vector2(object.getVertex(i).x, object.getVertex(i).y);
			int secondIndex = (i + 1) % nV;
			Vector2 secondVertex = Vector2(object.getVertex(secondIndex).x, object.getVertex(secondIndex).y);
			Vector2 middle = (firstVertex + secondVertex) / 2;

			Vector2 L = light.position - middle;

			Vector2 N;
			N.x = firstVertex.y - secondVertex.y;
			N.y = secondVertex.x - firstVertex.x;

			isBackFacing[i] = (N.dotProduct(L) > 0);
			//backFacingCount += isBackFacing[i];
		}

		//if(backFacingCount == nV) return 0;

		int startingIndex = 0;
		int endingIndex = 0;

		for (int i = 0; i < nV; i++)
		{
			//graphics.fillEllipse(object.getVertex(i).x, object.getVertex(i).y, 5, 5, 0, 2 * pi, COLOR_RGB(255, 255, 255), - 5);

			int currentIndex = i % nV;
			int nextEdge = (i + 1) % nV;

			/*if(isBackFacing[i])
			{
				graphics.fillEllipse(object.getVertex(i).x, object.getVertex(i).y, 20, 20, 0, 2 * pi, COLOR_RGB(255, 255, i * (255 / nV) ), - 10);
			}*/

			if (isBackFacing[currentIndex] && !isBackFacing[nextEdge])
			{
				endingIndex = nextEdge;

				//break;
			}

			if (!isBackFacing[currentIndex] && isBackFacing[nextEdge])
			{
				startingIndex = nextEdge;
			}
		}

		//*i1 = edges[0];
		//*i2 = object.getVertex(1);

		*index0 = startingIndex;
		*index1 = endingIndex;

		/*Vector2 i1 = object.getVertex(startingIndex);
		Vector2 i2 = object.getVertex(endingIndex);

		graphics.fillEllipse(i1.x, i1.y, 10, 10, 0, 2 * pi, COLOR_RGB(255, 0, 0), - 10);
		graphics.fillEllipse(i2.x, i2.y, 20, 20, 0, 2 * pi, COLOR_RGB(0, 255, 0), - 10);*/

		//console.print("StartingIndex : " + INT_TO_STRING(startingIndex) + ", EndingIndex : " + INT_TO_STRING(endingIndex));
	}
开发者ID:0xTHR34T,项目名称:EagleEngine,代码行数:83,代码来源:Light.cpp


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