private void windVertices() { Vector3 n = plane.getNormal(); //find the center of the polygon by taking the average of the vertices Vector3 cent = getCenter(); //selection sort these guys using the cosVal function for (int i = 0; i < vertices.Count - 1; i++) { int minVert = i + 1; double minCosVal = cosVal(cent, n, vertices[i].position, vertices[i + 1].position); for (int j = i + 2; j < vertices.Count; j++) { double cv = cosVal(cent, n, vertices[i].position, vertices[j].position); if (cv < minCosVal) { minVert = j; minCosVal = cv; } } Vertex v = vertices[minVert]; vertices.RemoveAt(minVert); vertices.Insert(i + 1, v); } //calculate the normal of this face and if it doesn't match up with the plane, reverse the winding //this inequailty and the inequality in the cosVal function seem linked somehow if (Vector3.Dot(Vector3.Cross(vertices[0].position - cent, vertices[1].position - cent), n) > 0) { vertices.Reverse(); } }
public Vertex getIntersection(Plane p1, Plane p2, Plane p3) { return getIntersection(p1.getNormal(), p2.getNormal(), p3.getNormal(), (float)(p1.getD()), (float)(p2.getD()), (float)(p3.getD())); }
public Vertex getIntersection(Plane p1, Plane p2, Plane p3) { return(getIntersection(p1.getNormal(), p2.getNormal(), p3.getNormal(), (float)(p1.getD()), (float)(p2.getD()), (float)(p3.getD()))); }