Ejemplo n.º 1
0
 public void ClassifyPoint(BSPVertex vert, Vector3 planePoint, Vector3 planeNorm)
 {
     if (PointOnPlane(vert.Point, planePoint, planeNorm))
     {
         vert.Classification = BSPClassification.OnPlane;
     }
     else if (PointInFront(vert.Point, planePoint, planeNorm))
     {
         vert.Classification = BSPClassification.Front;
     }
     else
     {
         vert.Classification = BSPClassification.Back;
     }
 }
Ejemplo n.º 2
0
        public void SplitPolygon(BSPFace face, Vector3 planePoint, Vector3 planeNorm, ref BSPFace front, ref BSPFace back)
        {
            front.TextureID = face.TextureID;
            back.TextureID  = face.TextureID;

            BSPVertex firstPoint = face.Points[0];

            if (firstPoint.Classification == BSPClassification.OnPlane)
            {
                front.Points.Add(firstPoint);
                back.Points.Add(firstPoint);
            }
            else if (firstPoint.Classification == BSPClassification.Front)
            {
                front.Points.Add(firstPoint);
            }
            else
            {
                back.Points.Add(firstPoint);
            }

            int       current = 0;
            BSPVertex vert1, vert2;

            for (int i = 1; i < face.Points.Count + 1; i++)
            {
                if (i == face.Points.Count)
                {
                    current = 0;
                }
                else
                {
                    current = i;
                }

                vert1 = face.Points[i - 1];
                vert2 = face.Points[current];

                ClassifyPoint(vert2, planePoint, planeNorm);
                if (vert2.Classification == BSPClassification.OnPlane)
                {
                    front.Points.Add(vert2);
                    back.Points.Add(vert2);
                }
                else
                {
                    Vector3 intersect  = new Vector3();
                    float   percentage = 0.0f;

                    bool split = SplitEdge(vert1.Point, vert2.Point, planePoint, planeNorm, ref percentage, ref intersect);

                    if (split)
                    {
                        Vector3   texDelta = vert2.UVs - vert1.UVs;
                        BSPVertex newVert  = new BSPVertex
                        {
                            Classification = BSPClassification.OnPlane,
                            Point          = intersect,
                            UVs            = texDelta * percentage + vert1.UVs
                        };

                        if (vert2.Classification == BSPClassification.Front)
                        {
                            back.Points.Add(newVert);
                            front.Points.Add(newVert);
                            front.Points.Add(vert2);
                        }
                        else if (vert2.Classification == BSPClassification.Back)
                        {
                            front.Points.Add(newVert);
                            back.Points.Add(newVert);
                            back.Points.Add(vert2);
                        }
                    }
                    else
                    {
                        if (vert2.Classification == BSPClassification.Front)
                        {
                            front.Points.Add(vert2);
                        }
                        else if (vert2.Classification == BSPClassification.Back)
                        {
                            back.Points.Add(vert2);
                        }
                    }
                }
            }
            //TODO: This isn't always accurate at extreme splits.
            front.Normal = face.Normal;
            back.Normal  = face.Normal;

            //front.CalculateNormal();
            front.CalculateCenter();

            //back.CalculateNormal();
            back.CalculateCenter();
        }