當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。