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


C# Vector2.Normalize方法代码示例

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


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

示例1: RoundedLine

        /// <summary>
        /// Draws a line with rounded ends.
        /// </summary>
        /// <param name="x1">The X position of the first point.</param>
        /// <param name="y1">The Y position of the first point.</param>
        /// <param name="x2">The X position of the second point.</param>
        /// <param name="y2">The Y position of the second point.</param>
        /// <param name="color">The color of the line.</param>
        /// <param name="thickness">The thickness of the line.</param>
        static public void RoundedLine(float x1, float y1, float x2, float y2, Color color, float thickness) {
            VertexArray vertices = new VertexArray(PrimitiveType.TrianglesFan);

            int rotationSteps = 10;

            var line = new Vector2(x2 - x1, y2 - y1);
            var normalUp = new Vector2(y1 - y2, x2 - x1);
            var normalDown = new Vector2(y2 - y1, x1 - x2);

            normalUp.Normalize(thickness * 0.5f);
            normalDown.Normalize(thickness * 0.5f);

            var nextPoint = new Vector2();

            float vx, vy;

            vx = x1;
            vy = y1;

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x1 + normalUp.X);
            vy = (float)(y1 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            nextPoint.X = normalUp.X;
            nextPoint.Y = normalUp.Y;

            for (int i = 0; i < rotationSteps; i++) {
                nextPoint = Util.Rotate(nextPoint, -180 / rotationSteps);

                vx = (float)(x1 + nextPoint.X);
                vy = (float)(y1 + nextPoint.Y);

                vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));
            }

            vx = (float)(x1 + normalDown.X);
            vy = (float)(y1 + normalDown.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x2 + normalDown.X);
            vy = (float)(y2 + normalDown.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            for (int i = 0; i < rotationSteps; i++) {
                nextPoint = Util.Rotate(nextPoint, -180 / rotationSteps);

                vx = (float)(x2 + nextPoint.X);
                vy = (float)(y2 + nextPoint.Y);

                vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));
            }

            vx = (float)(x2 + normalUp.X);
            vy = (float)(y2 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x1 + normalUp.X);
            vy = (float)(y1 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            Drawable(vertices, RenderStates.Default);
        }
开发者ID:KrissLaCross,项目名称:BreakOut,代码行数:78,代码来源:Draw.cs

示例2: Line

        /// <summary>
        /// Draws a line with a thickness using a quad.
        /// </summary>
        /// <param name="x1">The X position of the first point.</param>
        /// <param name="y1">The Y position of the first point.</param>
        /// <param name="x2">The X position of the second point.</param>
        /// <param name="y2">The Y position of the second point.</param>
        /// <param name="color">The color of the line.</param>
        /// <param name="thickness">The thickness of the line.</param>
        static public void Line(float x1, float y1, float x2, float y2, Color color, float thickness) {
            VertexArray vertices = new VertexArray(PrimitiveType.Quads);

            var line = new Vector2(x2 - x1, y2 - y1);
            var normalUp = new Vector2(y1 - y2, x2 - x1);
            var normalDown = new Vector2(y2 - y1, x1 - x2);

            normalUp.Normalize(thickness * 0.5f);
            normalDown.Normalize(thickness * 0.5f);

            float vx, vy;

            vx = (float)(x1 + normalUp.X);
            vy = (float)(y1 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x1 + normalDown.X);
            vy = (float)(y1 + normalDown.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x2 + normalDown.X);
            vy = (float)(y2 + normalDown.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            vx = (float)(x2 + normalUp.X);
            vy = (float)(y2 + normalUp.Y);

            vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor));

            Drawable(vertices, RenderStates.Default);
        }
开发者ID:KrissLaCross,项目名称:BreakOut,代码行数:43,代码来源:Draw.cs


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