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


C# Vector2.Normalize方法代码示例

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


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

示例1: Shoot

 public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
 {
     Vector2 direction = new Vector2(speedX, speedY);
     direction.Normalize();
     position += direction * item.width;
     return true;
 }
开发者ID:Eldrazi,项目名称:Pletharia,代码行数:7,代码来源:SuperSapphireStaff.cs

示例2: AngleBetween

 public static float AngleBetween(Vector2 v1, Vector2 v2)
 {
     v1.Normalize();
     v2.Normalize();
     float Angle = (float)Math.Acos(Vector2.Dot(v1, v2));
     return Angle;
 }
开发者ID:GarethIW,项目名称:TriRace,代码行数:7,代码来源:Helper.cs

示例3: DrawLightningStreak

        /// <summary>
        /// A streak of lightning is drawn simply by piecing together a long string of small line segments, 
        /// each of which is slightly rotated.
        /// </summary>
        private void DrawLightningStreak(LineBatch lineBatch, Color color, Vector2 start, Vector2 end, int numSegments,
            float deviation)
        {
            Random randomGen = new Random();

            Vector2 disp = end - start;
            Vector2 unitDisp = Vector2.Normalize(disp);
            Vector2 stepVector = unitDisp * disp.Length() / (float)numSegments;
            Vector2 perpVec = new Vector2(-stepVector.Y, stepVector.X);
            perpVec.Normalize();

            Vector2 startPoint = start;
            Vector2 endPoint = new Vector2();

            for (int i = 0; i < numSegments; ++i)
            {
                endPoint = start + stepVector * (i + 1);

                // If this is an intermediate segment, apply an offset perpendicular to the line connecting start to end.
                if (i < numSegments - 1)
                {
                    float random = (float)randomGen.NextDouble();
                    float offset = (random >= 0.5f ? 1 : -1) * random * deviation;

                    endPoint += perpVec * offset;
                }

                lineBatch.DrawLine(startPoint, endPoint, color);

                startPoint = endPoint;
            }
        }
开发者ID:zpconn,项目名称:FieldPong,代码行数:36,代码来源:LightningBox.cs

示例4: DirectionFrom

 public static Vector2 DirectionFrom(Vector2 point1, Vector2 point2, out float angle)
 {
     angle = AngleFrom(point1, point2);
     Vector2 direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
     direction.Normalize();
     return direction;
 }
开发者ID:eriksk,项目名称:Ludum-Dare-48,代码行数:7,代码来源:Utility.cs

示例5: Calculate

        public override void Calculate()
        {
            if (EnemyList.Count > 0)
            {
                Target = FindClosestEnemy();// EnemyList[0]; //TODO beregn den fysisk nermeste fiendem

                Vector2 t = new Vector2(Target.X + Target.Width/2, Target.Y + Target.Height/2);

                dir = t - Position;
                dir.Normalize();

                Angle = (float)Math.Atan2(
                          (double)dir.Y,
                          (double)dir.X);

                Position += dir * Speed;
                X = (int)Position.X;
                Y = (int)Position.Y;
            }
            else
            {
                X = (int)Position.X;
                Y = (int)Position.Y;
                Position += dir * Speed;
            }
        }
开发者ID:dosjos,项目名称:SpaceDestroyer,代码行数:26,代码来源:Rocket.cs

示例6: Act

        public override void Act(GameTime gameTime)
        {
            base.Act(gameTime);
            hitTime -= 1.0f;

            if (hitTime <= 0)
            {
                Vector2 temp = new Vector2(Owner.FaceVector.X, Owner.FaceVector.Y);
                temp.Normalize();
                ArrayList targetList = new ArrayList();
                Owner.EntitiesInRadius(50, Owner.CenterPosition + Owner.Bounds, targetList);

                for (int i = 0; i < targetList.Count; i++)
                {
                    if (targetList[i] is Player)
                    {
                        if (Owner is BigZombie)
                        {
                            ((Being)targetList[i]).Health -= 8;
                        }
                        ((Being)targetList[i]).Health -= 2;

                    }
                }
                hitTime = 5;
                //Zombie.CurrentState = new ZombieWalkState();
            }
        }
开发者ID:Bigalan09,项目名称:Zombies,代码行数:28,代码来源:ZombieHitState.cs

示例7: MoveDown

        public void MoveDown(float delta)
        {
            dir = new Vector2(0,1);

            pos = pos + dir * speed * delta;
            dir.Normalize();
        }
开发者ID:antonidag,项目名称:PacMan,代码行数:7,代码来源:PacMan.cs

示例8: FindTargets

        public override Vector2[] FindTargets(ZazumoActor zazumoActor, IEnumerable<EnemyActor> enemies)
        {
            var moveDiretion = new Vector2(zazumoActor.Location.X, zazumoActor.Location.Y) - _lastPosition;
            moveDiretion.Normalize();

            _lastPosition = new Vector2(zazumoActor.Location.X, zazumoActor.Location.Y);

            var requestedTarget = new Vector2(moveDiretion.X * -10f, moveDiretion.Y * -6f);

            if (Single.IsNaN(requestedTarget.X) || Single.IsNaN(requestedTarget.Y))
                return new Vector2[]{};

            if (_lastTarget == Vector2.Zero)
            {
                _lastTarget = requestedTarget;
                return new Vector2[] { requestedTarget };
            }
            else
            {
                _lastTarget.Normalize();
                var lastAngle = (Single)(Math.Acos(_lastTarget.X) * (_lastTarget.Y > 0 ? -1.0 : 1.0));

                requestedTarget.Normalize();
                var requestedAngle = (Single)(Math.Acos(requestedTarget.X) * (requestedTarget.Y > 0 ? -1.0 : 1.0));

                Single angle = (0.7f * lastAngle) + (0.3f * requestedAngle);

                var direction = new Vector2((Single)Math.Cos(angle), (Single)Math.Sin(angle) * -1.0f);
                direction.Normalize();
                var newtarget = new Vector2(direction.X * 10f, direction.Y * 6f);
                _lastTarget = newtarget;

                return new Vector2[] { newtarget };
            }
        }
开发者ID:HaKDMoDz,项目名称:Zazumo,代码行数:35,代码来源:StarWeapon.cs

示例9: Goalie

 public Goalie(World world, GoalieData spawn)
 {
     var body = new Body(world);
     var angle = spawn.End - spawn.Begin;
     body.Rotation = FMath.Atan2(angle.Y, angle.X);
     segment.A = spawn.Begin;
     segment.B = spawn.End;
     var normal = new Vector2(-angle.Y, angle.X);
     normal.Normalize();
     delta = normal * .5f;
     segmentOut.A = spawn.Begin + delta;
     segmentOut.B = spawn.End + delta;
     segmentIn.A = spawn.Begin - delta;
     segmentIn.B = spawn.End - delta;
     body.Position = spawn.Begin;
     var verts = new Vertices();
     verts.Add(new Vector2(left, bottom));
     verts.Add(new Vector2(right, bottom));
     verts.Add(new Vector2(right, top));
     verts.Add(new Vector2(left, top));
     var shape = new PolygonShape(verts, 1f);
     body.FixedRotation = true;
     body.BodyType = BodyType.Dynamic;
     Fixture = body.CreateFixture(shape);
 }
开发者ID:det,项目名称:Rimbalzo,代码行数:25,代码来源:Goalie.cs

示例10: Line

 public Line(int x1, int y1, int x2, int y2)
 {
     direction = new Vector2(x2-x1,y2-y1);
     worldPosition = new Vector2(x1,y1);
     normal = new Vector2(-direction.Y,direction.X);
     normal.Normalize();
 }
开发者ID:pensistudios,项目名称:Venus,代码行数:7,代码来源:Line.cs

示例11: Draw

        public void Draw(SpriteBatch spriteBatch, TrackPoint tp)
        {
            if (tp == this)
            {
                if (!drawn)
                {
                    drawn = true;
                }
                else
                {
                    drawn = false;
                    return;
                }
            }
            next.Draw(spriteBatch, tp);

            foreach (Particle p in occupying)
            {
                Vector2 shift = new Vector2(0, 1);
                shift.Normalize();
                shift *= -10 * occupying.IndexOf(p);
                Color colour = maxThroughput < 3 ? Color.Red : Color.IndianRed;
                p.Draw(spriteBatch, rotate(loc + shift, 1), colour);
            }
        }
开发者ID:kbarrett,项目名称:particle-car,代码行数:25,代码来源:TrackPoint.cs

示例12: WheelJointTest

        private WheelJointTest()
        {
            Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            {
                PolygonShape shape = new PolygonShape(1);
                shape.Vertices = PolygonTools.CreateRectangle(0.5f, 2.0f);

                Body body = new Body(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(0.0f, 7.0f);

                body.CreateFixture(shape);

                Vector2 axis = new Vector2(-1000.0f, -2.0f);
                axis.Normalize();

                WheelJoint jd = new WheelJoint(ground, body, new Vector2(0, 8.5f), axis);
                jd.MotorSpeed = 1.0f;
                jd.MaxMotorTorque = 1000.0f;
                jd.MotorEnabled = true;
                jd.SpringFrequencyHz = 1.0f;
                jd.SpringDampingRatio = 0.2f;
                World.AddJoint(jd);

                PolygonShape shape2 = new PolygonShape(1);
                shape2.Vertices = PolygonTools.CreateRectangle(0.5f, 2.0f);
                Body body2 = BodyFactory.CreatePolygon(World, shape2.Vertices, 0.5f);
                body2.BodyType = BodyType.Dynamic;
                body2.Position = new Vector2(10.0f, 7.0f);
            }
        }
开发者ID:boris2,项目名称:mmogameproject2,代码行数:32,代码来源:LineJointTest.cs

示例13: GetInletDirection

 public static Vector2 GetInletDirection(Vector2 Position)
 {
     Vector2 inletDirection = new Vector2();
     inletDirection = inletPosition - Position;
     inletDirection.Normalize();
     return inletDirection;
 }
开发者ID:BenHamrick,项目名称:Heart-Attack-2013-Game-Jam,代码行数:7,代码来源:Heart.cs

示例14: Update

        public override void Update(GameTime gameTime)
        {
            Vector2 direction = new Vector2(0, 0);

            mFixture.Body.ResetDynamics();
            mFixture.Body.LinearVelocity = new Vector2(0, 0);
            mFixture.Body.Rotation = 0;

            UpdateInput();

            //base.Update(gameTime);
            if (mControllable)
            {
                direction = DetermineDesiredDirection();

                if (direction.Length() > .065f)
                {
                    mFixture.Body.LinearVelocity = (direction * mMaxSpeed);
                }

                if (direction.Length() > 0)
                {
                    direction.Normalize();
                    mDirection = direction;
                }
            }

            mPosition = new Vector2(mFixture.Body.Position.X, mFixture.Body.Position.Y); // converts Body.Position (meters) into pixels

            UpdateAnimation(gameTime, direction);
        }
开发者ID:Danathus,项目名称:ggj-resurrection-2012,代码行数:31,代码来源:DeadPlayer.cs

示例15: update

 override public void update(float dt)
 {
     //Console.WriteLine(path.Count);
     double distance = Math.Sqrt(Math.Pow(target.hitBox.Center.X - owner.hitBox.Center.X, 2) + Math.Pow(target.hitBox.Center.Y - owner.hitBox.Center.Y, 2));
     if (distance > 50)
     {
         Vector2 attackVector = new Vector2(owner.hitBox.Center.X - target.hitBox.Center.X, owner.hitBox.Center.Y - target.hitBox.Center.Y);
         attackVector.Normalize();
         attackVector *= 50;
         attackVector.X += target.hitBox.Center.X;
         attackVector.Y += target.hitBox.Center.Y;
         Point attackPos = new Point((int)attackVector.X, (int)attackVector.Y);
         Vector2 movement = new Vector2(attackPos.X - owner.hitBox.Center.X, attackPos.Y - owner.hitBox.Center.Y);
         movement.Normalize();
         movement *= 5;
         //owner.movementIntent /= 3f;
         owner.velocity.X = movement.X;
         owner.velocity.Y = movement.Y;
         owner.isWalking = true;
         owner.setGaze(attackPos);
     }
     else
     {
         owner.setGaze(target.hitBox.Center);
         Punch punch = new Punch(owner.animationList, owner);
         if (!owner.animationList.has(punch))
         {
             owner.animationList.pushFront(punch);
         }
     }
 }
开发者ID:csalmon3,项目名称:DreamStateMachine,代码行数:31,代码来源:Aggravated.cs


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