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


C# Vector2.NormalizeFast方法代码示例

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


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

示例1: Update

        public override void Update(float timeSinceLastUpdate)
        {
            skybox.position = Camera.Instance.position;
            Camera.Instance.position -= cameraBobDelta;

            InputManager.enabled = !hudConsole.enabled;
            InputManager.UpdateToggleStates();

            if(InputManager.IsKeyDown(Key.R))
            {
                Respawn();
            }

            #region FPS camera

            if(!InputManager.IsKeyToggled(Key.Delete))
            {
                Vector2 mouseDelta = InputManager.GetMousePosition();
                mouseDelta.Y /= mouseSensitivity.Y / mouseSensitivityFactor;
                mouseDelta.X /= mouseSensitivity.X / mouseSensitivityFactor;
                fpsCam += mouseDelta;
                fpsCam.Y = (float)Math.Max(-1.57, Math.Min(1.57, fpsCam.Y));

                Camera.Instance.ResetOrientation();
                Camera.Instance.Pitch(-fpsCam.Y);
                Camera.Instance.Yaw(fpsCam.X);
                InputManager.HideCursor();
            }
            else
            {
                InputManager.ShowCursor();
            }

            #endregion
            #region Movement

            walkSpeed = config.GetInt(InputManager.IsKeyDown(Key.ShiftLeft) ? "runningSpeed" : "walkingSpeed");

            bool w = InputManager.IsKeyDown(Key.W);
            bool a = InputManager.IsKeyDown(Key.A);
            bool s = InputManager.IsKeyDown(Key.S);
            bool d = InputManager.IsKeyDown(Key.D);
            Vector2 delta = new Vector2(0, 0);
            if(w)
            {
                delta.Y += 1;
            }
            if(a)
            {
                delta.X -= 1;
            }
            if(s)
            {
                delta.Y -= 1;
            }
            if(d)
            {
                delta.X += 1;
            }

            delta.NormalizeFast();

            // Y
            Camera.Instance.velocity.X += delta.Y * walkSpeed * timeSinceLastUpdate * (float)Math.Sin(fpsCam.X); //0
            Camera.Instance.velocity.Z -= delta.Y * walkSpeed * timeSinceLastUpdate * (float)Math.Cos(fpsCam.X); //1

            // X
            Camera.Instance.velocity.X += delta.X * walkSpeed * timeSinceLastUpdate * (float)Math.Cos(fpsCam.X); //1
            Camera.Instance.velocity.Z += delta.X * walkSpeed * timeSinceLastUpdate * (float)Math.Sin(fpsCam.X); //0

            #endregion
            #region Collision

            bool grounded = false;
            playerHeight = config.GetInt(InputManager.IsKeyDown(Key.LControl) ? "crouchHeight" : "walkHeight");
            Vector3 feetPos = Camera.Instance.position;
            feetPos.Y -= playerHeight * 0.75f;

            foreach(CollisionAABB collisionBox in mapCollision)
            {
                // Y
                CollisionRay collisionRay = new CollisionRay(Camera.Instance.position, new Vector3(.00001f, -1, .00001f));
                float dist = collisionBox.Intersect(collisionRay);
                if(dist <= playerHeight && dist != -1)
                {
                    grounded = true;
                    Camera.Instance.position.Y += Math.Min(config.GetInt("riseSpeed") * timeSinceLastUpdate, playerHeight - dist);
                }

                // X vel
                if(Camera.Instance.velocity.X > 0)
                {
                    if(collisionBox.isInside(feetPos + new Vector3(Camera.Instance.velocity.X * timeSinceLastUpdate + 30, 0, 0)))
                    {
                        Camera.Instance.velocity.X = 0;
                    }
                }
                else
                {
                    if(collisionBox.isInside(feetPos + new Vector3(Camera.Instance.velocity.X * timeSinceLastUpdate - 30, 0, 0)))
//.........这里部分代码省略.........
开发者ID:carlosFPGA,项目名称:resim,代码行数:101,代码来源:Update.cs

示例2: DrawLine

        public unsafe void DrawLine(float x1, float y1, float x2, float y2, float thickness, Color4 color)
        {
            TryPush(this.pixelTex, null, BeginMode.Triangles);

            Vector2 dir = new Vector2(x2 - x1, y2 - y1);
            dir.NormalizeFast();
            Vector2 perp = dir.PerpendicularLeft;
            //perp.NormalizeFast();
            float hth = thickness / 2f;

            #region Add vertices

            int offset = vbuffer.VertexOffset / vbuffer.Stride;
            int* ind = vbuffer.GetIndexPointerToFill(6);
            float* vert = vbuffer.GetVertexPointerToFill(4);
            *(ind++) = offset; *(ind++) = offset + 1; *(ind++) = offset + 2;
            *(ind++) = offset; *(ind++) = offset + 2; *(ind++) = offset + 3;

            *(vert++) = x1 + perp.X * hth; *(vert++) = y1 + perp.Y * hth;
            *(vert++) = color.R; *(vert++) = color.G; *(vert++) = color.B; *(vert++) = color.A;
            *(vert++) = 0; *(vert++) = 0;

            *(vert++) = x2 + perp.X * hth; *(vert++) = y2 + perp.Y * hth;
            *(vert++) = color.R; *(vert++) = color.G; *(vert++) = color.B; *(vert++) = color.A;
            *(vert++) = 0; *(vert++) = 0;

            *(vert++) = x2 - perp.X * hth; *(vert++) = y2 - perp.Y * hth;
            *(vert++) = color.R; *(vert++) = color.G; *(vert++) = color.B; *(vert++) = color.A;
            *(vert++) = 0; *(vert++) = 0;

            *(vert++) = x1 - perp.X * hth; *(vert++) = y1 - perp.Y * hth;
            *(vert++) = color.R; *(vert++) = color.G; *(vert++) = color.B; *(vert++) = color.A;
            *(vert++) = 0; *(vert++) = 0;

            #endregion Add vertices
        }
开发者ID:remy22,项目名称:BlueberryEngine,代码行数:36,代码来源:SpriteBatch.cs


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