Example #1
0
		private Vector3 GetMinDistance(
			ref List<SupportTriangle> triangles,
			Vector3 point,
			ref int minTriangleIndex)
		{
			var result = new Vector3();
			var distanceBuf = new Vector3();
			double s = 0; double t = 0;

			var buffer = new SupportTriangle();

			double minDistance = double.MaxValue;

			for (int i = 0; i < triangles.Count; i++)
			{
				buffer = triangles[i];

				if (!GeometryUtilities.TestCollinearity(
						buffer.a.s,
						buffer.b.s,
						buffer.c.s))
				{
					distanceBuf = GeometryUtilities.GetPointTriangleIntersection(
						buffer.a.s,
						buffer.b.s,
						buffer.c.s,
						point,
						ref s,
						ref t).Value;

					buffer.SetValueS(s);
					buffer.SetValueT(t);
				}
				else
				{
					continue;
				}

				triangles[i] = buffer;

				double distance = Vector3.Length(distanceBuf);

				if (distance < minDistance)
				{
					minDistance = distance;
					minTriangleIndex = i;
					result = distanceBuf;
				}
			}

			return result;
		}
Example #2
0
		private void GetEpaVertexFromMinkowsky(
			SupportTriangle triangle,
			SimulationObject shape1,
			SimulationObject shape2,
			ref EngineCollisionPoint epaCollisionPoint)
		{
			Vector3 a1 = Helper.GetVertexPosition(shape1, triangle.a.a);
			Vector3 ba1 = Helper.GetVertexPosition(shape1, triangle.b.a) - a1;
			Vector3 ca1 = Helper.GetVertexPosition(shape1, triangle.c.a) - a1;

			Vector3 a2 = Helper.GetVertexPosition(shape2, triangle.a.b);
			Vector3 ba2 = Helper.GetVertexPosition(shape2, triangle.b.b) - a2;
			Vector3 ca2 = Helper.GetVertexPosition(shape2, triangle.c.b) - a2;

			epaCollisionPoint.SetA (a1 + (ba1 * triangle.s) + (ca1 * triangle.t));
			epaCollisionPoint.SetB (a2 + (ba2 * triangle.s) + (ca2 * triangle.t));
		}