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


C# Vector3.Length方法代码示例

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


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

示例1: Move

        public void Move(Vector3 dir, float amount)
        {
            if (dir.Length() != 1 && dir.Length() != 0)
                dir.Normalize();

            Position += Vector3.Transform(dir * amount, Matrix.CreateRotationX(Pitch) * Matrix.CreateRotationY(Yaw));
        }
开发者ID:HRuivo,项目名称:SolarSystemXNA,代码行数:7,代码来源:Camera.cs

示例2: TranslateMachine

        /// <summary>
        /// Creates a new, cool, advanced Model. For Accelerated Delivery. Otherwise I get
        /// lots of silly repetative variables. Note that all rendering options are hardcoded.
        /// </summary>
        /// <param name="machineNo">The machine number. For any numbers outside of 1-10, it is treated as the number of
        /// milliseconds until this machine automatically activates.</param>
        /// <param name="machines">An array of machines this machine holds. Null is acceptable.</param>
        /// <param name="models">A list of BaseModels and Tubes that the Machine contains.</param>
        /// <param name="targetPos">The amount of X, Y, and Z to translate.</param>
        /// <param name="timestep">The amount of time to use to translate.</param>
        public TranslateMachine(int machineNo, int soundIndex, Vector3 targetPos, float timestep, bool automatic, params BaseModel[] models)
            : base(machineNo, soundIndex, models)
        {
            joints = new List<WeldJoint>();
            timeStep = timestep;
            targetPosition = targetPos;
            this.automatic = automatic;
            baseJoint = new PrismaticJoint(null, modelList[0].Ent, modelList[0].Ent.Position, Vector3.Normalize(targetPos), modelList[0].Ent.Position);
            baseJoint.Motor.IsActive = true;
            baseJoint.Motor.Settings.Mode = MotorMode.Servomechanism;
            baseJoint.Motor.Settings.Servo.Goal = 0;
            baseJoint.Limit.Maximum = targetPos.Length();
            baseJoint.Limit.Minimum = 0;
            baseJoint.Limit.IsActive = true;
            baseJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = targetPos.Length() / timestep;
            baseJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = targetPos.Length() / timestep;
            baseJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 15;

            foreach(BaseModel m in modelList)
            {
                if(m == modelList[0])
                    continue;
                WeldJoint j = new WeldJoint(modelList[0].Ent, m.Ent);
                joints.Add(j);
            }
            foreach(Tube t in tubeList)
                t.SetParent(modelList[0].Ent);

            if(automatic)
            {
                inputs.Clear();
                inputs.Add(new MachineTimer(machineNo / 1000f));
            }
        }
开发者ID:snoozbuster,项目名称:accelerated-delivery,代码行数:45,代码来源:TranslateMachine.cs

示例3: ConstantLinearMoveBehavior

 public ConstantLinearMoveBehavior(Vector3 v)
     : base()
 {
     Speed = v.Length();
     v.Normalize();
     Direction = v;
 }
开发者ID:bigbadrat,项目名称:XnaGame,代码行数:7,代码来源:SimpleMovementBehaviors.cs

示例4: Update

 public override void Update(GameTime gameTime)
 {
     KeyboardManager KManager = (KeyboardManager)Game.Services.GetService(typeof(KeyboardManager));
     if (KManager.IsKeyPressed(Keys.M))
     {
         Mode = (CameraMode)(((int)Mode + 1) % 2);
     }
     float X = KManager.IsKeyDown(Keys.Right) ? 1 : 0;
     X -= KManager.IsKeyDown(Keys.Left) ? 1 : 0;
     float Z = KManager.IsKeyDown(Keys.Down) ? 1 : 0;
     Z -= KManager.IsKeyDown(Keys.Up) ? 1 : 0;
     Vector3 move = new Vector3(X, 0, Z);
     if (move.Length() > 0)
     {
         world_.Translation += move;
     }
     view_ = Matrix.CreateLookAt(world_.Translation, world_.Forward + world_.Translation, world_.Up);
     switch (Mode)
     {
         case CameraMode.PROJECTIVE:
             projection_ = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Game.GraphicsDevice.Viewport.AspectRatio, 0.1f, 100);
             break;
         case CameraMode.ORTHOGONAL:
             projection_ = Matrix.CreateOrthographic(Game.GraphicsDevice.Viewport.Width/20, Game.GraphicsDevice.Viewport.Height/20, 0.1f, 100);
             break;
     }
     base.Update(gameTime);
 }
开发者ID:TheSuperGoge,项目名称:UnDeadSchool,代码行数:28,代码来源:Camera.cs

示例5: AngleBetween

 public static float AngleBetween(this Vector3 v1, Vector3 v2)
 {
     float dot = Vector3.Dot(v1, v2);
     float mag1 = Math.Abs(v1.Length());
     float mag2 = Math.Abs(v2.Length());
     return (float)Math.Acos(dot / (mag1 * mag2));
 }
开发者ID:snoozbuster,项目名称:accelerated-delivery,代码行数:7,代码来源:Utilities.cs

示例6: Update

        public void Update(float dt)
        {
            Position += Velocity * dt;
            Velocity -= new Vector3(0, Gravity * dt, 0);
            Velocity *= (1f - Damping);

            Vector3 direction = Velocity;
            direction.Normalize();
            Ray ray = new Ray(Position, direction);//Vector3.Transform(Vector3.Forward, Orientation));
            RayCastResult result;
            Sector.Redria.Space.RayCast(ray, 2, out result);
            if (result.HitObject != null)
            {
                if (result.HitObject.Tag is ShipObj)
                {
                    var ship = (ShipObj)result.HitObject.Tag;
                    var magnitude = Velocity.Length();
                    //var angle = Vector3.Dot(result.HitData.Normal,Velocity)/magnitude;
                    float velocity = magnitude;//(float)(magnitude*angle);
                    ship.BulletStrike(Data,velocity);
                }
                Sector.Redria.Bullets.Remove(this);
            }
            if (Position.Y < -5) Sector.Redria.Bullets.Remove(this);
        }
开发者ID:Aryn,项目名称:Mobile-Fortress,代码行数:25,代码来源:Bullet.cs

示例7: GoalPoint

 /// <summary>
 /// Constructs a new GoalPoint.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <param name="orientation">The orientation.</param>
 /// <param name="scale">The amount to scale by.</param>
 /// <param name="nextLevel">
 /// The name of the next level to load.
 /// An invalid name will return to the Main menu.
 /// </param>
 /// <param name="partType">The part required to pass the level.</param>
 public GoalPoint(Vector3 position, Quaternion orientation, Vector3 scale, string nextLevel, Type partType)
     : base(new ScrollingTransparentModel("tractorBeam", new Vector2(0.1f, 0.0f)), new Cylinder(position, 1f, scale.Length() * 7.0f))
 {
     mNextLevel = nextLevel;
     PartType = partType;
     Scale = new Vector3(1.0f, 5.0f, 1.0f);
 }
开发者ID:thormme,项目名称:Chimera,代码行数:18,代码来源:GoalPoint.cs

示例8: ApplyForce

        public void ApplyForce(SimObject simObject)
        {
            //get the direction vector
            direction = simObjectA.CurrPosition - simObjectB.CurrPosition;

            //check for zero vector
            if (direction != Vector3.Zero)
            {
                //get length
                currLength = direction.Length();

                //normalize
                direction.Normalize();

                //add spring force
                force = -stiffness * ((currLength - restLength) * direction);

                //add spring damping force
                force += -damping * Vector3.Dot(simObjectA.CurrVelocity - simObjectB.CurrVelocity, direction) * direction;

                //apply the equal and opposite forces to the objects
                simObjectA.ResultantForce += force;
                simObjectB.ResultantForce += -force;
            }
        }
开发者ID:skeelogy,项目名称:xna-skeelsoftbodyphysics,代码行数:25,代码来源:Spring.cs

示例9: Truncate

        /// <summary>
        /// Truncates the vector in accordance to the maximal length
        /// </summary>
        /// <param name="vectorToTruncate">Vector to truncate</param>
        /// <param name="maxLengthOfVector">Maximal legal length of the vector</param>
        /// <returns>Truncated vector</returns>
        public static Vector3 Truncate(Vector3 vectorToTruncate, float maxLengthOfVector)
        {
            if (vectorToTruncate.Length() > maxLengthOfVector)
                vectorToTruncate = Vector3.Normalize(vectorToTruncate) * maxLengthOfVector;

            return vectorToTruncate;
        }
开发者ID:propheel,项目名称:Projects,代码行数:13,代码来源:V3Extensions.cs

示例10: pursue

 public Vector3 pursue(Vector3 evaderPosition, Vector3 evaderVelocity,Vector3 currentPosition,Vector3 velocity)
 {
     float distance = Vector3.Subtract(evaderPosition, currentPosition).Length();
     float timeToReachTarget = distance / velocity.Length();
     Vector3 targetPosition = evaderPosition + evaderVelocity * timeToReachTarget;
     return seek(targetPosition,currentPosition,velocity);
 }
开发者ID:HeatherXi,项目名称:game-programming,代码行数:7,代码来源:Steering.cs

示例11: dotProductCalculation

        public static Vector3 dotProductCalculation(Vector3 direction1, Vector3 direction2)
        {
            if (direction1.Length() == 0 || direction2.Length() == 0)
            {
                return Vector3.Zero;
            }
            else
            {
                Vector3 normalized1 = new Vector3(direction1.X, direction1.Y, direction1.Z);
                normalized1.Normalize();
                Vector3 normalized2 = new Vector3(direction2.X, direction2.Y, direction2.Z);
                normalized2.Normalize();
                float dotProduct = Vector3.Dot(normalized1, normalized2);

                return dotProduct * normalized2 * direction1.Length();
            }
        }
开发者ID:rickinator9,项目名称:SimTecPracticums,代码行数:17,代码来源:Physics.cs

示例12: Transform

		/// <summary>
		/// Construct this transform from a matrix
		/// </summary>
		/// <param name="matrix"></param>
		/// <param name="performValidityCheck">When true, the matrix will be checked to make sure it will produce a valid transform</param>
		public Transform(ref Matrix matrix, bool performValidityCheck)
		{
			if (performValidityCheck)
			{
				//validate the matrix is not sheered or inverted on a single axis.
				Vector3 x = new Vector3(matrix.M11, matrix.M12, matrix.M13);
				Vector3 y = new Vector3(matrix.M21, matrix.M22, matrix.M23);
				Vector3 z = new Vector3(matrix.M31, matrix.M32, matrix.M33);

				float xl = x.Length();
				float yl = y.Length();
				float zl = z.Length();

				float maxl = Math.Max(xl, Math.Max(yl, zl));
				float minl = Math.Min(xl, Math.Min(yl, zl));

				if ((maxl - minl) > maxl / 10)
					throw new ArgumentException("The input matrix is not uniformly scaled");

				if (xl > 0.000001f) x /= xl;
				if (yl > 0.000001f) y /= yl;
				if (zl > 0.000001f) z /= zl;

				Vector3 zc = Vector3.Cross(x, y);
				Vector3 yc = Vector3.Cross(z, x);
				Vector3 xc = Vector3.Cross(y, zc);

				if (Vector3.Dot(x, xc) < 0.975f || Vector3.Dot(z, zc) * Vector3.Dot(y, yc) < 0.95f)
					throw new ArgumentException("The input matrix is skewed, sheered or non uniformly scaled");
			}

			Vector3 scale;
			matrix.Decompose(out scale, out Rotation, out Translation);

			//if one or two components are negative, then the Decompose messed up.
			if (scale.X * scale.Y * scale.Z < 0)
			{
				Matrix copy = matrix;
				copy.M11 = -copy.M11;
				copy.M12 = -copy.M12;
				copy.M13 = -copy.M13;
				copy.M21 = -copy.M21;
				copy.M22 = -copy.M22;
				copy.M23 = -copy.M23;
				copy.M31 = -copy.M31;
				copy.M32 = -copy.M32;
				copy.M33 = -copy.M33;
				copy.Decompose(out scale, out Rotation, out Translation);
				scale = -scale;
			}

			this.Scale = Math.Min(Math.Min(scale.X, scale.Y), scale.Z);

			if (Scale > 0.999f && Scale < 1.001f)
				Scale = 1;

			this.Rotation.Normalize();
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:63,代码来源:Transform.cs

示例13: ExertFlapLeft

        protected virtual void ExertFlapLeft(Vector3 leftHandVel)
        {

            Vector2 impulse = Vector2.UnitY * leftHandVel.Length() * FLAP_MULTIPLIER;
            Matrix rot = Matrix.CreateRotationZ(ragdoll.Body.Rotation);
            impulse = Vector2.Transform(impulse, rot);

            ragdoll._upperLeftArm.ApplyLinearImpulse(impulse);

        }
开发者ID:guozanhua,项目名称:KinectRagdoll,代码行数:10,代码来源:Flappers.cs

示例14: Light

 public Light(Vector3 position, Vector3 gaze, Vector3 ambientColor, Vector3 diffuseColor, Vector3 specularColor)
 {
     mGaze = gaze;
     Position = position;
     mPositionPhi = (float)Math.Atan(Position.Y / Position.X);
     mPositionTheta = (float)Math.Acos(Position.Z / Position.Length());
     mAmbientColor = ambientColor;
     mDiffuseColor = diffuseColor;
     mSpecularColor = specularColor;
 }
开发者ID:thormme,项目名称:Chimera,代码行数:10,代码来源:Light.cs

示例15: ShouldFlap

        protected virtual bool ShouldFlap(Vector3 handLoc, Vector3 handVel)
        {

            if (handVel.Y < -1f && handLoc.Length() > .20f && handLoc.Y < 0)
            {
                //Console.WriteLine("HandVelY: " + handVel.Y + " handLocLength: " + handLoc.Length() + " handLocY: " + handLoc.Y);
                return true;
            }

            return false;
        }
开发者ID:guozanhua,项目名称:KinectRagdoll,代码行数:11,代码来源:Flappers.cs


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