當前位置: 首頁>>代碼示例>>C#>>正文


C# Vector3.LengthSquared方法代碼示例

本文整理匯總了C#中Microsoft.Xna.Framework.Vector3.LengthSquared方法的典型用法代碼示例。如果您正苦於以下問題:C# Vector3.LengthSquared方法的具體用法?C# Vector3.LengthSquared怎麽用?C# Vector3.LengthSquared使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.Xna.Framework.Vector3的用法示例。


在下文中一共展示了Vector3.LengthSquared方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SetForce

        public void SetForce(Vector3 force)
        {
            if (force.LengthSquared() > 1.0f)
                force.Normalize();

            mController.Force = GameOptions.MovementForce * force;
        }
開發者ID:Tengato,項目名稱:Mechadrone1,代碼行數:7,代碼來源:FlyerControllerComponent.cs

示例2: LocalGetSupportingVertexWithoutMargin

		// optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp
		//public class Hull m_optionalHull;

		public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec)
		{
			Vector3 supVec = new Vector3();

			float maxDot = -1e30f;

			float lenSqr = vec.LengthSquared();
			if (lenSqr < 0.0001f)
			{
				vec = new Vector3(1, 0, 0);
			}
			else
			{
				float rlen = 1f / (float)Math.Sqrt(lenSqr);
				vec *= rlen;
			}

			Vector3 vtx;
			float newDot;

			for (int i = 0; i < VertexCount; i++)
			{
				GetVertex(i, out vtx);
				newDot = Vector3.Dot(vec, vtx);
				if (newDot > maxDot)
				{
					maxDot = newDot;
					supVec = vtx;
				}
			}
			return supVec;
		}
開發者ID:Belxjander,項目名稱:Asuna,代碼行數:35,代碼來源:PolyhedralConvexShape.cs

示例3: Extend

        public static Vector3 Extend(Vector3 value, float min)
        {
            float minSquared = min*min;
            float vectorSquared = value.LengthSquared();

            if (vectorSquared >= minSquared || vectorSquared == 0)
                return value;
            else
                return value*(min/(float) Math.Sqrt(vectorSquared));
        }
開發者ID:rc183,項目名稱:igf,代碼行數:10,代碼來源:Vector3Extensions.cs

示例4: Truncate

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="max"></param>
        public static Vector3 Truncate(Vector3 value, float max)
        {
            float maxSquared = max * max;
            float vectorSquared = value.LengthSquared();

            if (vectorSquared <= maxSquared)
                return value;
            else
                return value * (max / (float)Math.Sqrt(vectorSquared));
        }
開發者ID:rc183,項目名稱:igf,代碼行數:15,代碼來源:Vector3Extensions.cs

示例5: ProjectVector3D

 public static void ProjectVector3D(ref Vector3 vec, ref Vector3 projectOn, out Vector3 result)
 {
     float dp;
     Vector3.Dot(ref vec, ref projectOn, out dp);
     float oneOnLenSqr = 1.0f / projectOn.LengthSquared();
     result = new Vector3(
                 dp * oneOnLenSqr * projectOn.X,
                 dp * oneOnLenSqr * projectOn.Y,
                 dp * oneOnLenSqr * projectOn.Y);
 }
開發者ID:gnomicstudios,項目名稱:GGJ13,代碼行數:10,代碼來源:VectorUtils.cs

示例6: update

			public void update()
			{
				velocity += _acceleration;
				position += velocity;
				_acceleration = Vector3.Zero;
				if( velocity.LengthSquared() < 0.001f * 0.001f )
					velocity = Vector3.Zero;

				velocity *= _damping;
				_damping = 0.98f;
			}
開發者ID:prime31,項目名稱:Nez,代碼行數:11,代碼來源:SpringGrid.cs

示例7: GetExtremePoint

        ///<summary>
        /// Gets the extreme point of the shape in world space in a given direction with margin expansion.
        ///</summary>
        ///<param name="direction">Direction to find the extreme point in.</param>
        /// <param name="shapeTransform">Transform to use for the shape.</param>
        ///<param name="extremePoint">Extreme point on the shape.</param>
        public void GetExtremePoint(Vector3 direction, ref RigidTransform shapeTransform, out Vector3 extremePoint)
        {
            GetExtremePointWithoutMargin(direction, ref shapeTransform, out extremePoint);

            float directionLength = direction.LengthSquared();
            if (directionLength > Toolbox.Epsilon)
            {
                Vector3.Multiply(ref direction, collisionMargin / (float)Math.Sqrt(directionLength), out direction);
                Vector3.Add(ref extremePoint, ref direction, out extremePoint);
            }

        }
開發者ID:Indiefreaks,項目名稱:igf,代碼行數:18,代碼來源:ConvexShape.cs

示例8: MovingLevelPiece

 public MovingLevelPiece(Game game, GameplayScreen host, String assetName, Vector3 pMovement, float pMoveSpeed)
     : base(game, host, assetName)
 {
     m_movement = pMovement;
     m_moveVelocity = m_movement;
     if (m_moveVelocity.LengthSquared() != 0)
     {
         m_moveVelocity.Normalize();
     }
     //50 is a good number, fyi
     m_moveVelocity *= pMoveSpeed;
     m_currentMovement = Vector3.Zero;
 }
開發者ID:vu159951,項目名稱:xnasuperdragonball,代碼行數:13,代碼來源:MovingLevelPiece.cs

示例9: NormalizeSafe

 /// <summary>
 /// 正規化された Vector3 を取得します。
 /// もしも Vector3 がゼロ ベクトルである場合にはゼロ ベクトルを返します。
 /// </summary>
 /// <param name="vector">Vector3。</param>
 /// <param name="result">正規化された Vector3。</param>
 public static void NormalizeSafe(ref Vector3 vector, out Vector3 result)
 {
     var lengthSquared = vector.LengthSquared();
     if (lengthSquared != 0.0f)
     {
         var coeff = 1.0f / (float) Math.Sqrt(lengthSquared);
         result.X = vector.X * coeff;
         result.Y = vector.Y * coeff;
         result.Z = vector.Z * coeff;
     }
     else
     {
         result = vector;
     }
 }
開發者ID:willcraftia,項目名稱:WindowsGame,代碼行數:21,代碼來源:Vector3Extension.cs

示例10: contains

        public override bool contains(Vector3 point)
        {
            Vector3 _p = new Vector3(point.X - Position.X, point.Y - Position.Y, point.Z - Position.Z);
            //Vector3 _p2 = Vector3.Transform(_p, Matrix.CreateFromQuaternion(Orientation));

            if (_p.Y >= 0 && _p.Y <= m_height)
            {
                if (_p.LengthSquared() < (m_radius * m_radius))
                {
                    return true;
                }
            }

            return false;
        }
開發者ID:DelBero,項目名稱:XnaScrap,代碼行數:15,代碼來源:CylinderCollider.cs

示例11: InertialMoveBehavior

        public InertialMoveBehavior(Vector3 v, float a, float mv)
            : base()
        {
            MaxSpeed = mv;
            Accel = a;

            if (v.LengthSquared() == 0)
            {
                Speed = 0;
                Direction = new Vector3();
            }
            else
            {
                Speed = v.Length();
                v.Normalize();
                Direction = v;
            }
        }
開發者ID:bigbadrat,項目名稱:XnaGame,代碼行數:18,代碼來源:SimpleMovementBehaviors.cs

示例12: GetLocalExtremePointWithoutMargin

        ///<summary>
        /// Gets the extreme point of the shape in local space in a given direction.
        ///</summary>
        ///<param name="direction">Direction to find the extreme point in.</param>
        ///<param name="extremePoint">Extreme point on the shape.</param>
        public override void GetLocalExtremePointWithoutMargin(ref Vector3 direction, out Vector3 extremePoint)
        {
            //Is it the tip of the cone?
            float sinThetaSquared = radius * radius / (radius * radius + height * height);
            //If d.Y * d.Y / d.LengthSquared >= sinthetaSquared
            if (direction.Y > 0 && direction.Y * direction.Y >= direction.LengthSquared() * sinThetaSquared)
            {
                extremePoint = new Vector3(0, .75f * height, 0);
                return;
            }
            //Is it a bottom edge of the cone?
            float horizontalLengthSquared = direction.X * direction.X + direction.Z * direction.Z;
            if (horizontalLengthSquared > Toolbox.Epsilon)
            {
                var radOverSigma = radius / Math.Sqrt(horizontalLengthSquared);
                extremePoint = new Vector3((float)(radOverSigma * direction.X), -.25f * height, (float)(radOverSigma * direction.Z));
            }
            else // It's pointing almost straight down...
                extremePoint = new Vector3(0, -.25f * height, 0);


        }
開發者ID:dsmo7206,項目名稱:Lemma,代碼行數:27,代碼來源:ConeShape.cs

示例13: VectorsDirectionEqual

 public static bool VectorsDirectionEqual(Vector3 vec1, Vector3 vec2, float allowedError)
 {
     float len1 = vec1.LengthSquared();
     float len2 = vec2.LengthSquared();
     float dot = Vector3.Dot(vec1, vec2);
     if(!(dot<0.0f))
         dot *= dot / (len1 * len2);
     return dot < 0.0f ? false : 1.0f - dot < allowedError;
 }
開發者ID:lancelot2112,項目名稱:XerUtilities,代碼行數:9,代碼來源:MathLib.cs

示例14: Update

            public void Update()
            {
                Velocity += acceleration;
                Position += Velocity;
                acceleration = Vector3.Zero;
                if (Velocity.LengthSquared() < 0.001f * 0.001f)
                    Velocity = Vector3.Zero;

                Velocity *= damping;
                damping = 0.98f;
            }
開發者ID:hvp,項目名稱:Squareosity,代碼行數:11,代碼來源:Grid.cs

示例15: Project

 public static Vector3 Project(this Vector3 v, Vector3 on)
 {
     return v.Dot(on) / on.LengthSquared() * on;
 }
開發者ID:ZetaTwo,項目名稱:Project-Easter-Egg,代碼行數:4,代碼來源:PointAndVectorExtensions.cs


注:本文中的Microsoft.Xna.Framework.Vector3.LengthSquared方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。