Esempio n. 1
0
        private Hit _Detect(float scan_angle, float max_distance)
        {
            scan_angle += 360f;
            scan_angle %= 360f;
            var pos  = _Entiry.GetPosition();
            var view = Vector2.AngleToVector(scan_angle);

            //Unity Debug Code
#if UNITY_EDITOR
            UnityEngine.Debug.DrawRay(new UnityEngine.Vector3(pos.X, 0, pos.Y), new UnityEngine.Vector3(view.X, 0, view.Y), UnityEngine.Color.blue, 0.5f);
#endif

            var hit = new Hit();
            hit.HitPoint = pos + view * max_distance;
            hit.Distance = max_distance;
            foreach (var visible in _FieldOfVision)
            {
                var     mesh = StandardBehavior._BuildMesh(visible);
                float   dis;
                Vector2 normal;
                Vector2 point;
                if (RayPolygonIntersect(pos, view, mesh.Points, out dis, out point, out normal))
                {
                    if (dis < hit.Distance)
                    {
                        hit.Visible  = visible;
                        hit.HitPoint = point;
                        hit.Distance = dis;
                    }
                }
            }


            return(hit);
        }
Esempio n. 2
0
        public static bool RayPolygonIntersect(Vector2 ro, Vector2 rd, Vector2[] polygon, out float t, out Vector2 point, out Vector2 normal)
        {
            t      = float.MaxValue;
            point  = ro;
            normal = rd;

            // Comparison variables.
            float distance;
            int   crossings = 0;

            for (int j = polygon.Length - 1, i = 0; i < polygon.Length; j = i, i++)
            {
                if (RayLineIntersect(ro, rd, polygon[j], polygon[i], out distance))
                {
                    crossings++;

                    // If new intersection is closer, update variables.
                    if (distance < t)
                    {
                        t     = distance;
                        point = ro + (rd * t);

                        Vector2 edge = polygon[j] - polygon[i];
                        normal = new Vector2(-edge.Y, edge.X).GetNormalized();
                    }
                }
            }

            return(crossings > 0 && crossings % 2 == 0);
        }
Esempio n. 3
0
        private TICKRESULT _GetDistance(Guid target, out float distance)
        {
            distance = 0f;
            var entity = _FieldOfVision.Find((e) => e.Id == target);

            if (entity == null)
            {
                return(TICKRESULT.FAILURE);
            }

            var mesh = _BuildMesh(entity);

            float   dis;
            Vector2 point;
            Vector2 normal;

            if (RayPolygonIntersect(
                    _Entiry.GetPosition(),
                    Vector2.AngleToVector(_Entiry.Direction),
                    mesh.Points,
                    out dis,
                    out point,
                    out normal))
            {
                distance = dis - _Entiry.GetDetectionRange();
                return(TICKRESULT.SUCCESS);
            }
            return(TICKRESULT.FAILURE);
        }
Esempio n. 4
0
        private TICKRESULT _GetTargetAngle(Guid id, ref float angle)
        {
            var target = _Find(id);

            if (target == null)
            {
                return(TICKRESULT.FAILURE);
            }
            var position = _Entiry.GetPosition();
            var diff     = target.Position - position;
            var a        = Vector2.VectorToAngle(diff.GetNormalized());

            a += 360;
            a %= 360;

            angle = a - _Entiry.Direction;

#if UNITY_EDITOR
            var distance  = target.Position.DistanceTo(position);
            var trunForce = Vector2.AngleToVector(a);
            var forcePos  = position + trunForce * (distance);
            UnityEngine.Debug.DrawLine(new UnityEngine.Vector3(position.X, 0, position.Y), new UnityEngine.Vector3(forcePos.X, 0, forcePos.Y), UnityEngine.Color.green, _DecisionTime);
            //UnityEngine.Debug.Log("TurnDirection = " + _GoblinWisdom.TurnDirection);
#endif
            return(TICKRESULT.SUCCESS);
        }
Esempio n. 5
0
        void IStage.Enter()
        {
            _Binder.Bind <ICastSkill>(this);

            _Player.SetSkillVelocity(_Caster.GetShiftDirection(), _Caster.GetShiftSpeed());
            _Player.CastBegin(_Caster.Data.Id);

            _MoveController.Backward   = _Caster.GetBackward();
            _MoveController.Forward    = _Caster.GetForward();
            _MoveController.RunForward = _Caster.GetRunForward();
            _MoveController.TurnLeft   = _Caster.GetTurnLeft();
            _MoveController.TurnRight  = _Caster.GetTurnRight();

            _Binder.Bind <IMoveController>(_MoveController);

            if (_Caster.CanDisarm())
            {
                _Binder.Bind <IBattleSkill>(this);
            }

            _CastTimer.Reset();

            _DatumPosition = _Player.GetPosition();
            var strength = _Player.Strength(-_Caster.Data.StrengthCost);

            _Overdraft = strength < 0.0f;
        }
Esempio n. 6
0
        public PointToProcess(RegulusVector2 point)
        {
            x = point.X;
            y = point.Y;

            K        = 0;
            Distance = 0;
        }
Esempio n. 7
0
    public void SetPosision(Regulus.CustomType.Vector2 position)
    {
        _Target = new Vector2(position.X, position.Y);


        /*var scaleX = _Rect.localScale.x;
         * var scaleY = _Rect.localScale.y;
         * _Rect.anchoredPosition = new Vector2(-position.X * scaleX + Viewport.rect.width / 2, -position.Y * scaleY + Viewport.rect.height / 2);*/
    }
Esempio n. 8
0
        public void FindHullTest2()
        {
            Vector2[] points = new Vector2[]
            {
                new Vector2(303.4322f , 68.75738f),
                new Vector2(303.4522f , 68.25784f),
                new Vector2(303.9518f , 68.27787f),
                new Vector2(303.9318f ,  68.77739f),

                new Vector2(303.4328f , 68.74139f),
                new Vector2(303.4529f ,  68.24185f),
                new Vector2(303.9524f , 68.26188f),
                new Vector2(303.9324f , 68.7614f)
            };
            for (int i = 0; i < 1000000; i++)
            {
                points.FindHull().ToArray();
            }
        }
Esempio n. 9
0
        public void FindHullTest1()
        {
            Vector2[] points = new Vector2[]
            {
                new Vector2(497.5674f , 125.8552f),
                new Vector2(497.5874f , 125.3556f),
                new Vector2(498.0869f , 125.3756f),
                new Vector2(498.0669f , 125.8752f),

                new Vector2(497.5667f , 125.8711f),
                new Vector2(497.5867f , 125.3716f),
                new Vector2(498.0863f , 125.3916f),
                new Vector2(498.0663f , 125.8912f)
            };
            for (int i = 0; i < 1000000; i++)
            {
                points.FindHull().ToArray();
            }
        }
Esempio n. 10
0
        public static bool RayLineIntersect(Vector2 ro, Vector2 rd, Vector2 l1, Vector2 l2, out float t)
        {
            Vector2 seg     = l2 - l1;
            Vector2 segPerp = new Vector2(seg.Y, -seg.X);


            float perpDotd = rd.DotProduct(segPerp);

            // If lines are parallel, return false.
            if (Math.Abs(perpDotd) <= float.Epsilon)
            {
                t = float.MaxValue;
                return(false);
            }

            Vector2 d = l1 - ro;


            t = segPerp.DotProduct(d) / perpDotd;
            float s = new Vector2(rd.Y, -rd.X).DotProduct(d) / perpDotd;

            // If intersect is in right direction and in segment bounds, return true.
            return(t >= 0.0f && s >= 0.0f && s <= 1.0f);
        }
 private static void _Draw(Vector2[] points, int i)
 {
     var p1 = new UnityEngine.Vector3(points[i].X, 0, points[i].Y);
     var p2 = new UnityEngine.Vector3(points[i + 1].X, 0, points[i + 1].Y);
     Debug.DrawLine(p1, p2);
 }
        public static bool RayPolygonIntersect(Vector2 ro, Vector2 rd, Vector2[] polygon, out float t, out Vector2 point, out Vector2 normal)
        {
            t = float.MaxValue;
            point = ro;
            normal = rd;

            // Comparison variables.
            float distance;
            int crossings = 0;

            for (int j = polygon.Length - 1, i = 0; i < polygon.Length; j = i, i++)
            {
                if (RayLineIntersect(ro, rd, polygon[j], polygon[i], out distance))
                {
                    crossings++;

                    // If new intersection is closer, update variables.
                    if (distance < t)
                    {
                        t = distance;
                        point = ro + (rd * t);

                        Vector2 edge = polygon[j] - polygon[i];
                        normal = new Vector2(-edge.Y, edge.X).GetNormalized();
                    }
                }
            }

            return crossings > 0 && crossings % 2 == 0;
        }
        public static bool RayLineIntersect(Vector2 ro, Vector2 rd, Vector2 l1, Vector2 l2, out float t)
        {
            Vector2 seg = l2 - l1;
            Vector2 segPerp = new Vector2(seg.Y, -seg.X);

            float perpDotd = rd.DotProduct(segPerp);

            // If lines are parallel, return false.
            if (Math.Abs(perpDotd) <= float.Epsilon)
            {
                t = float.MaxValue;
                return false;
            }

            Vector2 d = l1 - ro;

            t = segPerp.DotProduct(d) / perpDotd;
            float s = new Vector2(rd.Y, -rd.X).DotProduct(d) / perpDotd;

            // If intersect is in right direction and in segment bounds, return true.
            return t >= 0.0f && s >= 0.0f && s <= 1.0f;
        }
Esempio n. 14
0
 private void _SetPosition(Vector2 position)
 {
     var pos = new Vector3(position.X, 0, position.Y);
     _SetPosition(pos);
 }
        void IStage.Enter()
        {
            _Binder.Bind<ICastSkill>(this);
            _Player.SetSkillVelocity(_Caster.GetShiftDirection(), _Caster.GetShiftSpeed());
            _Player.CastBegin(_Caster.Data.Id);

            _MoveController.Backward = _Caster.GetBackward();
            _MoveController.Forward = _Caster.GetForward();
            _MoveController.RunForward = _Caster.GetRunForward();
            _MoveController.TurnLeft = _Caster.GetTurnLeft();
            _MoveController.TurnRight = _Caster.GetTurnRight();

            _Binder.Bind<IMoveController>(_MoveController);

            if (_Caster.CanDisarm())
            {
                _Binder.Bind<IBattleSkill>(this);
            }

            _CastTimer.Reset();

            _DatumPosition = _Player.GetPosition();
            var strength = _Player.Strength(-_Caster.Data.StrengthCost);
            _Overdraft = strength < 0.0f;
        }
        public static void _DrawAll(Vector2[] left, Vector2[] right, UnityEngine.Vector3 center, UnityEngine.Color color)
        {
            for (int i = 0; i < left.Length - 1; i++)
            {
                var pos1 = center + new UnityEngine.Vector3(left[i].X,0, left[i].Y);
                var pos2 = center + new UnityEngine.Vector3(left[i + 1].X, 0, left[i + 1].Y);
                UnityEngine.Debug.DrawLine(pos1, pos2, color);
            }

            for (int i = 0; i < right.Length - 1; i++)
            {
                var pos1 = center + new UnityEngine.Vector3(right[i].X, 0, right[i].Y);
                var pos2 = center + new UnityEngine.Vector3(right[i + 1].X, 0, right[i + 1].Y);
                UnityEngine.Debug.DrawLine(pos1, pos2, color);
            }
        }
Esempio n. 17
0
    private void _SetPosition(Vector2 position)
    {
        var pos = new Vector3(position.X, 0, position.Y);

        _SetPosition(pos);
    }
        public PointToProcess(RegulusVector2 point)
        {
            x = point.X;
            y = point.Y;

            K = 0;
            Distance = 0;
        }
Esempio n. 19
0
        public void TestSerializerVector2()
        {
            var v = new Regulus.CustomType.Vector2(99, 22);

            var array = Regulus.TypeHelper.Serializer(v);
            var v2 = Regulus.TypeHelper.Deserialize<Regulus.CustomType.Vector2>(array);

            Assert.AreEqual(99 , v2.X);
            Assert.AreEqual(22, v2.Y);
        }