当前位置: 首页>>代码示例>>C#>>正文


C# Vector2.Normalize方法代码示例

本文整理汇总了C#中System.Vector2.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2.Normalize方法的具体用法?C# Vector2.Normalize怎么用?C# Vector2.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Vector2的用法示例。


在下文中一共展示了Vector2.Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetPoints

        public List<Vector2> GetPoints()
        {
            //构造OBB
            //body的方向
            Vector2 bodyDir = direction;
            if (bodyDir != Vector2.Zero)
                bodyDir.Normalize();
            //body的方向 的垂直方向
            Vector2 bodyDirC = new Vector2(bodyDir.Y, -bodyDir.X);
            if (bodyDirC != Vector2.Zero)
                bodyDirC.Normalize();

            Vector2 point1 = bodyDir * height + bodyDirC * width + center;
            Vector2 point2 = bodyDir * height + -bodyDirC * width + center;
            Vector2 point3 = -bodyDir * height + -bodyDirC * width + center;
            Vector2 point4 = -bodyDir * height + bodyDirC * width + center;

            List<Vector2> points = new List<Vector2>();
            points.Add(point1);
            points.Add(point2);
            points.Add(point3);
            points.Add(point4);

            return points;
        }
开发者ID:PssProgram,项目名称:Lost-In-Trek,代码行数:25,代码来源:OBB.cs

示例2: TickCore

        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cooldown;
            if (state == null) cooldown = 1000;
            else cooldown = (int)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            var player = (Player)host.GetNearestEntity(distance, null);
            if (player != null)
            {
                Vector2 vect;
                vect = new Vector2(player.X - host.X, player.Y - host.Y);
                vect.Normalize();
                float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                host.ValidateAndMove(host.X + (-vect.X) * dist, host.Y + (-vect.Y) * dist);
                host.UpdateCount++;

                if (cooldown <= 0)
                {
                    Status = CycleStatus.Completed;
                    cooldown = 1000;
                }
                else
                {
                    Status = CycleStatus.InProgress;
                    cooldown -= time.thisTickTimes;
                }
            }

            state = cooldown;
        }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:34,代码来源:StayBack.cs

示例3: TickCore

        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if (!returned)
            {
                if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) return;
                var spd = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);

                Position pos = (host as Enemy).SpawnPoint;
                var tx = pos.X;
                var ty = pos.Y;
                if (Math.Abs(tx - host.X) > 1 || Math.Abs(ty - host.Y) > 1)
                {
                    var x = host.X;
                    var y = host.Y;
                    Vector2 vect = new Vector2(tx, ty) - new Vector2(host.X, host.Y);
                    vect.Normalize();
                    vect *= spd;
                    host.Move(host.X + vect.X, host.Y + vect.Y);
                    host.UpdateCount++;
                }

                if (host.X == pos.X && host.Y == pos.Y && once)
                {
                    once = true;
                    returned = true;
                }
            }
        }
开发者ID:OryxAwakening,项目名称:Fabiano_Swagger_of_Doom,代码行数:28,代码来源:ReturnToSpawn.cs

示例4: TickCore

        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed*GetSpeedMultiplier(Host.Self);

            var dist = radius;
            var entity = GetNearestEntity(ref dist, objType);
            if (entity != null && dist > targetRadius)
            {
                var tx = entity.X + rand.Next(-2, 2)/2f;
                var ty = entity.Y + rand.Next(-2, 2)/2f;
                if (tx != Host.Self.X || ty != Host.Self.Y)
                {
                    var x = Host.Self.X;
                    var y = Host.Self.Y;
                    var vect = new Vector2(tx, ty) - new Vector2(Host.Self.X, Host.Self.Y);
                    vect.Normalize();
                    vect *= (speed/1.5f)*(time.thisTickTimes/1000f);
                    ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                    Host.Self.UpdateCount++;
                }
                return true;
            }
            return false;
        }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:25,代码来源:Chasing.cs

示例5: Normalize

 /// <summary>
 /// 标准化
 /// </summary>
 public static void Normalize(ref Vector2 v2)
 {
     if(v2 != Vector2.Zero)
     {
         v2 = v2.Normalize();
     }
 }
开发者ID:PssProgram,项目名称:Lost-In-Trek,代码行数:10,代码来源:Maths.cs

示例6: UpdatePoints

        private void UpdatePoints()
        {
            // compute line points
            Vector2 lineVector = point2 - point1;
            // get the right vector of the line
            Vector2 right = new Vector2(-lineVector.Y, lineVector.X);
            right.Normalize();

            Vector2 leftStart = point1 + right * -lineWidth/2f;
            Vector2 rightStart = point1 + right * lineWidth/2f;

            Vector2 leftEnd = point2 + right * -lineWidth/2f;
            Vector2 rightEnd = point2 + right * lineWidth/2f;

            this.v = new float[]
            {
                leftStart.X, leftStart.Y,
                rightStart.X, rightStart.Y,
                leftEnd.X, leftEnd.Y,
                rightStart.X, rightStart.Y,
                rightEnd.X,rightEnd.Y,
                leftEnd.X, leftEnd.Y
            };
            this.UpdateVertex();
        }
开发者ID:aiv01,项目名称:aiv-fast2d,代码行数:25,代码来源:Segment.cs

示例7: SeaLink

        // TODO: Figure out light stuffs
        public SeaLink(float x, float y, float babies, Vector2 offset)
            : base(x - offset.X, y - offset.Y, 4, 1.0f)
        {
            // Initialize sprite
            sprite.CenterOrigin();
            Graphic = sprite;

            this.babies = babies;

            dirStepAmount = 1.3f;

            // Set up colliders
            SetHitbox(28, 28, (int)Tags.ENEMY);
            personalSpace = new CircleCollider((int)(spaceAmount * 0.5), (int)Tags.SEALINK, (int)Tags.ENEMYATTACK);
            AddCollider(personalSpace);

            if (offset == Vector2.Zero) {
                velocity = new Vector2(0, speed);
                velocity = Util.Rotate(velocity, Rand.Angle);
            } else {
                velocity = offset;
                velocity.Normalize();
                velocity = Util.Rotate(velocity, 4);
            }

            sprite.Scale = 0.1f;
        }
开发者ID:amiruqdah,项目名称:ToFightTheSea,代码行数:28,代码来源:SeaLink.cs

示例8: reset

 /// <summary>
 /// Cargar valores iniciales del interpolador
 /// </summary>
 public void reset()
 {
     dir = end - init;
     distanceToTravel = dir.Length();
     dir.Normalize(); 
     current = init;
 }
开发者ID:aniPerezG,项目名称:barbalpha,代码行数:10,代码来源:Position2dInterpolator.cs

示例9: Vector2ToRadians

 public static float Vector2ToRadians(Vector2 velocity)
 {
     velocity.Normalize();
       //  float t1 = (float)Math.Acos(velocity.X / Math.Sqrt(velocity.X * velocity.X + velocity.Y * velocity.Y));
     float t1 = (float)Math.Atan2(velocity.Y, velocity.X);
     return t1;
 }
开发者ID:mokujin,项目名称:DN,代码行数:7,代码来源:FunctionHelper.cs

示例10: TickCore

        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed * GetSpeedMultiplier(Host.Self);

            float dist = radius;
            Entity entity = GetNearestEntity(ref dist, objType);
            Character chr = Host as Character;
            if (entity != null && chr.HP < threshold)
            {
                var x = Host.Self.X;
                var y = Host.Self.Y;
                Vector2 vect = new Vector2(entity.X, entity.Y) - new Vector2(Host.Self.X, Host.Self.Y);
                vect.Normalize();
                vect *= -1 * (speed / 1.5f) * (time.thisTickTimes / 1000f);
                ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                Host.Self.UpdateCount++;

                if (!Host.StateStorage.ContainsKey(Key))
                {
                    chr.Owner.BroadcastPacket(new ShowEffectPacket()
                    {
                        EffectType = EffectType.Flashing,
                        PosA = new Position() { X = 1, Y = 1000000 },
                        TargetId = chr.Id,
                        Color = new ARGB(0xff303030)
                    }, null);
                    Host.StateStorage[Key] = true;
                }

                return true;
            }
            else return false;
        }
开发者ID:rotmgkillroyx,项目名称:rotmg_svr_OLD,代码行数:34,代码来源:Escaping.cs

示例11: TickCore

        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            var s = (OrbitState) state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            Entity entity = host.GetNearestEntity(acquireRange, target);
            if (entity != null)
            {
                double angle;
                if (host.Y == entity.Y && host.X == entity.X) //small offset
                    angle = Math.Atan2(host.Y - entity.Y + (Random.NextDouble()*2 - 1),
                        host.X - entity.X + (Random.NextDouble()*2 - 1));
                else
                    angle = Math.Atan2(host.Y - entity.Y, host.X - entity.X);
                float angularSpd = host.GetSpeed(s.Speed)/s.Radius;
                angle += angularSpd*(time.thisTickTimes/1000f);

                double x = entity.X + Math.Cos(angle)*radius;
                double y = entity.Y + Math.Sin(angle)*radius;
                Vector2 vect = new Vector2((float) x, (float) y) - new Vector2(host.X, host.Y);
                vect.Normalize();
                vect *= host.GetSpeed(s.Speed)*(time.thisTickTimes/1000f);

                host.ValidateAndMove(host.X + vect.X, host.Y + vect.Y);
                host.UpdateCount++;

                Status = CycleStatus.InProgress;
            }

            state = s;
        }
开发者ID:Club559,项目名称:Travs-Domain-Server,代码行数:34,代码来源:Orbit.cs

示例12: GetLengthAndNormalize

		public void GetLengthAndNormalize()
		{
			Vector2 Point3 = new Vector2(3, -4);
			Assert.IsTrue(Point3.Length > 4.999f && Point3.Length < 5.001f);

			Point3.Normalize();
			Assert.IsTrue(Point3.Length > 0.99f && Point3.Length < 1.01f);
		}
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:8,代码来源:Vector2DTests.cs

示例13: HandleImpostorInput

        public void HandleImpostorInput()
        {
            Vector2 impostorMove = new Vector2(X, Y);
            impostorMove -= new Vector2(Global.theGhost.X + (float)Math.Sin(Y * X) * 50, Global.theGhost.Y + (float)Math.Sin(Y * X*X) * 50);
            impostorMove.Normalize();
            MoveInDirection(-impostorMove);

            ShootInDirection(impostorMove);
        }
开发者ID:DrMelon,项目名称:UltimateDiscordInfinity,代码行数:9,代码来源:Ghost.cs

示例14: Projectile

 public Projectile(float x, float y, Vector2 direction, float speed, int radius, float lifespan, int damage, params int[] tags)
     : base(x, y)
 {
     direction.Normalize();
     this.velocity = direction * speed;
     this.lifespan = lifespan;
     Collider = new CircleCollider(radius, tags);
     Collider.CenterOrigin();
     this.damage = damage;
 }
开发者ID:amiruqdah,项目名称:ToFightTheSea,代码行数:10,代码来源:Projectile.cs

示例15: Tangent

        public override Vector2 Tangent(float t)
        {
            var tx = Curve2d.TangentQuadraticBezier(t, v0.x, v1.x, v2.x);
            var ty = Curve2d.TangentQuadraticBezier(t, v0.y, v1.y, v2.y);

            // returns unit vector
            var tangent = new Vector2(tx, ty);
            tangent.Normalize();
            return tangent;
        }
开发者ID:prepare,项目名称:three.net,代码行数:10,代码来源:QuadraticBezierCurve.cs


注:本文中的System.Vector2.Normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。