Пример #1
0
        public GLPolygon NearestPolygon(GLPoint P)
        {
            //Logger.WriteToLog("Detecting nearest polygon to point: " + P.ToString());

            GLPolygon nearestPolygon = null;

            var minDistance = double.MaxValue;
            var i           = 0;

            foreach (var pol in Polygons)
            {
                var d = pol.DistanceToPoint(P);

                if (d < minDistance)
                {
                    minDistance    = d;
                    nearestPolygon = pol;
                }

                //Logger.WriteToLog(String.Format("Distance to polygon {0}: {1} ",i,d.ToString("#0.00")));

                i++;
            }

            return(nearestPolygon);
        }
Пример #2
0
        public GLPolygon NearestPolygon(GLPoint P)
        {
            GLPolygon nearestPolygon = null;

            var minDistance = double.MaxValue;
            var i           = 0;

            foreach (var obj in Objects)
            {
                if (obj is GLObject)
                {
                    var d = obj.DistanceToPoint(P);

                    if (d == -1)
                    {
                        // some error
                        continue;
                    }

                    if (d < minDistance)
                    {
                        minDistance    = d;
                        nearestPolygon = (obj as GLObject).NearestPolygon(P);
                    }
                }
                i++;
            }

            return(nearestPolygon);
        }
Пример #3
0
        public static GLObject CreateFromPolygon(GLPolygon pol, string name)
        {
            var res = new GLObject()
            {
                Name = name
            };

            res.Polygons.Add(pol);

            return(res);
        }
Пример #4
0
        public static GLPolygon CreateFromPoints(IEnumerable <GLPoint> points)
        {
            var pol = new GLPolygon();

            foreach (var point in points)
            {
                pol.Points.Add(point);
            }

            return(pol);
        }
Пример #5
0
        public override void LoadFromXmlElement(Context context, XmlElement element)
        {
            base.LoadFromXmlElement(context, element);

            var polygonNodes = element.SelectNodes("./polygon");

            foreach (XmlElement polygonElement in polygonNodes)
            {
                var pol = new GLPolygon();
                pol.LoadFromXmlElement(polygonElement);
                Polygons.Add(pol);
            }
        }
Пример #6
0
        public GLPolygon Clone()
        {
            var pol = new GLPolygon();

            pol.FillColor = FillColor;
            pol.Texture   = Texture;
            pol.Visible   = Visible;

            pol.Points = new List <GLPoint>();

            foreach (var point in Points)
            {
                pol.Points.Add(new GLPoint(point.X, point.Y, point.Z));
            }

            return(pol);
        }
Пример #7
0
        public void CreatePolygons()
        {
            Polygons.Clear();

            for (var j = 0; j <= Slices; j++)
            {
                var angleJ  = j * 360.0 / (double)Slices;
                var angleJ2 = (j + 1) * 360.0 / (double)Slices;

                for (var i = 0; i <= Stacks; i++)
                {
                    var angleI  = i * 180.0 / (double)Stacks;
                    var angleI2 = (i + 1) * 180.0 / (double)Stacks;

                    var A = Spherical(Radius, angleI, angleJ);
                    var B = Spherical(Radius, angleI, angleJ2);
                    var C = Spherical(Radius, angleI2, angleJ2);
                    var D = Spherical(Radius, angleI2, angleJ);

                    var polygon = new GLPolygon(A, B, C, D);
                    polygon.Texture = Texture;

                    var textCoordLeft  = (j) * (1.0 / Slices);
                    var textCoordRight = (j + 1) * (1.0 / Slices);

                    var textCoordTop    = (i) * (1.0 / Stacks);
                    var textCoordBottom = (i + 1) * (1.0 / Stacks);

                    var coords = new List <GLTexCoord>();

                    coords.Add(new GLTexCoord(textCoordLeft, textCoordTop));
                    coords.Add(new GLTexCoord(textCoordRight, textCoordTop));
                    coords.Add(new GLTexCoord(textCoordRight, textCoordBottom));
                    coords.Add(new GLTexCoord(textCoordLeft, textCoordBottom));


                    polygon.SetPolygonTexCoords(coords);

                    Polygons.Add(polygon);
                }
            }
        }
Пример #8
0
        public void GenerateRingPolygon()
        {
            Ring = new GLObject();

            GLTexture ringTexture = null;

            if (RingTextureName != null)
            {
                ringTexture = GLTextureAdmin.GetTextureByName(RingTextureName);
            }

            var angleStep = 360.0 / (double)Slices;

            var c = new GLPoint(0, 0, 0);

            for (double i = 0; i <= 360; i += angleStep)
            {
                double ax = (Radius + 1) * Math.Cos(i * Math.PI / 180.0) + c.X;
                double az = (Radius + 1) * Math.Sin(i * Math.PI / 180.0) + c.Z;

                double bx = (Radius + 1 + RingSize) * Math.Cos(i * Math.PI / 180.0) + c.X;
                double bz = (Radius + 1 + RingSize) * Math.Sin(i * Math.PI / 180.0) + c.Z;

                double cx = (Radius + 1 + RingSize) * Math.Cos((i + angleStep) * Math.PI / 180.0) + c.X;
                double cz = (Radius + 1 + RingSize) * Math.Sin((i + angleStep) * Math.PI / 180.0) + c.Z;

                double dx = (Radius + 1) * Math.Cos((i + angleStep) * Math.PI / 180.0) + c.X;
                double dz = (Radius + 1) * Math.Sin((i + angleStep) * Math.PI / 180.0) + c.Z;

                var polygon = new GLPolygon();
                polygon.FillColor = RingFillColor;
                polygon.Texture   = ringTexture;

                polygon.Points.Add(new GLPoint(ax, c.Y, az));
                polygon.Points.Add(new GLPoint(bx, c.Y, bz));
                polygon.Points.Add(new GLPoint(cx, c.Y, cz));
                polygon.Points.Add(new GLPoint(dx, c.Y, dz));

                Ring.Polygons.Add(polygon);
            }
        }