• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Numerics.Vector2类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Vector2类属于System.Numerics命名空间,在下文中一共展示了Vector2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: PolygonShape

 public PolygonShape()
 {
     ShapeType = ShapeType.Polygon;
     _radius = Settings.b2_polygonRadius;
     _vertexCount = 0;
     _centroid = Vector2.Zero;
 }
开发者ID:Nukepayload2,项目名称:Box2D,代码行数:7,代码来源:PolygonShape.cs


示例2: Scale

        public void Scale(RenderTarget2D source, RenderTarget2D destination)
        {
            _effect.CurrentTechnique = source.Format.IsFloatingPoint() ? _effect.Techniques["Software"] : _effect.Techniques["Hardware"];

            Vector2 resolution = new Vector2(source.Width, source.Height);
            float scaleFactor = (destination.Width > source.Width) ? 2 : 0.5f;

            RenderTarget2D input = source;

            while (IntermediateNeeded(resolution, destination, scaleFactor))
            {
                resolution *= scaleFactor;

                RenderTarget2D output = RenderTargetManager.GetTarget(_device, (int)resolution.X, (int)resolution.Y, source.Format, name:"scaled", usage: RenderTargetUsage.DiscardContents);
                Draw(input, output);

                if (input != source)
                    RenderTargetManager.RecycleTarget(input);
                input = output;
            }

            Draw(input, destination);

            if (input != source)
                RenderTargetManager.RecycleTarget(input);
        }
开发者ID:xoxota99,项目名称:Myre,代码行数:26,代码来源:Scale.cs


示例3: Canvas_Draw

        private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var a = new Vector2(10, 10);
            var b = new Vector2(100, 100);

            args.DrawingSession.DrawLine(a, b, Colors.Yellow);
        }
开发者ID:chrisi,项目名称:IoTCanvas,代码行数:7,代码来源:MainPage.xaml.cs


示例4: Vector4

 /// <summary>
 /// Constructs a Vector4 from the given Vector2 and a Z and W component.
 /// </summary>
 /// <param name="value">The vector to use as the X and Y components.</param>
 /// <param name="z">The Z component.</param>
 /// <param name="w">The W component.</param>
 public Vector4(Vector2 value, Single z, Single w)
 {
     X = value.X;
     Y = value.Y;
     Z = z;
     W = w;
 }
开发者ID:uQr,项目名称:referencesource,代码行数:13,代码来源:Vector4_Intrinsics.cs


示例5: IntermediateNeeded

        private bool IntermediateNeeded(Vector2 currentResolution, RenderTarget2D target, float scale)
        {
// ReSharper disable CompareOfFloatsByEqualityOperator
            return (scale == 2) ? (currentResolution.X * 2 < target.Width && currentResolution.Y * 2 < target.Height)
// ReSharper restore CompareOfFloatsByEqualityOperator
                                : (currentResolution.X / 2 > target.Width && currentResolution.Y / 2 > target.Height);
        }
开发者ID:xoxota99,项目名称:Myre,代码行数:7,代码来源:Scale.cs


示例6: VertexPositionTextureNormalBinormalTangent

// ReSharper restore NotAccessedField.Global
// ReSharper restore MemberCanBePrivate.Global

        public VertexPositionTextureNormalBinormalTangent(Vector3 position, Vector2 textureCoordinate, Vector3 normal, Vector3 binormal, Vector3 tangent)
        {
            Position = position.ToXNA();
            TextureCoordinate = textureCoordinate.ToXNA();
            Normal = normal.ToXNA();
            Binormal = binormal.ToXNA();
            Tangent = tangent.ToXNA();
        }
开发者ID:xoxota99,项目名称:Myre,代码行数:11,代码来源:VertexPositionTextureNormalBinormalTangent.cs


示例7: OrientedBox2D

 public OrientedBox2D(float centerX, float centerY, float sizeX, float sizeY, float angle)
 {
     center.X = centerX;
     center.Y = centerY;
     Angle = angle;
     Radii = new Vector2(sizeX / 2.0f, sizeY / 2.0f);
     CalcHelpers();
 }
开发者ID:danielscherzer,项目名称:Framework,代码行数:8,代码来源:OrientedBox2D.cs


示例8: Line

        public SvgBuilder Line(Vector2 start, Vector2 end, float width, string stroke)
        {
            _parts.Add($"<line x1=\"{start.X * Scale}\" y1=\"{start.Y * Scale}\" x2=\"{end.X * Scale}\" y2=\"{end.Y * Scale}\" stroke=\"{stroke}\" stroke-width=\"{width}\" />");

            UpdateMinMax(start, end);

            return this;
        }
开发者ID:martindevans,项目名称:PrimitiveSvgBuilder,代码行数:8,代码来源:SvgBuilder.cs


示例9: VertexMetadata

 public VertexMetadata(float x, float y, float z, float u, float v, Color color, uint faceIndex, uint triangleIndex)
 {
     Position = new Vector4(x, y, z, 1f);
     TextureCoordinate = new Vector2(u, v);
     Color = color;
     FaceIndex = faceIndex;
     TriangleIndex = triangleIndex;
 }
开发者ID:gitter-badger,项目名称:Grasshopper,代码行数:8,代码来源:VertexMetadata.cs


示例10: Circle

        public SvgBuilder Circle(Vector2 center, float radius, string fill = "blue")
        {
            _parts.Add($"<circle cx=\"{center.X * Scale}\" cy=\"{center.Y * Scale}\" r=\"{radius * Scale}\" fill=\"{fill}\"></circle>");

            UpdateMinMax(center - new Vector2(radius));
            UpdateMinMax(center + new Vector2(radius));

            return this;
        }
开发者ID:martindevans,项目名称:PrimitiveSvgBuilder,代码行数:9,代码来源:SvgBuilder.cs


示例11: Operation

 public void Operation(Operations operation)
 {
     Random rand = new Random(84329);
     Vector2 v1 = new Vector2(Convert.ToSingle(rand.NextDouble()), Convert.ToSingle(rand.NextDouble()));
     Vector2 v2 = new Vector2(Convert.ToSingle(rand.NextDouble()), Convert.ToSingle(rand.NextDouble()));
     foreach (var iteration in Benchmark.Iterations)
         using (iteration.StartMeasurement())
             ExecuteTest(operation, 1000000, v1, v2);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:9,代码来源:Perf.Vector2.cs


示例12: RadialGradientStyle

 /// <summary>
 ///     Initializes a new instance of the <see cref="RadialGradientStyle" /> class.
 /// </summary>
 /// <param name="unitOriginOffset">The unit origin offset.</param>
 /// <param name="transform">The transform.</param>
 /// <param name="gradientStops">The gradient stops.</param>
 public RadialGradientStyle(
     Vector2 unitOriginOffset,
     Matrix3x2 transform,
     [NotNull] IReadOnlyList<GradientStop> gradientStops)
     : base(gradientStops)
 {
     UnitOriginOffset = unitOriginOffset;
     GradientTransform = transform;
 }
开发者ID:billings7,项目名称:EscherTilier,代码行数:15,代码来源:RadialGradientStyle.cs


示例13: DrawLine

 public void DrawLine(Vector2 p1, Vector2 p2, Color color, float strokeWidth, CanvasStrokeStyle strokeStyle)
 {
     if (m_renderingType == TestSceneRenderingType.Default)
     {
         m_drawingSession.DrawLine(p1, p2, color, strokeWidth, strokeStyle);
     }
     else
     {
         m_drawingSession.DrawLine(p1, p2, Colors.Black);
     }
 }
开发者ID:gfcprogramer,项目名称:Win2D,代码行数:11,代码来源:TestSceneRenderer.cs


示例14: FillEllipse

 public void FillEllipse(Vector2 center, float radiusX, float radiusY, Color color)
 {
     if (m_renderingType == TestSceneRenderingType.Default)
     {
         m_drawingSession.FillEllipse(center, radiusX, radiusY, color);
     }
     else
     {
         m_drawingSession.DrawEllipse(center, radiusX, radiusY, Colors.Black);
     }
 }
开发者ID:gfcprogramer,项目名称:Win2D,代码行数:11,代码来源:TestSceneRenderer.cs


示例15: TextSprite

 public TextSprite(
     string text,
     FontId font = default(FontId),
     float fontSize = 12,
     Vector2 position = default(Vector2),
     Color? color = null)
 {
     this.Text = text;
     this.Font = font;
     this.FontSize = fontSize;
     this.Position = position;
     this.Color = color ?? Color.White;
 }
开发者ID:OpenLocalization,项目名称:Nine.Graphics,代码行数:13,代码来源:TextSprite.cs


示例16: Arrive

        /// <summary>
        ///     Move to and stop at a specified position.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public static Vector2 Arrive(Vector2 position, Vector2 target)
        {
            /*
                target_offset = target - position
                distance = length (target_offset)
                ramped_speed = max_speed * (distance / slowing_distance)
                clipped_speed = minimum (ramped_speed, max_speed)
                desired_velocity = (clipped_speed / distance) * target_offset
                steering = desired_velocity - velocity
            */

            return Vector2.Zero;
        }
开发者ID:prashast1310,项目名称:Soccer,代码行数:19,代码来源:SteeringStrategies.cs


示例17: ExecuteTest

 public void ExecuteTest(Operations operation, int innerIterations, Vector2 v1, Vector2 v2)
 {
     Vector2 res;
     switch (operation)
     {
         case Operations.Add_Operator:
             for (int i = 0; i < innerIterations; i++)
             { res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; }
             break;
         case Operations.Add_Function:
             for (int i = 0; i < innerIterations; i++)
             { Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); Vector2.Add(v1, v2); }
             break;
         case Operations.Sub_Operator:
             for (int i = 0; i < innerIterations; i++)
             { res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; }
             break;
         case Operations.Sub_Function:
             for (int i = 0; i < innerIterations; i++)
             { Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); Vector2.Subtract(v1, v2); }
             break;
         case Operations.Mul_Operator:
             for (int i = 0; i < innerIterations; i++)
             { res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; }
             break;
         case Operations.Mul_Function:
             for (int i = 0; i < innerIterations; i++)
             { Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); Vector2.Multiply(v1, v2); }
             break;
         case Operations.Dot:
             for (int i = 0; i < innerIterations; i++)
             { Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); Vector2.Dot(v1, v2); }
             break;
         case Operations.SquareRoot:
             for (int i = 0; i < innerIterations; i++)
             { Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); Vector2.SquareRoot(v1); }
             break;
         case Operations.Length_Squared:
             for (int i = 0; i < innerIterations; i++)
             { v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); }
             break;
         case Operations.Normalize:
             for (int i = 0; i < innerIterations; i++)
             { Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); Vector2.Normalize(v1); }
             break;
         case Operations.Distance_Squared:
             for (int i = 0; i < innerIterations; i++)
             { Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); Vector2.DistanceSquared(v1, v2); }
             break;
     }
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:51,代码来源:Perf.Vector2.cs


示例18: GetCircleRectangleCollisionNormal

        /// <summary>
        ///     Determines if a circle and rectangle intersect.
        /// </summary>
        /// <param name="center">The center of the circle.</param>
        /// <param name="radius">The radius of the circle.</param>
        /// <param name="rectangle">The rectangle.</param>
        /// <returns>Returns a <see cref="Vector2" /> representing the normal if a collision occurs; otherwise <c>null</c>.</returns>
        public static Vector2? GetCircleRectangleCollisionNormal(Vector2 center, float radius, RectangleF rectangle)
        {
            var contact = center;

            if (contact.X < rectangle.Left) contact.X = rectangle.Left;
            if (contact.X > rectangle.Right) contact.X = rectangle.Right;
            if (contact.Y < rectangle.Top) contact.Y = rectangle.Top;
            if (contact.Y > rectangle.Bottom) contact.Y = rectangle.Bottom;

            var v = new Vector2(contact.X - center.X, contact.Y - center.Y);
            var length = v.Length();

            return length > 0 && length < radius ? v/length : (Vector2?) null;
        }
开发者ID:PurdueSIGAI,项目名称:Soccer,代码行数:21,代码来源:CollisionMath.cs


示例19: Execute

        public override Kick Execute(ISimulation simulation)
        {
            var ballChaser = FootballStrategies.ClosestPlayerToPoint(this.Players, simulation.Ball, 0);
            var kick = Kick.None;

            foreach (var player in Players)
            {
                if (player == ballChaser)
                {
                    //messages[player] = "Chaser";

                    var playersExceptSelf = Players.ToList();
                    playersExceptSelf.Remove(player);

                    player.Force = SteeringStrategies.Pursue(player, simulation.Ball, 1);

                    if ((player.Position - simulation.Ball.Position).Length() < player.Radius + simulation.Ball.Radius) {
                        var isLeftTeam = this.GoalBounds.Left > 0 ? true : false;
                        PointMass[] arr = new PointMass[7];
                        playersExceptSelf.CopyTo(arr, 0);
                        arr[4] = new PointMass(1, 1, 1, 1, new Vector2(isLeftTeam ? this.GoalBounds.Left : this.GoalBounds.Right, this.GoalBounds.Top + (0.2f) * this.GoalBounds.Height), Vector2.Zero);
                        arr[5] = new PointMass(1, 1, 1, 1, new Vector2(isLeftTeam ? this.GoalBounds.Left : this.GoalBounds.Right, this.GoalBounds.Top + (0.5f) * this.GoalBounds.Height), Vector2.Zero);
                        arr[6] = new PointMass(1, 1, 1, 1, new Vector2(isLeftTeam ? this.GoalBounds.Left : this.GoalBounds.Right, this.GoalBounds.Top + (0.8f) * this.GoalBounds.Height), Vector2.Zero);
                        arr[4].id = "GT";
                        arr[5].id = "GM";
                        arr[6].id = "GB";
                        ReadOnlyCollection<PointMass> roc = new ReadOnlyCollection<PointMass>(arr);
                        Vector2 middleOfGoal = new Vector2(isLeftTeam ? this.GoalBounds.Left : this.GoalBounds.Right, this.GoalBounds.Top - (0.5f) * this.GoalBounds.Height);
                        IPointMass kickTarget = ClosestPlayerToPoint(roc, player, 1, middleOfGoal);
                        messages[player] = "Chaser T: " + kickTarget.id;
                        k = kick = FootballStrategies.PassToPlayer(player, kickTarget, simulation.Ball);
                    }  else
                        k = kick = Kick.None;
                }
                else
                {
                    messages[player] = isOutsideOfField(player, simulation.PitchBounds) ? "Outside" : "inside";

                    var allPlayers = simulation.Teams[0].Players.Concat(simulation.Teams[1].Players);
                    if (isOutsideOfField(player, simulation.PitchBounds))
                        player.Force = SteeringStrategies.Seek(player, Vector2.Zero, player.MaxSpeed);
                    else
                        FootballStrategies.SpreadOut(player, allPlayers, simulation.PitchBounds, 150, 100);
                }
            }

            return kick;
        }
开发者ID:PurdueSIGAI,项目名称:SoccerApp,代码行数:48,代码来源:TestTeams.cs


示例20: ComputeAABB

        /// @see Shape.ComputeAABB
        public override void ComputeAABB(out AABB aabb, ref XForm xf)
        {
            Vector2 lower = MathUtils.Multiply(ref xf, _vertices[0]);
            Vector2 upper = lower;

            for (int i = 1; i < _vertexCount; ++i)
            {
                Vector2 v = MathUtils.Multiply(ref xf, _vertices[i]);
                lower = Vector2.Min(lower, v);
                upper = Vector2.Max(upper, v);
            }

            Vector2 r = new Vector2(_radius, _radius);
            aabb.lowerBound = lower - r;
            aabb.upperBound = upper + r;
        }
开发者ID:Nukepayload2,项目名称:Box2D,代码行数:17,代码来源:PolygonShape.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Numerics.Vector3类代码示例发布时间:2022-05-26
下一篇:
C# Numerics.Vector类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap