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


C# Vector3.Normalize方法代码示例

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


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

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

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

示例3: Normalize

 public void Normalize()
 {
     Vector3 v1 = new Vector3(-10.5f, 0.2f, 1000.0f);
     Vector3 v2 = new Vector3(-10.5f, 0.2f, 1000.0f);
     v1.Normalize();
     var expectedResult = new Vector3(-0.0104994215f, 0.000199988979f, 0.999944866f);
     Assert.That(expectedResult, Is.EqualTo(v1).Using(Vector3Comparer.Epsilon));
     v2 = Vector3.Normalize(v2);
     Assert.That(expectedResult, Is.EqualTo(v2).Using(Vector3Comparer.Epsilon));
 }
开发者ID:Zodge,项目名称:MonoGame,代码行数:10,代码来源:Vector3Test.cs

示例4: Initialise

        public override void Initialise()
        {
            CameraDirection = Vector3.Zero - World.Translation;
            CameraDirection.Normalize();
            CameraUpDirection = Vector3.Up;
            CameraTarget = World.Translation + CameraDirection;

            CreateLookAt(StartTarget);

            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, AspectRatio, NearPlane, FarPlane);

            base.Initialise();
        }
开发者ID:TalonTwist,项目名称:3DBraveChess,代码行数:13,代码来源:Camera.cs

示例5: OnLoaded

        void OnLoaded(object sender, RoutedEventArgs e)
        {
            ActorFormControl.RuntimeContent = DataContext as RuntimeContentViewModel;
            ActorFormControl.LoadContent();
            ActorFormControl.ResetActorOrientation(defaultActorOrientation);

            // コントロールに設定されたカメラ座標とモデル姿勢行列を初期値として記憶しておきます。
            defaultCameraPosition = ActorFormControl.CameraPosition;

            // 光源をデフォルトとは違う位置に設定します (デフォルトは方向が Vector3.Down の光源)。
            var direction = new Vector3(1, -1, -1);
            direction.Normalize();
            ActorFormControl.SceneSettings.DirectionalLight0.Direction = direction;
        }
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:14,代码来源:RuntimeActorControl.xaml.cs

示例6: Apply

        public override void Apply(Entity entity, DrawData? drawData)
        {
            if (entity == null)
                _shader.Parameters["uLightSource"].SetValue(Vector3.Zero);
            else
            {
                float num1 = 0.0f;
                if (drawData.HasValue)
                    num1 = drawData.Value.rotation;

                Vector2 vector2_1 = entity.position;
                float x1 = (float)entity.width;
                float y1 = (float)entity.height;
                Vector2 vector2_2 = vector2_1 + new Vector2(x1, y1) * 0.1f;
                float x2 = x1 * 0.8f;
                float y2 = y1 * 0.8f;
                Vector3 subLight1 = Lighting.GetSubLight(vector2_2 + new Vector2(x2 * 0.5f, 0.0f));
                Vector3 subLight2 = Lighting.GetSubLight(vector2_2 + new Vector2(0.0f, y2 * 0.5f));
                Vector3 subLight3 = Lighting.GetSubLight(vector2_2 + new Vector2(x2, y2 * 0.5f));
                Vector3 subLight4 = Lighting.GetSubLight(vector2_2 + new Vector2(x2 * 0.5f, y2));
                float num2 = subLight1.X + subLight1.Y + subLight1.Z;
                float num3 = subLight2.X + subLight2.Y + subLight2.Z;
                float num4 = subLight3.X + subLight3.Y + subLight3.Z;
                float num5 = subLight4.X + subLight4.Y + subLight4.Z;
                Vector2 spinningpoint = new Vector2(num4 - num3, num5 - num2);
                if ((double)spinningpoint.Length() > 1.0)
                {
                    float num6 = 1f;
                    spinningpoint /= num6;
                }

                if (entity.direction == -1)
                    spinningpoint.X *= -1f;

                spinningpoint = Utils.RotatedBy(spinningpoint, -(double)num1, new Vector2());
                Vector3 vector3 = new Vector3(spinningpoint, (float)(1.0 - ((double)spinningpoint.X * (double)spinningpoint.X + (double)spinningpoint.Y * (double)spinningpoint.Y)));
                vector3.X *= 2f;
                vector3.Y -= 0.15f;
                vector3.Y *= 2f;
                vector3.Normalize();
                vector3.Z *= 0.6f;
                _shader.Parameters["uLightSource"].SetValue(vector3);
            }
            base.Apply(entity, drawData);
        }
开发者ID:EmuDevs,项目名称:EDTerraria,代码行数:45,代码来源:ReflectiveArmorShaderData.cs

示例7: ColoredTerrain

        /// <summary>
        /// Initializes a new instance of the <see cref="ColoredTerrain" /> class.
        /// </summary>
        /// <param name="heightMap">The height map.</param>
        /// <param name="coloringMethod">The coloring method.</param>
        public ColoredTerrain(GraphicsDevice device, IHeightMap heightMap, IHeightToColorTranslationMethod coloringMethod)
        {
            this.effect = new BasicEffect(device);
            this.effect.VertexColorEnabled = true;
            Vector3 lightDir = new Vector3(1, -1, -1);
            lightDir.Normalize();
            this.effect.LightingEnabled = true;
            this.effect.PreferPerPixelLighting = true;
            this.effect.DirectionalLight0.Direction = lightDir;

            this.Width = heightMap.Width;
            this.Height = heightMap.Height;
            this.heightMap = heightMap;
            this.coloringMethod = coloringMethod;

            this.SetUpVertices();
            this.SetUpIndices();
            this.CalculateNormals();
        }
开发者ID:elkorn,项目名称:Tanks3DFPP,代码行数:24,代码来源:ColoredTerrain.cs

示例8: SatisfyConstraint

        public void SatisfyConstraint()
        {
            //calculate direction
            direction = simObj2.CurrPosition - simObj1.CurrPosition;

            //calculate current length
            currentLength = direction.Length();

            //check for zero vector
            if (direction != Vector3.Zero)
            {
                //normalize direction vector
                direction.Normalize();

                //move to goal positions
                moveVector = 0.5f * (currentLength - length) * direction;
                simObj1.CurrPosition += moveVector;
                simObj2.CurrPosition += -moveVector;
            }
        }
开发者ID:skeelogy,项目名称:xna-skeelsoftbodyphysics,代码行数:20,代码来源:LengthConstraint.cs

示例9: GetHeightAndNormal

        public void GetHeightAndNormal(Vector3 position, out float height, out Vector3 normal)
        {
            Vector3 positionOnHeightmap = position - ModelMatrix.Translation;

            int left, bottom;

            left = ((int)positionOnHeightmap.X + (int)halfTerrainWidth) / (int)blockScale;
            bottom = ((int)positionOnHeightmap.Z + (int)halfTerrainDepth) / (int)blockScale;

            float xNormalized = ((positionOnHeightmap.X + halfTerrainWidth) % blockScale) / blockScale;
            float zNormalized = ((positionOnHeightmap.Z + halfTerrainDepth) % blockScale) / blockScale;

            float bottomHeight = MathHelper.Lerp(
                verticesArrray[PlaceInArray(bottom, left)].Y,
                verticesArrray[PlaceInArray(bottom, left + 1)].Y,
                xNormalized);

            float topHeight = MathHelper.Lerp(
                verticesArrray[PlaceInArray(bottom + 1, left)].Y,
                verticesArrray[PlaceInArray(bottom + 1, left + 1)].Y,
                xNormalized);

            height = MathHelper.Lerp(bottomHeight, topHeight, zNormalized);

            Vector3 bottomNormal = Vector3.Lerp(
               normalArray[PlaceInArray(bottom, left)],
               normalArray[PlaceInArray(bottom, left + 1)],
                xNormalized);

            Vector3 topNormal = Vector3.Lerp(
               normalArray[PlaceInArray(bottom + 1, left)],
               normalArray[PlaceInArray(bottom + 1, left + 1)],
               xNormalized);

            normal = Vector3.Lerp(bottomNormal, topNormal, zNormalized);
            normal.Normalize();
        }
开发者ID:Andrusza,项目名称:PiratesArr,代码行数:37,代码来源:TerrainColision.cs

示例10: Rangefinder

        public Rangefinder(IGameEntity entity)
        {
            SensingEntity = entity;

            // Initialize feeler directions.
            Vector3 forwardDir = new Vector3(entity.Heading, 0.0f);
            forwardDir.Normalize();

            Vector3 leftForwardDir = Vector3.Transform(forwardDir,
                Matrix.CreateRotationZ(MathHelper.ToRadians(-AngleBetweenFeelers)));
            leftForwardDir.Normalize();

            Vector3 rightForwardDir = Vector3.Transform(forwardDir,
                Matrix.CreateRotationZ(MathHelper.ToRadians(AngleBetweenFeelers)));
            rightForwardDir.Normalize();

            // Add 3 feelers.
            Vector3 position = new Vector3(entity.Position, 0.0f);
            Feelers.Add(new Ray(position, leftForwardDir));
            Feelers.Add(new Ray(position, forwardDir));
            Feelers.Add(new Ray(position, rightForwardDir));

            rangefinderDebugger = new RangefinderDebugger(this);
        }
开发者ID:Linusa,项目名称:AI_Project,代码行数:24,代码来源:Rangefinder.cs

示例11: Get

        public Enemy Get(EnemyType type, int speedLevel, int livesLevel, int value)
        {
            Enemy e = EnemiesPools[type].Get();

            e.Name = GetTexture(type);
            e.Type = type;
            e.Simulator = Simulator;
            e.Speed = GetSpeed(type, speedLevel);
            e.LifePoints = e.StartingLifePoints = GetLives(type, livesLevel); ;
            e.CashValue = value;
            e.PointsValue = livesLevel;
            e.Color = ColorsEnemies[type];
            e.Level = (speedLevel + livesLevel) / 2;
            e.FadeInTime = (type == EnemyType.Swarm) ? 250 : 1000;
            e.ImpulseSpeed = (type == EnemyType.Swarm) ? 1f : 0;
            e.ImpulseTime = (type == EnemyType.Swarm) ? 250 : 0;

            if (type == EnemyType.Swarm)
            {
                Vector3 direction = new Vector3(
                    Main.Random.Next(-100, 100),
                    Main.Random.Next(-100, 100),
                    0
                );

                direction.Normalize();

                e.ImpulseDirection = direction;
            }

            return e;
        }
开发者ID:jodigiordano,项目名称:commander,代码行数:32,代码来源:EnemiesFactory.cs

示例12: IsAreaVisible

        /// <summary>
        /// Calculates if the area is visible within a camera viewport or not
        /// </summary>
        /// <param name="area">The area</param>
        /// <param name="camera">The camera to check against</param>
        /// <returns>True if the area is visible, false if not</returns>
        public bool IsAreaVisible(Area area, CameraBase camera)
        {
            if (area.Info.IsEmpty)
            {
                return false;
            }

            // Calculate the distance from the area to the camera
            areaToCameraDistance = (area.Info.Center - camera.Position).Length();

            // Is the area within stand-on or next-to distance
            if (areaToCameraDistance < areasAlwaysVisibleWithinDistance)
            {
                return true;
            }

            // Calculate the normal from the area pointing towards the camera position
            areaLookAtNormal = (camera.Position - area.Info.Center);
            areaLookAtNormal.Normalize();

            return Vector3.Dot(camera.LookAtNormal, areaLookAtNormal) <= -0.5f;
        }
开发者ID:JohanGl,项目名称:Outworld-XNA,代码行数:28,代码来源:TerrainVisibility.cs

示例13: FindSupport

        /// <summary>
        /// Finds a supporting entity, the contact location, and the contact normal.
        /// </summary>
        /// <param name="location">Contact point between the wheel and the support.</param>
        /// <param name="normal">Contact normal between the wheel and the support.</param>
        /// <param name="suspensionLength">Length of the suspension at the contact.</param>
        /// <param name="supportingCollidable">Collidable supporting the wheel, if any.</param>
        /// <param name="entity">Supporting object.</param>
        /// <param name="material">Material of the wheel.</param>
        /// <returns>Whether or not any support was found.</returns>
        protected internal override bool FindSupport(out Vector3 location, out Vector3 normal, out float suspensionLength, out Collidable supportingCollidable, out Entity entity, out Material material)
        {
            suspensionLength = float.MaxValue;
            location = Toolbox.NoVector;
            supportingCollidable = null;
            entity = null;
            normal = Toolbox.NoVector;
            material = null;

            Collidable testCollidable;
            RayHit rayHit;

            bool hit = false;

            for (int i = 0; i < detector.CollisionInformation.pairs.Count; i++)
            {
                var pair = detector.CollisionInformation.pairs[i];
                testCollidable = (pair.BroadPhaseOverlap.entryA == detector.CollisionInformation ? pair.BroadPhaseOverlap.entryB : pair.BroadPhaseOverlap.entryA) as Collidable;
                if (testCollidable != null)
                {
                    if (CollisionRules.CollisionRuleCalculator(this, testCollidable) == CollisionRule.Normal &&
                        testCollidable.RayCast(new Ray(wheel.suspension.worldAttachmentPoint, wheel.suspension.worldDirection), wheel.suspension.restLength, out rayHit) &&
                        rayHit.T < suspensionLength)
                    {
                        suspensionLength = rayHit.T;
                        EntityCollidable entityCollidable;
                        if ((entityCollidable = testCollidable as EntityCollidable) != null)
                        {
                            entity = entityCollidable.Entity;
                            material = entityCollidable.Entity.Material;
                        }
                        else
                        {
                            entity = null;
                            supportingCollidable = testCollidable;
                            var materialOwner = testCollidable as IMaterialOwner;
                            if (materialOwner != null)
                                material = materialOwner.Material;
                        }
                        location = rayHit.Location;
                        normal = rayHit.Normal;
                        hit = true;
                    }
                }
            }
            if (hit)
            {
                if (suspensionLength > 0)
                    normal.Normalize();
                else
                    Vector3.Negate(ref wheel.suspension.worldDirection, out normal);
                return true;
            }
            return false;
        }
开发者ID:Indiefreaks,项目名称:igf,代码行数:65,代码来源:RaycastWheelShape.cs

示例14: MoveRight

 public void MoveRight(float amount, float deltaTime)
 {
     Vector3 rightXz = new Vector3(Right.X, 0.0f, Right.Z);
     rightXz.Normalize();
     Position += amount * rightXz * deltaTime;
 }
开发者ID:ruicaridade,项目名称:IP3D,代码行数:6,代码来源:Camera.cs

示例15: OnMouseMove

        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (curCamera != null && SimulatorContainer.IsMouseCaptured)
                {
                    var p = e.GetPosition(SimulatorContainer);
                    var drag = new Vector2((float)p.X - mouseStart.X, (float)p.Y - mouseStart.Y);
                    mouseStart = new Vector2((float)p.X, (float)p.Y);
                    xnaTypes.Vector3 view = curCamera.Camera.LookAt - curCamera.Camera.Location;
                    view.Normalize();
                    switch (dragType)
                    {
                        case DragType.LOOK:
                            xnaTypes.Vector3 up = new xnaTypes.Vector3(0, 1, 0);
                            float dot = xnaTypes.Vector3.Dot(view, up);
                            if (Math.Abs(dot) > 0.99)
                            {
                                up += new xnaTypes.Vector3(0.1f, 0, 0);
                                up.Normalize();
                            }
                            xnaTypes.Vector3 right = xnaTypes.Vector3.Cross(view, up);
                            view = xnaTypes.Vector3.Multiply(view, 10f);
                            view = xnaTypes.Vector3.Transform(view, xnaTypes.Matrix.CreateFromAxisAngle(up, (float)(-drag.X * Math.PI / 500)));
                            view = xnaTypes.Vector3.Transform(view, xnaTypes.Matrix.CreateFromAxisAngle(right, (float)(-drag.Y * Math.PI / 500)));

                            curCamera.Camera.LookAt = curCamera.Camera.Location + view;
                            break;
                        case DragType.MOVE:
                            var right2 = xnaTypes.Vector3.Cross(view, new xnaTypes.Vector3(0, 1, 0));
                            var up2 = xnaTypes.Vector3.Cross(right2, view);
                            right2 *= (drag.X * 0.05f);
                            up2 *= (-drag.Y * 0.05f);
                            var delta = right2 + up2;
                            curCamera.Camera.LookAt += delta;
                            curCamera.Camera.Location += delta;
                            break;
                    }
                }
            }
            catch (Exception err)
            {
                GUIUtilities.ReportUnexpectedException(err);
            }
        }
开发者ID:SamLin95,项目名称:cs3630,代码行数:45,代码来源:SimulatorDisplay.xaml.cs


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