Esempio n. 1
0
        public static GLPlane CreateFromPoints(GLPoint A, GLPoint B, GLPoint C)
        {
            var u = new GLVector(A, B);
            var v = new GLVector(B, C);

            return(CreateFromVectorsAndPoint(u, v, A));
        }
Esempio n. 2
0
        public static GLPoint GetMovedPointByAngle(GLPoint P, double stepSize, double angle, bool forward)
        {
            var rotatedPoint = new GLPoint(0, P.Y, 0);

            rotatedPoint.X = P.X + stepSize * Math.Cos((angle - 90) * Math.PI / 180.0);
            rotatedPoint.Z = P.Z + stepSize * Math.Sin((angle - 90) * Math.PI / 180.0);

            var viewVec = new GLVector(rotatedPoint, P);

            var movedPoint = new GLPoint(P.X, P.Y, P.Z);

            if (forward)
            {
                movedPoint.X += 1 * viewVec.X;
                movedPoint.Y += 1 * viewVec.Y;
                movedPoint.Z += 1 * viewVec.Z;
            }
            else
            {
                movedPoint.X -= 1 * viewVec.X;
                movedPoint.Y -= 1 * viewVec.Y;
                movedPoint.Z -= 1 * viewVec.Z;
            }

            return(movedPoint);
        }
Esempio n. 3
0
 public GLStarSpace()
 {
     Name      = "StarSpace";
     FillColor = Color.White;
     Count     = 0;
     SizeVec   = new GLVector(10, 5, 10);
     Stars     = new List <GLPoint>();
 }
Esempio n. 4
0
 public void Rotate(GLVector vec)
 {
     Rotation.X += vec.X;
     Rotation.X += vec.X % 360;
     Rotation.Y += vec.Y;
     Rotation.Y += vec.Y % 360;
     Rotation.Z += vec.Z;
     Rotation.Z += vec.Z % 360;
 }
Esempio n. 5
0
        public GLEllipse(string name, double radiusMajor, double radiusMinor, GLVector vecX, GLVector vecY)
            : this(name)
        {
            RadiusMajor = radiusMajor;
            RadiusMinor = radiusMinor;

            U = new GLVector(vecX);
            V = new GLVector(vecY);
        }
Esempio n. 6
0
        public GLEllipse()
        {
            FillColor = Color.White;

            RadiusMajor = 10;
            RadiusMinor = 5;

            U = new GLVector(1, 0, 0);
            V = new GLVector(0, 0, 1);
        }
Esempio n. 7
0
        public GLVector CrossProduct()
        {
            if (Points.Count < 3)
            {
                return(new GLVector());
            }

            var u = new GLVector(Points[0], Points[1]);
            var v = new GLVector(Points[1], Points[2]);

            return(GLVector.CrossProduct(u, v));
        }
Esempio n. 8
0
 public static double Distance(GLObj A, GLObj B)
 {
     if (A != null && B != null)
     {
         var vec = new GLVector(A.Position, B.Position);
         return(vec.Length);
     }
     else
     {
         return(0);
     }
 }
Esempio n. 9
0
        public double AngleToVec(GLVector vec)
        {
            // using first three points for creating plane vectors:
            if (Points.Count < 3)
            {
                return(0);
            }
            var plane = GLPlane.CreateFromPoints(Points[0], Points[1], Points[2]);

            var angleToNormal = plane.NormalVector.AngleToVec(vec);

            return(90 - angleToNormal);
        }
Esempio n. 10
0
        public GLSphere()
        {
            RotationSpeed = new GLVector(0, 0, 0.5);
            Radius        = 2;
            Slices        = 20;
            Stacks        = 20;
            Texture       = null;
            Orbit         = new GLEllipse();
            OrbitAngle    = 270;
            OrbitSpeed    = 0.5;

            Polygons = new List <GLPolygon> ();
        }
Esempio n. 11
0
        public static GLPlane CreateFromVectorsAndPoint(GLVector u, GLVector v, GLPoint P)
        {
            var plane = new GLPlane();

            plane.Name = "plane";

            plane.Position = P;

            var n = GLVector.CrossProduct(u, v);

            plane.NormalVector = n;

            plane.D = -n.X * P.X - n.Y * P.Y - n.Z * P.Z;

            return(plane);
        }
Esempio n. 12
0
        public GLPoint GetPositionOfAngleFocused(double angle)
        {
            var a            = (angle) * Math.PI / 180.0;
            var excentricity = Math.Sqrt(Math.Pow(RadiusMajor, 2) - Math.Pow(RadiusMinor, 2));
            var point270     = GetPositionOfAngle(270);

            if (RadiusMajor != 0)
            {
                var vec = new GLVector(Center, point270);
                var Fx  = new GLVector(excentricity / RadiusMajor * vec.X,
                                       excentricity / RadiusMajor * vec.Y,
                                       excentricity / RadiusMajor * vec.Z);
            }

            var x = Center.X + RadiusMajor * Math.Cos(a) * U.X + RadiusMinor * Math.Sin(a) * V.X;
            var y = Center.Y + RadiusMajor * Math.Cos(a) * U.Y + RadiusMinor * Math.Sin(a) * V.Y;
            var z = Center.Z + RadiusMajor * Math.Cos(a) * U.Z + RadiusMinor * Math.Sin(a) * V.Z;

            return(new GLPoint(x, y, z));
        }
Esempio n. 13
0
        public double AngleToVec(GLVector v)
        {
            var vec1den = Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2);
            var vec2den = Math.Pow(v.X, 2) + Math.Pow(v.Y, 2) + Math.Pow(v.Z, 2);

            vec1den = Math.Sqrt(vec1den);
            vec2den = Math.Sqrt(vec2den);

            var denominator = vec1den * vec2den;

            if (denominator == 0)
            {
                return(0);
            }

            var numerator = Math.Abs(X * v.X + Y * v.Y + Z * v.Z);

            var cosfee = numerator / denominator;

            return(Math.Acos(cosfee) * (180 / Math.PI));
        }
Esempio n. 14
0
        public override void Render()
        {
            //var timeAngle = ( (DateTime.Now.Second + DateTime.Now.Millisecond/1000.0) * 360/10.0);
            foreach (var satelitte in Satellites)
            {
                //satelitteAndHisEllipse.Key.OrbitAngle = timeAngle;
                //satelitteAndHisEllipse.Key.Position = satelitteAndHisEllipse.Value.GetPositionOfAngleFocused(timeAngle);
                //timeAngle+=70;

                // move ellipse center to planet
                // center of ellipse is [0;0;0]
                var moveVec = new GLVector(Position, satelitte.Orbit.Center);

                //satelitteAndHisEllipse.Value.Render();
                satelitte.Move(moveVec);
                //satelitteAndHisEllipse.Key.Rotation.Z = -timeAngle;
                satelitte.Render();
            }



            if (ShowRing)
            {
                if (Ring == null)
                {
                    GenerateRingPolygon();
                }

                Ring.Position = Position;
                Ring.Rotation = new GLVector(-30, 0, 20);

                Ring.Render();
            }


            base.Render();
        }
Esempio n. 15
0
 public void Move(GLVector vec)
 {
     X += vec.X;
     Y += vec.Y;
     Z += vec.Z;
 }
Esempio n. 16
0
 public static GLVector CrossProduct(GLVector u, GLVector v)
 {
     return(new GLVector(u.Y * v.Z - u.Z * v.Y, u.Z * v.X - u.X * v.Z, u.X * v.Y - u.Y * v.X));
 }
Esempio n. 17
0
        public double DistanceToPoint(GLPoint P)
        {
            // using first three points for creating plane vectors:
            if (Points.Count < 3)
            {
                return(-1);
            }

            var plane = GLPlane.CreateFromPoints(Points[0], Points[1], Points[2]);

            // computing line (made by observer view) - plane cross

            var viewLine = new GLLine();

            viewLine.Position   = P;
            viewLine.LineVector = plane.NormalVector;

            var cross = plane.CrossWithLine(viewLine);

            // geting polygon center to determine right half-plane
            var center = new GLPoint(
                (Points[0].X + Points[1].X + Points[2].X) / 3,
                (Points[0].Y + Points[1].Y + Points[2].Y) / 3,
                (Points[0].Z + Points[1].Z + Points[2].Z) / 3);

            // creating polygon-edge planes:

            //Logger.WriteToLog("Generating edge planes and lines");

            var edgeLines = new List <GLLine>();

            var pointInsideEdgePlanes = true;

            for (var i = 0; i < Points.Count; i++)
            {
                var A = Points[i];
                var B = i + 1 <= Points.Count - 1 ? Points[i + 1] : Points[0];
                var u = new GLVector(A, B);

                var edgePlane = GLPlane.CreateFromVectorsAndPoint(u, plane.NormalVector, A);

                // testing center half-plane position
                var centerInUpperHalfPlane = edgePlane.PointInUpperHalfPlane(center);
                var crossInUpperHalfPlane  = edgePlane.PointInUpperHalfPlane(cross);

                edgeLines.Add(GLLine.CrateFromPoints(A, B));

                if (centerInUpperHalfPlane != crossInUpperHalfPlane)
                {
                    pointInsideEdgePlanes = false;
                    break;
                }
            }

            //Logger.WriteToLog(" cross: " + cross.ToString());

            if (pointInsideEdgePlanes)
            {
                // point inside edge planes
                //Logger.WriteToLog(" point inside edge planes");

                return(cross.DistanceToPoint(P));
            }
            else
            {
                //Logger.WriteToLog("detecting minimal distance to all edge lines");

                var minDistance = double.MaxValue;

                foreach (var line in edgeLines)
                {
                    if (line.LineVector.IsZero)
                    {
                        continue;
                    }

                    var intersectionT = line.IntersectionWithPerpendicularThroughPointParamTValue(P);
                    //Logger.WriteToLog(" intersectionT param value: " + intersectionT.ToString());

                    if (intersectionT == double.MinValue)
                    {
                        return(-1);
                    }

                    if (intersectionT < 0)
                    {
                        // distance to A

                        var distanceToA = P.DistanceToPoint(line.Position);
                        if (distanceToA < minDistance)
                        {
                            minDistance = distanceToA;
                        }
                    }
                    else if (intersectionT > 1)
                    {
                        // distance to B
                        var B           = line.PointByParam(1);
                        var distanceToB = P.DistanceToPoint(B);
                        if (distanceToB < minDistance)
                        {
                            minDistance = distanceToB;
                        }
                    }
                    else
                    {
                        // distance to perpendicular line intersection

                        var intersection   = line.PointByParam(intersectionT);
                        var distanceToLine = P.DistanceToPoint(intersection);
                        if (distanceToLine < minDistance)
                        {
                            minDistance = distanceToLine;
                        }
                    }
                }

                if (minDistance == double.MaxValue)
                {
                    return(-1);
                }

                return(minDistance);
            }
        }
Esempio n. 18
0
 public GLVector(GLVector vec)
 {
     X = vec.X;
     Y = vec.Y;
     Z = vec.Z;
 }
Esempio n. 19
0
 public virtual void Move(GLVector vec)
 {
     Move((float)vec.X, (float)vec.Y, (float)vec.Z);
 }
Esempio n. 20
0
        }                                      // vector of rotation in all axis

        public GLObj(string name)
        {
            Name     = name;
            Rotation = new GLVector(0, 0, 0);
            Position = new GLPoint(0, 0, 0);
        }
Esempio n. 21
0
 public GLObj()
 {
     Rotation = new GLVector(0, 0, 0);
     Position = new GLPoint(0, 0, 0);
 }
Esempio n. 22
0
 public static GLPoint GetMovedPoint(GLPoint P, GLVector moveVector)
 {
     return(new GLPoint(P.X + moveVector.X, P.X + moveVector.Y, P.X + moveVector.Z));
 }