Canguro.Commands.View.Selection.getPlanes C# (CSharp) Méthode

getPlanes() private méthode

Method to return the four bounding planes given two points in screen coordinates (as in two mouse clicks). A plane can be defined by a point on it and its normal, which is what is beaing returned for each of the four planes as defined by selectWindow. For this, 8 points are calculated, two for each corner, for the front and back plane. This defines a box. The points are to be defined as pointing towards the screen (i.e. a1 lies in the middle of the volume and a2 is in the front plane), regardless of the coordinate system used (left or right handed), and the second point will be at the screen plane.
private getPlanes ( Canguro activeView, int fx1, int fy1, int fx2, int fy2, System.Vector3 &nAB, System.Vector3 &sAB, System.Vector3 &nBC, System.Vector3 &sBC, System.Vector3 &nCD, System.Vector3 &sCD, System.Vector3 &nDA, System.Vector3 &sDA, System.Vector3 &corners1, System.Vector3 &corners2 ) : void
activeView Canguro The view that's used for calculating the bounding planes
fx1 int Clicked first point, X screen coordinate
fy1 int Clicked first point, Y screen coordinate
fx2 int Clicked second point, X screen coordinate
fy2 int Clicked second point, Y screen coordinate
nAB System.Vector3 Returns the calculated normal for the plane AB
sAB System.Vector3 Returns a point on the calculated plane AB
nBC System.Vector3 Returns the calculated normal for the plane BC
sBC System.Vector3 Returns a point on the calculated plane BC
nCD System.Vector3 Returns the calculated normal for the plane CD
sCD System.Vector3 Returns a point on the calculated plane CD
nDA System.Vector3 Returns the calculated normal for the plane DA
sDA System.Vector3 Returns a point on the calculated plane DA
corners1 System.Vector3
corners2 System.Vector3
Résultat void
        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;
        }