void OnSceneGUI()
    {
        SceneRectangle t   = (SceneRectangle)target;
        Vector3        pos = t.transform.position;

        Vector3[] verts = new Vector3[]
        {
            t.unscaledMin,
            t.unscaledMin + new Vector3(t.unscaledMax.x - t.unscaledMin.x, 0, 0),
            t.unscaledMax,
            t.unscaledMin + new Vector3(0, 0, t.unscaledMax.z - t.unscaledMin.z),
        };

        Handles.DrawSolidRectangleWithOutline(verts, new Color(0.5f, 0.5f, 0.5f, 0.1f), new Color(0, 0, 0, 1));

        EditorGUI.BeginChangeCheck();
        Vector3 newMin = Handles.PositionHandle(t.unscaledMin, Quaternion.identity);
        Vector3 newMax = Handles.PositionHandle(t.unscaledMax, Quaternion.identity);

        newMin.y = newMax.y = 0;
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(t, "Change scene rectangle");
            t.unscaledMin = Vector3.Min(newMin, newMax);
            t.unscaledMax = Vector3.Max(newMin, newMax);
        }
    }
        public void Scene_СalculateCircumscribingRectangle_ShouldBeСorrectСalculateСoordinates()
        {
            var commandProducer = new CommandProducer();
            var scene           = new Scene();

            commandProducer.AppendLine("add rectangle R1 (2, 1) (6, 5)");
            var command = commandProducer.GetCommand();

            command.Apply(scene);

            SceneRectangle sceneRectangle = scene.CalculateCircumscribingRectangle("R1");
            bool           matching       = false;

            if (EqualScenePoints(sceneRectangle.Vertex1, new ScenePoint(2, 5)) &&
                EqualScenePoints(sceneRectangle.Vertex2, new ScenePoint(6, 1)) ||
                EqualScenePoints(sceneRectangle.Vertex1, new ScenePoint(2, 1)) &&
                EqualScenePoints(sceneRectangle.Vertex2, new ScenePoint(6, 5)))
            {
                matching = true;
            }

            Assert.That(matching,
                        Is.True,
                        "Координаты прямоугольника, описывающего прямоугольник, неверные");
        }
        public void Scene_СalculateCircumscribingCircle_ShouldBeСorrectСalculateСoordinates()
        {
            var commandProducer = new CommandProducer();
            var scene           = new Scene();

            commandProducer.AppendLine("add circle C1 (-4, -3) radius 5");
            var command = commandProducer.GetCommand();

            command.Apply(scene);

            SceneRectangle sceneRectangle = scene.CalculateCircumscribingRectangle("C1");
            bool           matching       = false;

            if (EqualScenePoints(sceneRectangle.Vertex1, new ScenePoint(-9, 2)) &&
                EqualScenePoints(sceneRectangle.Vertex2, new ScenePoint(1, -8)) ||
                EqualScenePoints(sceneRectangle.Vertex1, new ScenePoint(1, 2)) &&
                EqualScenePoints(sceneRectangle.Vertex2, new ScenePoint(-9, -8)))
            {
                matching = true;
            }

            Assert.That(matching,
                        Is.True,
                        "Координаты прямоугольника, описывающего окружность, неверные");
        }
        public void Scene_СalculateCircumscribingPolygon_ShouldBeСorrectСalculateСoordinates()
        {
            var commandProducer = new CommandProducer();
            var scene           = new Scene();

            commandProducer.AppendLine("add polygon P1");
            commandProducer.AppendLine("add point (-3, 1)");
            commandProducer.AppendLine("add point (1, 5)");
            commandProducer.AppendLine("add point (0, 0)");
            commandProducer.AppendLine("add point (7, -6)");
            commandProducer.AppendLine("add point (-1, -4)");
            commandProducer.AppendLine("end polygon");
            var command = commandProducer.GetCommand();

            command.Apply(scene);

            SceneRectangle sceneRectangle = scene.CalculateCircumscribingRectangle("P1");
            bool           matching       = false;

            if (EqualScenePoints(sceneRectangle.Vertex1, new ScenePoint(-3, -6)) &&
                EqualScenePoints(sceneRectangle.Vertex2, new ScenePoint(7, 5)) ||
                EqualScenePoints(sceneRectangle.Vertex1, new ScenePoint(-3, 5)) &&
                EqualScenePoints(sceneRectangle.Vertex2, new ScenePoint(7, -6)))
            {
                matching = true;
            }

            Assert.That(matching,
                        Is.True,
                        "Координаты прямоугольника, описывающего полигон, неверные");
        }
Beispiel #5
0
        public SceneRectangle CalculateCircumscribingRectangle()
        {
            var arrayX = new SortedSet <double>();
            var arrayY = new SortedSet <double>();

            foreach (var figure in _childFigures)
            {
                var сircRectangle = new SceneRectangle
                {
                    Vertex1 = figure.CalculateCircumscribingRectangle().Vertex1,
                    Vertex2 = figure.CalculateCircumscribingRectangle().Vertex2
                };

                arrayX.Add(сircRectangle.Vertex1.X);
                arrayX.Add(сircRectangle.Vertex2.X);
                arrayY.Add(сircRectangle.Vertex1.Y);
                arrayY.Add(сircRectangle.Vertex2.Y);
            }

            var сircumscribingRectangle = new SceneRectangle
            {
                Vertex1 = new ScenePoint {
                    X = arrayX.Min, Y = arrayY.Max
                },
                Vertex2 = new ScenePoint {
                    X = arrayX.Max, Y = arrayY.Min
                }
            };

            return(сircumscribingRectangle);
        }
Beispiel #6
0
 public void Grapple(Transform grapplerTransform, Vector3 relativeTargetPos, SceneRectangle validRect)
 {
     if (activeGrappleCoroutine != null)
     {
         Debug.LogError("Grapple is already active!", this);
         return;
     }
     activeGrappleCoroutine = StartCoroutine(DoGrapple(grapplerTransform, relativeTargetPos, validRect));
     RpcShowGrapple(grapplerTransform.gameObject);
 }
        public SceneRectangle CalculateCircumscribingRectangle()
        {
            var ñircumscribingRectangle = new SceneRectangle
            {
                Vertex1 = new ScenePoint {
                    X = _center.X - _radius, Y = _center.Y + _radius
                },
                Vertex2 = new ScenePoint {
                    X = _center.X + _radius, Y = _center.Y - _radius
                }
            };

            return(ñircumscribingRectangle);
        }
Beispiel #8
0
        public void Reflect(ReflectOrientation orientation)
        {
            SceneRectangle circumscribingRectangle = CalculateCircumscribingRectangle();
            var            pointSceneCenter        = new ScenePoint
            {
                X = (circumscribingRectangle.Vertex1.X + circumscribingRectangle.Vertex2.X) / 2.0,
                Y = (circumscribingRectangle.Vertex1.Y + circumscribingRectangle.Vertex2.Y) / 2.0
            };

            foreach (var figure in _childFigures)
            {
                var points = figure.Points;
                GeneralMethodsFigure.ReflectFigure(orientation, pointSceneCenter, ref points);
                figure.Points = points;
            }
        }
        public void Scene_СalculateCircumscribingScene_ShouldBeСorrectСalculateСoordinates()
        {
            var commandProducer = new CommandProducer();
            var scene           = new Scene();

            commandProducer.AppendLine("add circle C1 (-1, -2) radius 3");
            var command = commandProducer.GetCommand();

            command.Apply(scene);

            commandProducer.AppendLine("add circle C2 (-7, 5) radius 1");
            command = commandProducer.GetCommand();
            command.Apply(scene);

            commandProducer.AppendLine("add polygon P1");
            commandProducer.AppendLine("add point (0, 2)");
            commandProducer.AppendLine("add point (-2, -1)");
            commandProducer.AppendLine("add point (2, -1)");
            commandProducer.AppendLine("end polygon");
            command = commandProducer.GetCommand();
            command.Apply(scene);

            commandProducer.AppendLine("add rectangle R1 (-6, 2) (-2, 7)");
            command = commandProducer.GetCommand();
            command.Apply(scene);

            commandProducer.AppendLine("group C1, P1 as G1");
            command = commandProducer.GetCommand();

            SceneRectangle sceneRectangle = scene.CalculateSceneCircumscribingRectangle();
            bool           matching       = false;

            if (EqualScenePoints(sceneRectangle.Vertex1, new ScenePoint(-8, -5)) &&
                EqualScenePoints(sceneRectangle.Vertex2, new ScenePoint(2, 7)) ||
                EqualScenePoints(sceneRectangle.Vertex1, new ScenePoint(-8, 7)) &&
                EqualScenePoints(sceneRectangle.Vertex2, new ScenePoint(2, -5)))
            {
                matching = true;
            }

            Assert.That(matching,
                        Is.True,
                        "Координаты прямоугольника, описывающего сцену, неверные");
        }
        public void Apply(Scene scene)
        {
            if (_name == "scene")
            {
                SceneRectangle ScPoint = scene.CalculateSceneCircumscribingRectangle();

                Console.WriteLine("Сoordinates сircumscribing rectangle scene" +
                                  " (" + ScPoint.Vertex1.X + ", " + ScPoint.Vertex1.Y + ") " +
                                  " (" + ScPoint.Vertex2.X + ", " + ScPoint.Vertex2.Y + ")");
            }
            else
            {
                SceneRectangle ScPoint = scene.CalculateCircumscribingRectangle(_name);

                Console.WriteLine("Сoordinates сircumscribing rectangle " + _name +
                                  " (" + ScPoint.Vertex1.X + ", " + ScPoint.Vertex1.Y + ") " +
                                  " (" + ScPoint.Vertex2.X + ", " + ScPoint.Vertex2.Y + ")");
            }
        }
Beispiel #11
0
        /* Ñalculate the rectangle that wraps current figure and has edges parallel to X and Y */
        public SceneRectangle CalculateCircumscribingRectangle()
        {
            var arrayX = new SortedSet <double> {
                _p1.X, _p2.X, _p3.X, _p4.X
            };
            var arrayY = new SortedSet <double> {
                _p1.Y, _p2.Y, _p3.Y, _p4.Y
            };

            var ñircumscribingRectangle = new SceneRectangle
            {
                Vertex1 = new ScenePoint {
                    X = arrayX.Min, Y = arrayY.Max
                },
                Vertex2 = new ScenePoint {
                    X = arrayX.Max, Y = arrayY.Min
                }
            };

            return(ñircumscribingRectangle);
        }
        public SceneRectangle CalculateCircumscribingRectangle()
        {
            var arrayX = new SortedSet <double>();
            var arrayY = new SortedSet <double>();

            foreach (var point in _points)
            {
                arrayX.Add(point.X);
                arrayY.Add(point.Y);
            }

            var ñircumscribingRectangle = new SceneRectangle
            {
                Vertex1 = new ScenePoint {
                    X = arrayX.Min, Y = arrayY.Max
                },
                Vertex2 = new ScenePoint {
                    X = arrayX.Max, Y = arrayY.Min
                }
            };

            return(ñircumscribingRectangle);
        }
Beispiel #13
0
    private IEnumerator DoGrapple(Transform grapplerTransform, Vector3 relativeTargetPos, SceneRectangle validRect)
    {
        yield return(new WaitForSeconds(Constants.grappleShootDuration));

        rbody.isKinematic = true;

        Vector3 startPos = transform.position;
        float   radius   = transform.localScale.y / 2;

        Func <Vector3> currentTargetPos = () =>
        {
            Vector3 pos = grapplerTransform.TransformPoint(relativeTargetPos);
            pos = validRect.ProjectPoint(pos, radius + 0.01f);
            // Make sure point is above ground and below ceiling
            pos.y = Mathf.Clamp(pos.y, radius, Constants.scaledCeilingHeight - radius);
            return(pos);
        };

        yield return(Util.DoAnimate(Constants.grapplePullDuration, Util.EaseOut01, t =>
        {
            Vector3 targetPos = currentTargetPos();
            targetPos.y += grappleYCurve.Evaluate(t) * Scale.gameScale;
            rbody.MovePosition(Vector3.Lerp(startPos, targetPos, t));
        }));

        // Hold in place.
        yield return(Util.DoAnimate(Constants.grappleHoldDuration, _ =>
        {
            rbody.MovePosition(currentTargetPos());
        }));

        rbody.velocity        = Vector3.zero;
        rbody.angularVelocity = Vector3.zero;

        // Go!
        rbody.isKinematic = false;
        RpcHideGrapple();
        activeGrappleCoroutine = null;
    }