inline Vertex *Polyline::vertex(size_t v) {
   if (closed) {
     v %= edgeCount();
   } else if (v >= edgeCount()) {
     return v == edgeCount() ? edges.back()->v2 : NULL;
   }
   return edges[v]->v1;
 }
 inline size_t Polyline::vertexCount() const {
   return edgeCount() + (closed ? 0 : 1);
 }
 inline polyline_edge_const_iter Polyline::eend() const { 
   return polyline_edge_const_iter(this, edgeCount());
 }
Exemple #4
0
 inline polyline_edge_iter Polyline::eend() { 
   return polyline_edge_iter(this, (ssize_t)edgeCount());
 }
void NxAbstractMeshDescription::UpdateDerivedInformation(NxApexRenderDebug* renderDebug)
{
	if (numIndices > 0)
	{
		pMin = pPosition[pIndices[0]];
		pMax = pMin;
	}
	avgEdgeLength = 0;
	avgTriangleArea = 0;

	PxU32 triCount(numIndices / 3);
	PxU32 edgeCount(numIndices);
	for (PxU32 j = 0; j < numIndices; j += 3)
	{
		PxU32 i0 = pIndices[j + 0];
		PxU32 i1 = pIndices[j + 1];
		PxU32 i2 = pIndices[j + 2];

		const PxVec3& v0 = pPosition[i0];
		const PxVec3& v1 = pPosition[i1];
		const PxVec3& v2 = pPosition[i2];

		pMin.minimum(v0);
		pMin.minimum(v1);
		pMin.minimum(v2);

		pMax.maximum(v0);
		pMax.maximum(v1);
		pMax.maximum(v2);

		PxVec3 e0 = v1 - v0;
		PxVec3 e1 = v2 - v1;
		PxVec3 e2 = v0 - v2;

		avgEdgeLength += e0.magnitude();
		avgEdgeLength += e1.magnitude();
		avgEdgeLength += e2.magnitude();


		if (renderDebug)
		{
			renderDebug->setCurrentColor(renderDebug->getDebugColor(physx::DebugColors::DarkBlue));
			renderDebug->debugLine(v0, v1);
			renderDebug->debugLine(v1, v2);
			renderDebug->debugLine(v2, v0);
			renderDebug->setCurrentColor(renderDebug->getDebugColor(physx::DebugColors::Green));
			renderDebug->debugPoint(v0, 0.1f);
			renderDebug->debugPoint(v1, 0.1f);
			renderDebug->debugPoint(v2, 0.1f);
		}

		PxF32 triangleArea = e0.cross(e2).magnitude() * 0.5f;
		avgTriangleArea += triangleArea;
		triCount++;
	}

	avgEdgeLength /= edgeCount;
	avgTriangleArea /= triCount;
	centroid = 0.5f * (pMin + pMax);
	radius = 0.5f * (pMax - pMin).magnitude();

	//printf("Min = <%f, %f, %f>; Max = <%f, %f, %f>; centroid = <%f, %f, %f>; radius = %f; avgEdgeLength = %f; avgTriangleArea = %f;\n",
	//	pMin.x, pMin.y, pMin.z, pMax.x, pMax.y, pMax.z, centroid.x, centroid.y, centroid.z, radius, avgEdgeLength, avgTriangleArea);
}