Ejemplo n.º 1
0
        private void BotCountDownTimerOnTick(object sender)
        {
            var timeDiff = DateTime.Now - startTime;

            System.Windows.Application.Current?.Dispatcher.Invoke(() =>
            {
                TopPlayerRestTime = GeometryLibUtils.DoubleFormat(Constants.GameConstraint.BotThinkingTimeSeconds - timeDiff.TotalSeconds, 2);
            });
        }
        private void UpdateGridDrawing(int roundedTimeSlotCount, double excactTimeSlotCount, double timeSlotWidth)
        {
            for (int slot = 0; slot < roundedTimeSlotCount + 1; slot++)
            {
                var xCoord = slot * timeSlotWidth;

                TimeSlotLabels[slot].XCoord       = xCoord;
                TimeSlotLines [slot].XCoord       = xCoord;
                TimeSlotLines [slot].YCoordBottom = gridSize.Height;
            }

            if (!GeometryLibUtils.DoubleEquals(excactTimeSlotCount, roundedTimeSlotCount))
            {
                TimeSlotLabels[roundedTimeSlotCount + 1].XCoord       = gridSize.Width;
                TimeSlotLines [roundedTimeSlotCount + 1].XCoord       = gridSize.Width;
                TimeSlotLines [roundedTimeSlotCount + 1].YCoordBottom = gridSize.Height;
            }
        }
        private void CreateGridDrawing(int roundedTimeSlotCount, double excactTimeSlotCount,
                                       uint slotLengthInSeconds, double timeSlotWidth)
        {
            TimeSlotLabels.Clear();
            TimeSlotLines.Clear();

            for (uint slot = 0; slot < roundedTimeSlotCount + 1; slot++)
            {
                var timeCaption = new Time(timeSlotStart + new Duration(slot * slotLengthInSeconds)).ToString()
                                  .Substring(0, 5);

                TimeSlotLabels.Add(new TimeSlotLabel(timeCaption)
                {
                    XCoord = slot * timeSlotWidth,
                    YCoord = 30
                });

                TimeSlotLines.Add(new TimeSlotLine()
                {
                    XCoord       = slot * timeSlotWidth,
                    YCoordTop    = 60,
                    YCoordBottom = gridSize.Height
                });
            }

            if (!GeometryLibUtils.DoubleEquals(excactTimeSlotCount, roundedTimeSlotCount))
            {
                var timeCaption = timeSlotEnd.ToString()
                                  .Substring(0, 5);

                TimeSlotLabels.Add(new TimeSlotLabel(timeCaption)
                {
                    XCoord = gridSize.Width,
                    YCoord = 30
                });

                TimeSlotLines.Add(new TimeSlotLine()
                {
                    XCoord       = gridSize.Width,
                    YCoordTop    = 60,
                    YCoordBottom = gridSize.Height
                });
            }
        }
Ejemplo n.º 4
0
        private static IntersectionResult <double> RayPlaneIntersection(Ray r, Plane p)
        {
            var quotient = r.Direction * p.Normal;

            if (GeometryLibUtils.DoubleEquals(quotient, 0))
            {
                return(new IntersectionResult <double>(IntersectionResultType.NoIntersection));
            }

            var t = (p.Distance - ((Vec3)r.Origin * p.Normal)) / quotient;

            if (t < 0)
            {
                return(new IntersectionResult <double>(IntersectionResultType.NoIntersection));
            }
            else
            {
                return(new IntersectionResult <double>(t));
            }
        }
Ejemplo n.º 5
0
 public override string ToString() => $"PC({GeometryLibUtils.DoubleFormat(Radius)}, {Theta}, {Phi})";
Ejemplo n.º 6
0
 public override bool Equals(object obj) => this.Equals(obj, (p1, p2) => GeometryLibUtils.DoubleEquals(p1.Radius, p2.Radius) &&
                                                        p1.Theta == p2.Theta &&
                                                        p1.Phi == p2.Phi);
Ejemplo n.º 7
0
        static double[] ComputeBarycentricCoords3D(CartesianCoordinate a,
                                                   CartesianCoordinate b,
                                                   CartesianCoordinate c,
                                                   CartesianCoordinate p)
        {
            // First, compute two clockwise edge vectors
            var d1 = b - a;
            var d2 = c - b;

            // Compute surface normal using cross product. In many cases
            // this step could be skipped, since we would have the surface
            // normal precomputed. We do not need to normalize it, although
            // if a precomputed normal was normalized, it would be OK.
            var n = d1 % d2;

            // Locate dominant axis of normal, and select plane of projection
            double u1, u2, u3, u4;
            double v1, v2, v3, v4;

            if ((Abs(n.X) >= Abs(n.Y)) &&
                (Abs(n.X) >= Abs(n.Z)))
            {
                // Discard x, project onto yz plane
                u1 = a.Y - c.Y;     v1 = a.Z - c.Z;
                u2 = b.Y - c.Y;     v2 = b.Z - c.Z;
                u3 = p.Y - a.Y;     v3 = p.Z - a.Z;
                u4 = p.Y - c.Y;     v4 = p.Z - c.Z;
            }
            else if (Abs(n.Y) >= Abs(n.Z))
            {
                // Discard y, project onto xz plane
                u1 = a.Z - c.Z;     v1 = a.X - c.X;
                u2 = b.Z - c.Z;     v2 = b.X - c.X;
                u3 = p.Z - a.Z;     v3 = p.X - a.X;
                u4 = p.Z - c.Z;     v4 = p.X - c.X;
            }
            else
            {
                u1 = a.X - c.X;     v1 = a.Y - c.Y;
                u2 = b.X - c.X;     v2 = b.Y - c.Y;
                u3 = p.X - a.X;     v3 = p.Y - a.Y;
                u4 = p.X - c.X;     v4 = p.Y - c.Y;
            }

            // Compute denominator, check for invalid
            var denom = v1 * u2 - v2 * u1;

            if (GeometryLibUtils.DoubleEquals(denom, 0.0))
            {
                // Bogus triangle - probably triangle has zero area
                return(null);
            }

            // Compute barycentric coordinates
            var barycentricCoords = new double[3];

            var oneOverDenom = 1.0 / denom;

            barycentricCoords[0] = (v4 * u2 - v2 * u4) * oneOverDenom;
            barycentricCoords[1] = (v1 * u3 - v3 * u1) * oneOverDenom;
            barycentricCoords[2] = 1.0 - barycentricCoords[0] - barycentricCoords[1];

            // OK
            return(barycentricCoords);
        }
Ejemplo n.º 8
0
 public override string ToString() => GeometryLibUtils.DoubleFormat(Value) + " deg";
Ejemplo n.º 9
0
 public override bool   Equals(object obj) => this.Equals(obj, (a1, a2) => GeometryLibUtils.DoubleEquals(a1.PosValue.Value, a2.PosValue.Value));