Esempio n. 1
0
        public static double GetSignedDistanceFromPointToLine(
            double pX, double pZ, double v1X, double v1Z, double v2X, double v2Z, double v3X, double v3Z, int p1Index, int p2Index, bool?misalignmentOffsetNullable = null)
        {
            double[] vX = new double[] { v1X, v2X, v3X };
            double[] vZ = new double[] { v1Z, v2Z, v3Z };

            double p1X = vX[p1Index - 1];
            double p1Z = vZ[p1Index - 1];
            double p2X = vX[p2Index - 1];
            double p2Z = vZ[p2Index - 1];

            double dist                   = MoreMath.GetDistanceFromPointToLine(pX, pZ, p1X, p1Z, p2X, p2Z);
            bool   leftOfLine             = MoreMath.IsPointLeftOfLine(pX, pZ, p1X, p1Z, p2X, p2Z);
            bool   floorTri               = MoreMath.IsPointLeftOfLine(v3X, v3Z, v1X, v1Z, v2X, v2Z);
            bool   onSideOfLineTowardsTri = floorTri == leftOfLine;
            double signedDist             = dist * (onSideOfLineTowardsTri ? 1 : -1);

            bool misalignmentOffset = misalignmentOffsetNullable ?? SavedSettingsConfig.UseMisalignmentOffsetForDistanceToLine;

            if (misalignmentOffset)
            {
                if (p1X == p2X)
                {
                    bool thirdPointOnLeft = p1Z >= p2Z == floorTri;
                    if ((thirdPointOnLeft && p1X >= 0) || (!thirdPointOnLeft && p1X <= 0))
                    {
                        signedDist += 1;
                    }
                }
                else if (p1Z == p2Z)
                {
                    bool thirdPointOnTop = p1X <= p2X == floorTri;
                    if ((thirdPointOnTop && p1Z >= 0) || (!thirdPointOnTop && p1Z <= 0))
                    {
                        signedDist += 1;
                    }
                }
            }

            return(signedDist);
        }
Esempio n. 2
0
            public CoinState GetNextState()
            {
                float newXSpeed = (float)MoreMath.MoveNumberTowards(XSpeed, 0, 0.001f * XSpeed * XSpeed);
                float newZSpeed = (float)MoreMath.MoveNumberTowards(ZSpeed, 0, 0.001f * ZSpeed * ZSpeed);
                float newHSpeed = (float)Math.Sqrt(newXSpeed * newXSpeed + newZSpeed * newZSpeed);
                float newYSpeed = Math.Max(-78, YSpeed - 4);

                float newX = X + newXSpeed;
                float newZ = Z + newZSpeed;
                float newY = Y + newYSpeed;

                ushort newAngle = Angle;

                (double newXSpeed2, double newZSpeed2) = MoreMath.GetComponentsFromVector(
                    newHSpeed, MoreMath.TruncateToMultipleOf16(newAngle));
                newXSpeed = (float)newXSpeed2;
                newZSpeed = (float)newZSpeed2;

                return(new CoinState(
                           newX, newY, newZ,
                           newXSpeed, newYSpeed, newZSpeed,
                           newHSpeed, newAngle));
            }
Esempio n. 3
0
 public static uint ParseUIntRoundingCapping(double value)
 {
     return((uint)MoreMath.GetIntegerInRangeCapped(value, 1.0 + uint.MaxValue - uint.MinValue, false));
 }
Esempio n. 4
0
 public static int ParseIntRoundingCapping(double value)
 {
     return((int)MoreMath.GetIntegerInRangeCapped(value, 1.0 + int.MaxValue - int.MinValue, true));
 }
Esempio n. 5
0
 public static short ParseShortRoundingCapping(double value)
 {
     return((short)MoreMath.GetIntegerInRangeCapped(value, 1.0 + short.MaxValue - short.MinValue, true));
 }
Esempio n. 6
0
 public static sbyte ParseSByteRoundingCapping(double value)
 {
     return((sbyte)MoreMath.GetIntegerInRangeCapped(value, 1.0 + sbyte.MaxValue - sbyte.MinValue, true));
 }
Esempio n. 7
0
 public static byte ParseByteRoundingCapping(double value)
 {
     return((byte)MoreMath.GetIntegerInRangeCapped(value, 1.0 + byte.MaxValue - byte.MinValue, false));
 }
Esempio n. 8
0
 public static ushort ParseUShortRoundingWrapping(double value)
 {
     return((ushort)MoreMath.GetIntegerInRangeWrapped(value, 1.0 + ushort.MaxValue - ushort.MinValue, false));
 }
Esempio n. 9
0
 public static double GetRelativeCoordinate(double coord)
 {
     return(MoreMath.MaybeNegativeModulus(coord, PuSize));
 }
Esempio n. 10
0
        public static void SetTrackBarValueCapped(TrackBar trackBar, double value)
        {
            int newValue = (int)MoreMath.Clamp(value, trackBar.Minimum, trackBar.Maximum);

            trackBar.Value = newValue;
        }
Esempio n. 11
0
        public static void InitializeThreeDimensionController(
            CoordinateSystem coordinateSystem,
            bool allowRelativeOptions,
            GroupBox groupbox,
            Button buttonSquareLeft,
            Button buttonSquareRight,
            Button buttonSquareUp,
            Button buttonSquareDown,
            Button buttonSquareUpLeft,
            Button buttonSquareDownLeft,
            Button buttonSquareUpRight,
            Button buttonSquareDownRight,
            Button buttonLineUp,
            Button buttonLineDown,
            TextBox textboxSquare,
            TextBox textboxLine,
            CheckBox checkbox,
            Action <float, float, float, bool> actionMove)
        {
            Action <int, int> actionSquare = (int hSign, int vSign) =>
            {
                float value;
                if (!float.TryParse(textboxSquare.Text, out value))
                {
                    return;
                }
                actionMove(hSign * value, vSign * value, 0, checkbox?.Checked ?? false);
            };

            Action <int> actionLine = (int nSign) =>
            {
                float value;
                if (!float.TryParse(textboxLine.Text, out value))
                {
                    return;
                }
                actionMove(0, 0, nSign * value, checkbox?.Checked ?? false);
            };

            Action setEulerNames = () =>
            {
                buttonSquareLeft.Text      = "X-";
                buttonSquareRight.Text     = "X+";
                buttonSquareUp.Text        = "Z-";
                buttonSquareDown.Text      = "Z+";
                buttonSquareUpLeft.Text    = "X-Z-";
                buttonSquareDownLeft.Text  = "X-Z+";
                buttonSquareUpRight.Text   = "X+Z-";
                buttonSquareDownRight.Text = "X+Z+";
                buttonLineUp.Text          = "Y+";
                buttonLineDown.Text        = "Y-";
            };

            Action setRelativeNames = () =>
            {
                buttonSquareLeft.Text      = "L";
                buttonSquareRight.Text     = "R";
                buttonSquareUp.Text        = "F";
                buttonSquareDown.Text      = "B";
                buttonSquareUpLeft.Text    = "FL";
                buttonSquareDownLeft.Text  = "BL";
                buttonSquareUpRight.Text   = "FR";
                buttonSquareDownRight.Text = "BR";
                buttonLineUp.Text          = "U";
                buttonLineDown.Text        = "D";
            };

            Action actionCheckedChanged = () =>
            {
                if (checkbox.Checked)
                {
                    setRelativeNames();
                }
                else
                {
                    setEulerNames();
                }
            };

            buttonSquareLeft.Click      += (sender, e) => actionSquare(-1, 0);
            buttonSquareRight.Click     += (sender, e) => actionSquare(1, 0);
            buttonSquareUp.Click        += (sender, e) => actionSquare(0, 1);
            buttonSquareDown.Click      += (sender, e) => actionSquare(0, -1);
            buttonSquareUpLeft.Click    += (sender, e) => actionSquare(-1, 1);
            buttonSquareDownLeft.Click  += (sender, e) => actionSquare(-1, -1);
            buttonSquareUpRight.Click   += (sender, e) => actionSquare(1, 1);
            buttonSquareDownRight.Click += (sender, e) => actionSquare(1, -1);
            buttonLineUp.Click          += (sender, e) => actionLine(1);
            buttonLineDown.Click        += (sender, e) => actionLine(-1);
            if (coordinateSystem == CoordinateSystem.Euler && allowRelativeOptions)
            {
                checkbox.CheckedChanged += (sender, e) => actionCheckedChanged();
            }

            // Implement ToolStripMenu

            List <Button> buttonList = new List <Button>()
            {
                buttonSquareUp,
                buttonSquareUpRight,
                buttonSquareRight,
                buttonSquareDownRight,
                buttonSquareDown,
                buttonSquareDownLeft,
                buttonSquareLeft,
                buttonSquareUpLeft,
            };

            List <Point> positionList = buttonList.ConvertAll(
                button => new Point(button.Location.X, button.Location.Y));

            ToolStripMenuItem itemLeft      = new ToolStripMenuItem("Face Left (X-) (49152)");
            ToolStripMenuItem itemRight     = new ToolStripMenuItem("Face Right (X+) (16384)");
            ToolStripMenuItem itemUp        = new ToolStripMenuItem("Face Up (Z-) (32768)");
            ToolStripMenuItem itemDown      = new ToolStripMenuItem("Face Down (Z+) (0)");
            ToolStripMenuItem itemUpLeft    = new ToolStripMenuItem("Face Up-Left (X-Z-) (40960)");
            ToolStripMenuItem itemDownLeft  = new ToolStripMenuItem("Face Down-Left (X-Z+) (57344)");
            ToolStripMenuItem itemUpRight   = new ToolStripMenuItem("Face Up-Right (X+Z-) (24576)");
            ToolStripMenuItem itemDownRight = new ToolStripMenuItem("Face Down-Right (X+Z+) (8192)");
            ToolStripMenuItem itemInverted  = new ToolStripMenuItem("Inverted");
            int lastDirection = 0;

            List <ToolStripMenuItem> itemList =
                new List <ToolStripMenuItem>()
            {
                itemUp,
                itemUpRight,
                itemRight,
                itemDownRight,
                itemDown,
                itemDownLeft,
                itemLeft,
                itemUpLeft,
            };

            Action <int, bool> SetFacingDirection = (int direction, bool inverted) =>
            {
                for (int i = 0; i < itemList.Count; i++)
                {
                    itemList[i].Checked = i == direction;
                }
                lastDirection = direction;

                for (int i = 0; i < buttonList.Count; i++)
                {
                    int    sign          = inverted ? -1 : 1;
                    int    positionIndex = MoreMath.NonNegativeModulus(i * sign, buttonList.Count);
                    int    buttonIndex   = MoreMath.NonNegativeModulus(direction + i, buttonList.Count);
                    Point  point         = positionList[positionIndex];
                    Button button        = buttonList[buttonIndex];
                    button.Location = point;
                }
            };

            itemLeft.Click      += (sender, e) => SetFacingDirection(6, itemInverted.Checked);
            itemRight.Click     += (sender, e) => SetFacingDirection(2, itemInverted.Checked);
            itemUp.Click        += (sender, e) => SetFacingDirection(0, itemInverted.Checked);
            itemDown.Click      += (sender, e) => SetFacingDirection(4, itemInverted.Checked);
            itemUpLeft.Click    += (sender, e) => SetFacingDirection(7, itemInverted.Checked);
            itemDownLeft.Click  += (sender, e) => SetFacingDirection(5, itemInverted.Checked);
            itemUpRight.Click   += (sender, e) => SetFacingDirection(1, itemInverted.Checked);
            itemDownRight.Click += (sender, e) => SetFacingDirection(3, itemInverted.Checked);
            itemInverted.Click  += (sender, e) =>
            {
                itemInverted.Checked = !itemInverted.Checked;
                SetFacingDirection(lastDirection, itemInverted.Checked);
            };

            ToolStripMenuItem itemPopOut = new ToolStripMenuItem("Pop Out");

            itemPopOut.Click += (sender, e) =>
            {
                VariableTripletControllerForm form = new VariableTripletControllerForm();
                TabPage parentTab  = GetTab(groupbox);
                Form    parentForm = GetForm(groupbox);
                string  text       = parentTab != null ? parentTab.Text + " " + groupbox.Text : parentForm.Text;
                form.Initialize(text, coordinateSystem, allowRelativeOptions, actionMove);
                form.ShowForm();
            };

            ContextMenuStrip contextMenuStrip = new ContextMenuStrip();

            contextMenuStrip.Items.Add(itemLeft);
            contextMenuStrip.Items.Add(itemRight);
            contextMenuStrip.Items.Add(itemUp);
            contextMenuStrip.Items.Add(itemDown);
            contextMenuStrip.Items.Add(itemUpLeft);
            contextMenuStrip.Items.Add(itemDownLeft);
            contextMenuStrip.Items.Add(itemUpRight);
            contextMenuStrip.Items.Add(itemDownRight);
            contextMenuStrip.Items.Add(new ToolStripSeparator());
            contextMenuStrip.Items.Add(itemInverted);
            contextMenuStrip.Items.Add(new ToolStripSeparator());
            contextMenuStrip.Items.Add(itemPopOut);
            groupbox.ContextMenuStrip = contextMenuStrip;

            AddInversionContextMenuStrip(buttonLineUp, buttonLineDown);

            itemUp.Checked = true;
        }
Esempio n. 12
0
        public static List <TriangleShape> GetWallTriangleHitboxComponents(List <TriangleDataModel> wallTriangles)
        {
            List <((short, short), (short, short), bool)> vertexPairs =
                new List <((short, short), (short, short), bool)>();

            foreach (TriangleDataModel wallTriangle in wallTriangles)
            {
                List <(short, short)> vertices = new List <(short, short)>()
                {
                    (wallTriangle.X1, wallTriangle.Z1),
                    (wallTriangle.X2, wallTriangle.Z2),
                    (wallTriangle.X3, wallTriangle.Z3),
                };

                for (int i = 0; i < vertices.Count; i++)
                {
                    (short x1, short z1) = vertices[i];
                    (short x2, short z2) = vertices[(i + 1) % vertices.Count];
                    vertexPairs.Add(((x1, z1), (x2, z2), wallTriangle.XProjection));
                }
            }

            List <int> badVertexPairIndexes = new List <int>();

            for (int i = 0; i < vertexPairs.Count; i++)
            {
                ((short x1, short z1), (short x2, short z2), bool proj) = vertexPairs[i];
                if (x1 == x2 && z1 == z2)
                {
                    badVertexPairIndexes.Add(i);
                }
            }
            for (int i = 0; i < vertexPairs.Count; i++)
            {
                for (int j = i + 1; j < vertexPairs.Count; j++)
                {
                    var vertexPair1 = vertexPairs[i];
                    var vertexPair2 = vertexPairs[j];
                    ((short vp1x1, short vp1z1), (short vp1x2, short vp1z2), bool vp1proj) = vertexPair1;
                    ((short vp2x1, short vp2z1), (short vp2x2, short vp2z2), bool vp2proj) = vertexPair2;
                    if ((vp1x1 == vp2x1 && vp1z1 == vp2z1 && vp1x2 == vp2x2 && vp1z2 == vp2z2) ||
                        (vp1x1 == vp2x2 && vp1z1 == vp2z2 && vp1x2 == vp2x1 && vp1z2 == vp2z1))
                    {
                        badVertexPairIndexes.Add(j);
                    }
                }
            }

            badVertexPairIndexes = badVertexPairIndexes.Distinct().ToList();
            badVertexPairIndexes.Sort();
            badVertexPairIndexes.Reverse();
            badVertexPairIndexes.ForEach(index => vertexPairs.RemoveAt(index));

            List <TriangleShape> triShapes = new List <TriangleShape>();

            foreach (var((x1, z1), (x2, z2), proj) in vertexPairs)
            {
                double angle     = MoreMath.AngleTo_AngleUnits(x1, z1, x2, z2);
                double projAngle = proj ? 16384 : 0;
                double projDist  = 50 / Math.Sin(MoreMath.AngleUnitsToRadians(angle - projAngle));
                (double p1X, double p1Z) = MoreMath.AddVectorToPoint(projDist, projAngle, x1, z1);
                (double p2X, double p2Z) = MoreMath.AddVectorToPoint(-1 * projDist, projAngle, x1, z1);
                (double p3X, double p3Z) = MoreMath.AddVectorToPoint(projDist, projAngle, x2, z2);
                (double p4X, double p4Z) = MoreMath.AddVectorToPoint(-1 * projDist, projAngle, x2, z2);

                TriangleShape triShape1 = new TriangleShape(p1X, 0, p1Z, p2X, 0, p2Z, p3X, 0, p3Z);
                TriangleShape triShape2 = new TriangleShape(p2X, 0, p2Z, p3X, 0, p3Z, p4X, 0, p4Z);
                triShapes.Add(triShape1);
                triShapes.Add(triShape2);
            }
            return(triShapes);
        }
Esempio n. 13
0
 public static ushort GetRngValue(int index)
 {
     index = MoreMath.NonNegativeModulus(index, RNG_COUNT);
     return(IndexToRNGDictionary[index]);
 }