private void getPlanes(Canguro.View.GraphicView activeView, int fx1, int fy1, int fx2, int fy2,
out Vector3 nAB, out Vector3 sAB, out Vector3 nBC, out Vector3 sBC,
out Vector3 nCD, out Vector3 sCD, out Vector3 nDA, out Vector3 sDA,
ref Vector3[] corners1, ref Vector3[] corners2)
{
// First calculate the 8 points (2 for each corner)
Vector3 a1 = new Vector3(fx1, fy1, 0.5f);
Vector3 a2 = new Vector3(fx1, fy1, 1);
Vector3 b1 = new Vector3(fx2, fy1, 0.5f);
Vector3 b2 = new Vector3(fx2, fy1, 1);
Vector3 c1 = new Vector3(fx2, fy2, 0.5f);
Vector3 c2 = new Vector3(fx2, fy2, 1);
Vector3 d1 = new Vector3(fx1, fy2, 0.5f);
Vector3 d2 = new Vector3(fx1, fy2, 1);
activeView.Unproject(ref a1);
activeView.Unproject(ref a2);
activeView.Unproject(ref b1);
activeView.Unproject(ref b2);
activeView.Unproject(ref c1);
activeView.Unproject(ref c2);
activeView.Unproject(ref d1);
activeView.Unproject(ref d2);
if (corners1 != null && corners2 != null && corners1.Length == 4 && corners2.Length == 4)
{
corners1[0] = a1;
corners1[1] = b1;
corners1[2] = c1;
corners1[3] = d1;
corners2[0] = a2;
corners2[1] = b2;
corners2[2] = c2;
corners2[3] = d2;
}
// Now calculate the normals
// If points P and Q are consecutive and in CCW order, then
// normal = (q2 - p1) x (q1 - p1)
nAB = Vector3.Normalize(Vector3.Cross((b2 - a1), (b1 - a1)));
nBC = Vector3.Normalize(Vector3.Cross((c2 - b1), (c1 - b1)));
nCD = Vector3.Normalize(Vector3.Cross((d2 - c1), (d1 - c1)));
nDA = Vector3.Normalize(Vector3.Cross((a2 - d1), (a1 - d1)));
// Now assign the points on the planes.
// Points calculated at the corners are used here
sAB = a1;
sBC = c1;
sCD = c1;
sDA = a1;
}