コード例 #1
0
ファイル: Vector2UtilTests.cs プロジェクト: MetaIdea/OpenSAGE
        public void RotationAroundItselfIsIdentity()
        {
            var point   = new Vector2(2, 2);
            var rotated = Vector2Utility.RotateAroundPoint(point, point, MathUtility.PiOver2);

            VectorsEqual(point, rotated, 3);
        }
コード例 #2
0
ファイル: Vector2UtilTests.cs プロジェクト: MetaIdea/OpenSAGE
        public void RotationByZeroIsIdentity()
        {
            var axis    = Vector2.Zero;
            var point   = new Vector2(1, 0);
            var rotated = Vector2Utility.RotateAroundPoint(axis, point, 0);

            VectorsEqual(point, rotated, 3);
        }
コード例 #3
0
ファイル: Vector2UtilTests.cs プロジェクト: MetaIdea/OpenSAGE
        public void RotationBy2PiIsIdentity()
        {
            var axis    = Vector2.Zero;
            var point   = new Vector2(30, 30);
            var rotated = Vector2Utility.RotateAroundPoint(axis, point, MathUtility.TwoPi);

            VectorsEqual(point, rotated, 3);
        }
コード例 #4
0
ファイル: Vector2UtilTests.cs プロジェクト: MetaIdea/OpenSAGE
        [InlineData(0, 0, 0, 1, -1.5708f, 1, 0)] // 90 degrees counter-clockwise
        public void RotationTheory(float axisX, float axisY, float pointX, float pointY, float angle, float resultX, float resultY)
        {
            var axis     = new Vector2(axisX, axisY);
            var point    = new Vector2(pointX, pointY);
            var expected = new Vector2(resultX, resultY);
            var rotated  = Vector2Utility.RotateAroundPoint(axis, point, angle);

            VectorsEqual(expected, rotated, 3);
        }
コード例 #5
0
ファイル: Vector2UtilTests.cs プロジェクト: MetaIdea/OpenSAGE
        public void RotationForwardsAndBackwardsIsIdentity()
        {
            var axis  = Vector2.Zero;
            var point = new Vector2(1, 3);

            var rotatedCw  = Vector2Utility.RotateAroundPoint(axis, point, 0.3f);
            var rotatedCcw = Vector2Utility.RotateAroundPoint(axis, rotatedCw, -0.3f);

            VectorsEqual(point, rotatedCcw, 3);
        }
コード例 #6
0
ファイル: Tornado.cs プロジェクト: potsh/RimWorld
        private void DoDamage(IntVec3 c, float damageFactor)
        {
            tmpThings.Clear();
            tmpThings.AddRange(c.GetThingList(base.Map));
            Vector3 vector = c.ToVector3Shifted();
            float   num    = 0f - Vector2Utility.AngleTo(b: new Vector2(vector.x, vector.z), a: realPosition) + 180f;

            for (int i = 0; i < tmpThings.Count; i++)
            {
                BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null;
                switch (tmpThings[i].def.category)
                {
                case ThingCategory.Pawn:
                {
                    Pawn pawn = (Pawn)tmpThings[i];
                    battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Tornado);
                    Find.BattleLog.Add(battleLogEntry_DamageTaken);
                    if (pawn.RaceProps.baseHealthScale < 1f)
                    {
                        damageFactor *= pawn.RaceProps.baseHealthScale;
                    }
                    if (pawn.RaceProps.Animal)
                    {
                        damageFactor *= 0.75f;
                    }
                    if (pawn.Downed)
                    {
                        damageFactor *= 0.2f;
                    }
                    break;
                }

                case ThingCategory.Building:
                    damageFactor *= 0.8f;
                    break;

                case ThingCategory.Item:
                    damageFactor *= 0.68f;
                    break;

                case ThingCategory.Plant:
                    damageFactor *= 1.7f;
                    break;
                }
                int       num2           = Mathf.Max(GenMath.RoundRandom(30f * damageFactor), 1);
                Thing     thing          = tmpThings[i];
                DamageDef tornadoScratch = DamageDefOf.TornadoScratch;
                float     amount         = (float)num2;
                float     angle          = num;
                thing.TakeDamage(new DamageInfo(tornadoScratch, amount, 0f, angle, this)).AssociateWithLog(battleLogEntry_DamageTaken);
            }
            tmpThings.Clear();
        }
コード例 #7
0
        public void Process()
        {
            Vector2 value = Get2DValue();

            if (!Vector2Utility.Approximately(value, _priorValue))
            {
                if (AxisMove2D != null)
                {
                    AxisMove2D(_inputDescription.InputName, value);
                }
            }

            _priorValue = value;
        }
コード例 #8
0
        public static TextureCoordinates Curve(float y, float halfRoadWidth, float angle)
        {
            var topLeft    = new Vector2(0, y - halfRoadWidth);
            var bottomLeft = new Vector2(0, y + halfRoadWidth);

            var radius      = 10f / 3f * halfRoadWidth;
            var center      = new Vector2(0, y - radius);
            var topRight    = Vector2Utility.RotateAroundPoint(center, topLeft, angle);
            var bottomRight = Vector2Utility.RotateAroundPoint(center, bottomLeft, angle);

            return(new TextureCoordinates(
                       topLeft,
                       topRight,
                       bottomLeft,
                       bottomRight));
        }
コード例 #9
0
        /// <summary>
        /// Update the position of the pointer
        /// </summary>
        /// <param name="objScreenPos">
        /// The position of the target object in the screen space
        /// </param>
        private void UpdatePointer(Vector3 objScreenPos)
        {
            if (objScreenPos.z > 0 && _indicatorPositionBorder.Contains(objScreenPos))
            {
                _pointerObject.gameObject.SetActive(false);
                return;
            }

            var degree =
                Vector2Utility.GetVectorSignedDegree(objScreenPos - _indicatorObject.position);
            var localPosition =
                Vector2Utility.GetCirclePosition(Vector2.zero, _pointerObjectRadius, degree);

            _pointerObject.gameObject.SetActive(true);
            _pointerObject.localPosition = localPosition;
            _pointerObject.rotation      = Quaternion.Euler(0, 0, degree);
        }
コード例 #10
0
        public static TextureCoordinates Curve(float v, float halfRoadWidth, float radiusInHalfRoadWidths)
        {
            var angle            = MathF.PI / 6f;
            var radius           = radiusInHalfRoadWidths * halfRoadWidth;
            var cosine           = MathF.Cos(angle / 2f);
            var additionalRadius = (radius + halfRoadWidth) * (1f - cosine) / cosine;
            var uStart           = 0f;

            var center = new Vector2(uStart, v - radius);

            var topLeft    = new Vector2(uStart, v - halfRoadWidth);
            var bottomLeft = new Vector2(uStart, v + halfRoadWidth + additionalRadius);

            var topRight    = Vector2Utility.RotateAroundPoint(center, topLeft, -angle);
            var bottomRight = Vector2Utility.RotateAroundPoint(center, bottomLeft, -angle);

            return(new TextureCoordinates(
                       topLeft,
                       topRight,
                       bottomLeft,
                       bottomRight));
        }