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


C# Vector2.Length方法代码示例

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


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

示例1: AddWall

 public void AddWall(Vector2 p1, Vector2 p2)
 {
     double angle1, angle2;
     angle1 = Math.Atan2(p1.Y, p1.X);
     angle2 = Math.Atan2(p2.Y, p2.X);
     double adiff = angle2 - angle1;
     if (adiff < 0) adiff += Math.PI * 2.0;
     if (adiff > Math.PI)
     {
         Vector2 tmp = p2; p2 = p1; p1 = tmp;
         double tmp2 = angle1; angle1 = angle2; angle2 = tmp2;
     }
     if (angle1 < 0) angle1 += Math.PI * 2.0;
     if (angle2 < 0) angle2 += Math.PI * 2.0;
     if (angle2 < angle1)
     {
         float tmp = getinetersecty0(p1, p2);
         addit(tmp, 0.0f, p2.Length(), (float)angle2);
         addit(p1.Length(), (float)angle1, tmp, (float)Math.PI * 2.0f);
     }
     else
     {
         addit(p1.Length(), (float)angle1, p2.Length(), (float)angle2);
     }
 }
开发者ID:blmarket,项目名称:lib4bpp,代码行数:25,代码来源:Shadow.cs

示例2: FromCartesian

        /// <summary>
        /// Converts a Cartesian x-, y- coordinate pair to polar coordinates.
        /// </summary>
        /// <param name="cartesian"></param>
        /// <returns></returns>
        public static PolarCoordinate FromCartesian(Vector2 cartesian)
        {
            float angle = (float)Math.Atan2(cartesian.Y, cartesian.X);
            float distance = cartesian.Length();

            return new PolarCoordinate(angle, distance);
        }
开发者ID:yadiate,项目名称:MonoGameGui,代码行数:12,代码来源:PolarCoordinate.cs

示例3: Vector2_CalculatesLengthCorrectly

        public void Vector2_CalculatesLengthCorrectly()
        {
            var vector = new Vector2(123.4f, 567.8f);

            TheResultingValue(vector.Length()).WithinDelta(0.1f)
                .ShouldBe((float)Math.Sqrt((123.4f * 123.4f) + (567.8f * 567.8f)));
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:7,代码来源:Vector2Tests.cs

示例4: 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

示例5: IsInBounds

 protected override bool IsInBounds(int x, int y)
 {
     int cx = X + radius;
     int cy = Y + radius;
     Vector2 d = new Vector2(x - cx, y - cy);
     return d.Length() <= Radius;
 }
开发者ID:yuri410,项目名称:lrvbsvnicg,代码行数:7,代码来源:RoundButton.cs

示例6: run

        public void run(float deltaTime)
        {
            Vector3 rotation = tankHead.Rotation;
            float barrelRotation = tankHead.BarrelRotation;

            Vector3 targetVector = TurretManager.ManagedTurrets[0].Location - tankHead.Location;
            rotation.X = (float)Math.Atan2(targetVector.X, targetVector.Z);
            tankHead.Rotation = rotation;

            Vector2 distanceXZ = new Vector2(targetVector.X, targetVector.Z);
            tankHead.BarrelRotation = (float)Math.Atan2(distanceXZ.Length(), targetVector.Y);
        }
开发者ID:newgrounds,项目名称:Clear-Skies,代码行数:12,代码来源:TankHeadRotationScript.cs

示例7: Update

		protected override void Update(TimeSpan gameTime)
		{
			var impulse = new Vector2();

			impulse = Behaviors.Aggregate(impulse, (current, behavior) => behavior.Apply(current));

			if (impulse.Length() > MaxImpulseLength)
			{
				impulse.Normalize();
				impulse = impulse*MaxImpulseLength;
			}

			RigidBody.ApplyLinearImpulse(new Vector3(impulse.X, 0, impulse.Y));
		}
开发者ID:JacobRichardt,项目名称:PolkaDotted.FlyOrDie,代码行数:14,代码来源:CreatureBehavior.cs

示例8: GenerateRandomPosition

        //Genero posicion aleatoria para el asteoride.
        public void GenerateRandomPosition()
        {
            Random rnd = new Random();

            //Determina de que lado de la pantalla aparece
            int lado = (int)(rnd.NextDouble() * 2);
            if( lado == 0)
                Position.X = 0;
            else
                Position.X = GameManager.ScreenWidth;

            Position.Y = GameManager.ScreenHeight * (float)rnd.NextDouble();

            //Busco el angulo del asteroide para que vaya al centro de la pantalla.
            Vector2 ScreenCenterVector = new Vector2();
            Vector2 ScreenCenter = new Vector2(GameManager.ScreenWidth / 2, GameManager.ScreenHeight / 2);
            ScreenCenterVector = Vector2.Subtract(ScreenCenter, Position);

            if (ScreenCenterVector.Length() > 0)
                angle = (float)Math.Atan2(ScreenCenterVector.Y, ScreenCenterVector.X);
        }
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:22,代码来源:Asteroide.cs

示例9: Update

        public void Update()
        {
            const float radialMenuYOffset = 0.17f;
            const float radialMenuInnerRadius = 0.23f;
            const int numberOfSectors = 8;
            const int sectorSize = 360 / numberOfSectors;

            var deltaVector = new Vector2(_tobiiTracker.GazeX * _tobiiTracker.AspectRatio, (float)(_tobiiTracker.GazeY + radialMenuYOffset));
            if (deltaVector.Length() < radialMenuInnerRadius) return;

            var angleRad = (float)Math.Atan2(-deltaVector.Y, deltaVector.X);
            var angleDeg = Mathf.Rad2Deg * angleRad;
            var region = (int)Math.Floor(360 + angleDeg + sectorSize * 0.5) / sectorSize;
            region = region % numberOfSectors;
            if (region < 0) region += numberOfSectors;

            if (_lastRadialMenuRegion == region)
            {
                _newRadialMenuRegionStopwatch.Reset();
            }
            else
            {
                _newRadialMenuRegionStopwatch.Start();
            }
            var switchTime = TimeSpan.FromMilliseconds(60);
            if (_newRadialMenuRegionStopwatch.Elapsed > switchTime)
            {
                _lastRadialMenuRegion = region;
                _newRadialMenuRegionStopwatch.Reset();
            }

            if (_lastRadialMenuRegion < 0) return;
            var alpha = Mathf.Deg2Rad * (_lastRadialMenuRegion * sectorSize);
            var freelookDeltaVector = new Vector2((float)(Math.Cos(alpha)), (float)(-Math.Sin(alpha)));
            const double rotationalSpeed = 1;
            _controllerEmulation.DeltaX = freelookDeltaVector.X * rotationalSpeed;
            _controllerEmulation.DeltaY = freelookDeltaVector.Y * rotationalSpeed;
        }
开发者ID:alex8b,项目名称:gta5eyetracking,代码行数:38,代码来源:RadialMenu.cs

示例10: Process

        public void Process(Vector2 gazeNormalizedCenterDelta, double aspectRatio)
        {
            const double radialMenuYOffset = 0.17;
            const double radialMenuInnerRadius = 0.23;
            const int numberOfSectors = 8;
            const int sectorSize = 360 / numberOfSectors;

            var deltaVector = new Vector2((float)(gazeNormalizedCenterDelta.X * aspectRatio), (float)(gazeNormalizedCenterDelta.Y + radialMenuYOffset));
            if (deltaVector.Length() < radialMenuInnerRadius) return;

            var angleRad = Math.Atan2(-deltaVector.Y, deltaVector.X);
            var angleDeg = Geometry.RadToDeg(angleRad);
            var region = (int)Math.Floor(360 + angleDeg + sectorSize * 0.5) / sectorSize;
            region = region % numberOfSectors;
            if (region < 0) region += numberOfSectors;

            if (_lastRadialMenuRegion == region)
            {
                _newRadialMenuRegionStopwatch.Reset();
            }
            else
            {
                _newRadialMenuRegionStopwatch.Start();
            }
            var switchTime = TimeSpan.FromMilliseconds(60);
            if (_newRadialMenuRegionStopwatch.Elapsed > switchTime)
            {
                _lastRadialMenuRegion = region;
                _newRadialMenuRegionStopwatch.Reset();
            }

            if (_lastRadialMenuRegion < 0) return;
            var alpha = Geometry.DegToRad(_lastRadialMenuRegion * sectorSize);
            var freelookDeltaVector = new Vector2((float)(Math.Cos(alpha)), (float)(-Math.Sin(alpha)));
            const double rotationalSpeed = 1;
            _controllerEmulation.DeltaX = freelookDeltaVector.X * rotationalSpeed;
            _controllerEmulation.DeltaY = freelookDeltaVector.Y * rotationalSpeed;
        }
开发者ID:Guad,项目名称:gta5eyetracking,代码行数:38,代码来源:RadialMenu.cs

示例11: HandleInput

        /// <summary>
        /// Handling scrollbar's input
        /// </summary>
        /// <param name="input"></param>
        /// <param name="hasKeyboardActiveControl"></param>
        /// <param name="hasKeyboardActiveControlPrevious"></param>
        /// <param name="receivedFocusInThisUpdate"></param>
        /// <returns></returns>
        public bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captureInput = false;
            // still scrolling
            if (IsScrolling() && input.IsLeftMousePressed())
            {
                if (m_mouseLastPosition != null)
                {
                    Vector2 distance = new Vector2(0.0f, 0.0f);
                    Vector2 sliderDistanceFromLastUpdate = MyGuiManager.MouseCursorPosition - m_mouseLastPosition.Value;
                    switch (m_scrollDirection)
                    {
                        case MyScrollDirection.Horizontal:
                            distance.X = sliderDistanceFromLastUpdate.X;
                            break;
                        case MyScrollDirection.Vertical:
                            distance.Y = sliderDistanceFromLastUpdate.Y;
                            break;
                    }
                    if (distance.Length() > 0.00001f)
                    {
                        Vector2 newScrollSliderPosition = m_scrollSliderPosition + distance;
                        FixScrollSliderPosition(ref newScrollSliderPosition);

                        if (newScrollSliderPosition != m_scrollSliderPosition)
                        {                            
                            SetScrollSliderPosition(newScrollSliderPosition);
                            m_mouseLastPosition = MyGuiManager.MouseCursorPosition;
                        }

                    }
                    captureInput = true;
                }
            }
            // start scrolling
            else if (!IsScrolling() && input.IsNewLeftMousePressed() && IsMouseOverScrollSlider())
            {
                m_isScrollSliderDragging = true;
                m_mouseLastPosition = MyGuiManager.MouseCursorPosition;
                captureInput = true;
            }
            // no scrolling
            else
            {
                m_mouseLastPosition = null;
                m_isScrollSliderDragging = false;
            }

            return captureInput;
        }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:58,代码来源:MyGuiControlListboxScrollBar.cs

示例12: TestStaticFn_Length_i

        public void TestStaticFn_Length_i ()
        {
            Vector2 a = new Vector2(3, -4);

            Double expected = 5;

            Double result = a.Length();

            Assert.That(result, Is.EqualTo(expected));
        }
开发者ID:sungiant,项目名称:abacus,代码行数:10,代码来源:Abacus.Double.Tests.cs

示例13: InitVelocityConstraints

        internal override void InitVelocityConstraints(ref SolverData data)
        {
            _indexA = BodyA.IslandIndex;
            _indexB = BodyB.IslandIndex;
            _localCenterA = BodyA._sweep.LocalCenter;
            _localCenterB = BodyB._sweep.LocalCenter;
            _invMassA = BodyA._invMass;
            _invMassB = BodyB._invMass;
            _invIA = BodyA._invI;
            _invIB = BodyB._invI;

            Vector2 cA = data.positions[_indexA].c;
            float aA = data.positions[_indexA].a;
            Vector2 vA = data.velocities[_indexA].v;
            float wA = data.velocities[_indexA].w;

            Vector2 cB = data.positions[_indexB].c;
            float aB = data.positions[_indexB].a;
            Vector2 vB = data.velocities[_indexB].v;
            float wB = data.velocities[_indexB].w;

            Rot qA = new Rot(aA), qB = new Rot(aB);

            _rA = MathUtils.Mul(qA, LocalAnchorA - _localCenterA);
            _rB = MathUtils.Mul(qB, LocalAnchorB - _localCenterB);
            _u = cB + _rB - cA - _rA;

            _length = _u.Length();

            float C = _length - MaxLength;
            if (C > 0.0f)
            {
                State = LimitState.AtUpper;
            }
            else
            {
                State = LimitState.Inactive;
            }

            if (_length > Settings.LinearSlop)
            {
                _u *= 1.0f / _length;
            }
            else
            {
                _u = Vector2.Zero;
                _mass = 0.0f;
                _impulse = 0.0f;
                return;
            }

            // Compute effective mass.
            float crA = MathUtils.Cross(_rA, _u);
            float crB = MathUtils.Cross(_rB, _u);
            float invMass = _invMassA + _invIA * crA * crA + _invMassB + _invIB * crB * crB;

            _mass = invMass != 0.0f ? 1.0f / invMass : 0.0f;

            if (Settings.EnableWarmstarting)
            {
                // Scale the impulse to support a variable time step.
                _impulse *= data.step.dtRatio;

                Vector2 P = _impulse * _u;
                vA -= _invMassA * P;
                wA -= _invIA * MathUtils.Cross(_rA, P);
                vB += _invMassB * P;
                wB += _invIB * MathUtils.Cross(_rB, P);
            }
            else
            {
                _impulse = 0.0f;
            }

            data.velocities[_indexA].v = vA;
            data.velocities[_indexA].w = wA;
            data.velocities[_indexB].v = vB;
            data.velocities[_indexB].w = wB;
        }
开发者ID:tracer0707,项目名称:OpenGLF,代码行数:79,代码来源:RopeJoint.cs

示例14: InitVelocityConstraints

        internal override void InitVelocityConstraints(ref SolverData data)
        {
            _indexA = BodyA.IslandIndex;
            _indexB = BodyB.IslandIndex;
            _localCenterA = BodyA._sweep.LocalCenter;
            _localCenterB = BodyB._sweep.LocalCenter;
            _invMassA = BodyA._invMass;
            _invMassB = BodyB._invMass;
            _invIA = BodyA._invI;
            _invIB = BodyB._invI;

            Vector2 cA = data.positions[_indexA].c;
            float aA = data.positions[_indexA].a;
            Vector2 vA = data.velocities[_indexA].v;
            float wA = data.velocities[_indexA].w;

            Vector2 cB = data.positions[_indexB].c;
            float aB = data.positions[_indexB].a;
            Vector2 vB = data.velocities[_indexB].v;
            float wB = data.velocities[_indexB].w;

            Rot qA = new Rot(aA), qB = new Rot(aB);

            _rA = MathUtils.Mul(qA, LocalAnchorA - _localCenterA);
            _rB = MathUtils.Mul(qB, LocalAnchorB - _localCenterB);

            // Get the pulley axes.
            _uA = cA + _rA - WorldAnchorA;
            _uB = cB + _rB - WorldAnchorB;

            float lengthA = _uA.Length();
            float lengthB = _uB.Length();

            if (lengthA > 10.0f * Settings.LinearSlop)
            {
                _uA *= 1.0f / lengthA;
            }
            else
            {
                _uA = Vector2.Zero;
            }

            if (lengthB > 10.0f * Settings.LinearSlop)
            {
                _uB *= 1.0f / lengthB;
            }
            else
            {
                _uB = Vector2.Zero;
            }

            // Compute effective mass.
            float ruA = MathUtils.Cross(_rA, _uA);
            float ruB = MathUtils.Cross(_rB, _uB);

            float mA = _invMassA + _invIA * ruA * ruA;
            float mB = _invMassB + _invIB * ruB * ruB;

            _mass = mA + Ratio * Ratio * mB;

            if (_mass > 0.0f)
            {
                _mass = 1.0f / _mass;
            }

            if (Settings.EnableWarmstarting)
            {
                // Scale impulses to support variable time steps.
                _impulse *= data.step.dtRatio;

                // Warm starting.
                Vector2 PA = -(_impulse) * _uA;
                Vector2 PB = (-Ratio * _impulse) * _uB;

                vA += _invMassA * PA;
                wA += _invIA * MathUtils.Cross(_rA, PA);
                vB += _invMassB * PB;
                wB += _invIB * MathUtils.Cross(_rB, PB);
            }
            else
            {
                _impulse = 0.0f;
            }

            data.velocities[_indexA].v = vA;
            data.velocities[_indexA].w = wA;
            data.velocities[_indexB].v = vB;
            data.velocities[_indexB].w = wB;
        }
开发者ID:ImmortalJINX,项目名称:Project-EGOR,代码行数:89,代码来源:PulleyJoint.cs

示例15: GetSphereExtentAxis

        /// <summary>
        /// 
        /// </summary>
        /// <param name="znear"></param>
        /// <param name="a"></param>
        /// <param name="z"></param>
        /// <param name="r"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        bool GetSphereExtentAxis( float znear, float a, float z, float r, out float min, out float max )
        {
            min = max = 0;

            if (z>r-znear) {
                return false;
            }

            var c		=	new Vector2( a, z );
            var t		=	sqrt( c.LengthSquared() - r * r );
            var cLen	=	c.Length();
             		var cosT	=	t / cLen;
            var sinT	=	r / cLen;

            c.X /= cLen;
            c.Y /= cLen;

            var T		=	new Vector2( cosT * c.X - sinT * c.Y, +sinT * c.X + cosT * c.Y ) * t;
            var B		=	new Vector2( cosT * c.X + sinT * c.Y, -sinT * c.X + cosT * c.Y ) * t;

            var tau		=	new Vector2( a + sqrt( r*r - square(znear-z) ), znear );
            var beta	=	new Vector2( a - sqrt( r*r - square(znear-z) ), znear );

            var U		=	T.Y < znear ? T : tau;
            var L		=	B.Y < znear ? B : beta;

            max			=	U.X / U.Y * znear;
            min			=	L.X / L.Y * znear;

            return true;
        }
开发者ID:temik911,项目名称:audio,代码行数:41,代码来源:LightRenderer.cs


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