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


C# System.Vector2类代码示例

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


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

示例1: Capture

        public unsafe void Capture(Vector2 targetSize)
        {
            if (_previousTargetSize != targetSize)
            {
                SetupBuffers(targetSize);
                _previousTargetSize = targetSize;
            }

            _pboIndex = (_pboIndex + 1) % 2;
            _nextPboIndex = (_pboIndex + 1) % 2;

            var frame = _frameCache[_cachedFramesIndex++];
            _cachedFramesIndex %= _numberOfCachedFrames;

            frame.FrameIndex = _frameIndex++;

            GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
            GL.BindBuffer(BufferTarget.PixelPackBuffer, _pboIds[_pboIndex]);
            GL.ReadPixels(0, 0, (int)targetSize.X, (int)targetSize.Y, PixelFormat.Bgra, PixelType.UnsignedByte, (IntPtr)0);

            GL.BindBuffer(BufferTarget.PixelPackBuffer, _pboIds[_nextPboIndex]);
            var ptr = GL.MapBufferRange(BufferTarget.PixelPackBuffer, (IntPtr)0, (IntPtr)GetTargetSizeInBytes(targetSize), BufferAccessMask.MapReadBit);

            fixed (byte* data = frame.Bytes)
            {
                memcpy((IntPtr)data, ptr, GetTargetSizeInBytes(targetSize));
            }

            GL.UnmapBuffer(BufferTarget.PixelPackBuffer);
            GL.BindBuffer(BufferTarget.PixelPackBuffer, 0);
            GL.ReadBuffer(ReadBufferMode.Back);

            _frames.TryAdd(frame);
        }
开发者ID:BraveSirAndrew,项目名称:DualityScreenCapturePlugin,代码行数:34,代码来源:ScreenCaptureStream.cs

示例2: ListBoxTextItem

		public ListBoxTextItem(string displayName, string itemValue)
			: base(displayName)
		{
			Padding = new BorderDouble(3);
			ItemValue = itemValue;
			MinimumSize = new Vector2(Width, Height);
		}
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:7,代码来源:ListBox.cs

示例3: SetNewState

 private void SetNewState(VelocityComponentState state)
 {
     if (_lastState != null)
         _previousState = _lastState;
     _lastState = state;
     Velocity = new Vector2(state.VelocityX, state.VelocityY);
 }
开发者ID:millpond,项目名称:space-station-14,代码行数:7,代码来源:VelocityComponent.cs

示例4: PartPreviewMainWindow

		public PartPreviewMainWindow(PrintItemWrapper printItem, View3DWidget.AutoRotate autoRotate3DView, View3DWidget.OpenMode openMode = View3DWidget.OpenMode.Viewing)
			: base(750, 550)
		{
			UseOpenGL = true;
			string partPreviewTitle = LocalizedString.Get("MatterControl");
			Title = string.Format("{0}: ", partPreviewTitle) + Path.GetFileName(printItem.Name);

			this.Name = "Part Preview Window";

			partPreviewWidget = new PartPreviewContent(printItem, View3DWidget.WindowMode.StandAlone, autoRotate3DView, openMode);
			partPreviewWidget.Closed += (sender, e) =>
			{
				Close();
			};

			this.AddChild(partPreviewWidget);

			AddHandlers();

			Width = 750;
			Height = 550;

			MinimumSize = new Vector2(400, 300);
			ShowAsSystemWindow();
		}
开发者ID:unlimitedbacon,项目名称:MatterControl,代码行数:25,代码来源:PartPreviewMainWindow.cs

示例5: OnDraw

 private static void OnDraw(EventArgs args)
 {
     if (Enabled)
     {
         foreach (
             var unit in ObjectManager.Get<Obj_AI_Hero>().Where(u => u.IsValidTarget() && u.IsHPBarRendered))
         {
             // Get damage to unit
             var damage = damageToUnit(unit);
             // Continue on 0 damage
             if (damage <= 0)
             {
                 continue;
             }
             // Get remaining HP after damage applied in percent and the current percent of health
             var damagePercentage = ((unit.Health - damage) > 0 ? (unit.Health - damage) : 0) / unit.MaxHealth;
             var currentHealthPercentage = unit.Health / unit.MaxHealth;
             // Calculate start and end point of the bar indicator
             var startPoint =
                 new Vector2(
                     (int) (unit.HPBarPosition.X + BarOffset.X + damagePercentage * BarWidth),
                     (int) (unit.HPBarPosition.Y + BarOffset.Y) - 5);
             var endPoint =
                 new Vector2(
                     (int) (unit.HPBarPosition.X + BarOffset.X + currentHealthPercentage * BarWidth) + 1,
                     (int) (unit.HPBarPosition.Y + BarOffset.Y) - 5);
             // Draw the line
             Drawing.DrawLine(startPoint, endPoint, LineThickness, DrawingColor);
         }
     }
 }
开发者ID:blacky,项目名称:LeagueSharp,代码行数:31,代码来源:DamageIndicator.cs

示例6: OnMouseMove

 public void OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     var mouseState = Mouse.GetState();
     var keyboardState = Keyboard.GetState();
     var currentMouseCoordinate = new Vector2(e.X, e.Y);
     if (keyboardState.IsKeyDown(Key.ShiftLeft) && (mouseState[MouseButton.Middle] || (mouseState[MouseButton.Left] && keyboardState[Key.ControlLeft])))
     {
         var d = 5;
         var previousMouseWorldCoordinate = Maths.Project(ViewMatrix, Viewport.ProjectionMatrix, previousMouseCoordinate, (Rectangle)Viewport, Maths.ProjectionTarget.View);
         var mouseWorldCoordinate = Maths.Project(ViewMatrix, ProjectionMatrix, currentMouseCoordinate, (Rectangle)Viewport, Maths.ProjectionTarget.View);
         var delta = mouseWorldCoordinate - previousMouseWorldCoordinate;
         delta *= d;
         panTrack.Update(delta.X, delta.Y);
     }
     else if (keyboardState.IsKeyDown(Key.AltLeft) && (mouseState[MouseButton.Middle] || (mouseState[MouseButton.Left] && keyboardState[Key.ControlLeft])))
     {
         var previousMouseWorldCoordinate = Maths.Project(ViewMatrix, Viewport.ProjectionMatrix, previousMouseCoordinate, (Rectangle)Viewport, Maths.ProjectionTarget.View);
         var mouseWorldCoordinate = Maths.Project(ViewMatrix, ProjectionMatrix, currentMouseCoordinate, (Rectangle)Viewport, Maths.ProjectionTarget.View);
         var delta = mouseWorldCoordinate - previousMouseWorldCoordinate;
         delta *= 10;
         zoomTrack.Update(delta.Y);
     }
     else if (mouseState[MouseButton.Middle] || (mouseState[MouseButton.Left] && keyboardState[Key.ControlLeft]))
     {
         var delta = currentMouseCoordinate - previousMouseCoordinate;
         //delta *= 10;
         orbitTrack.Update(delta.X, delta.Y);
     }
     if (this.MouseMove != null) this.MouseMove(this, new MouseEventArgs(this, new Vector2(e.X, e.Y), default(Vector3), e.Button));
     previousMouseCoordinate = currentMouseCoordinate;
 }
开发者ID:jacksoncougar,项目名称:Moonfish-Editor,代码行数:31,代码来源:camera.cs

示例7: TrackBallController

		public TrackBallController(Vector2 screenCenter, double trackBallRadius)
		{
			rotationStart = new Vector3();
			rotationCurrent = new Vector3();
			this.screenCenter = screenCenter;
			this.rotationTrackingRadius = trackBallRadius;
		}
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:7,代码来源:TrackBallController.cs

示例8: IsOnScreen

 public static bool IsOnScreen(this Vector2 start, Vector2 end)
 {
     if (start.X > 0 && start.X < Drawing.Width && start.Y > 0 && start.Y < Drawing.Height && end.X > 0 &&
         end.X < Drawing.Width && end.Y > 0 && end.Y < Drawing.Height)
     {
         return true;
     }
     if (start.Intersection(end, new Vector2(0, 0), new Vector2(Drawing.Width, 0)).Intersects)
     {
         return true;
     }
     if (start.Intersection(end, new Vector2(0, 0), new Vector2(0, Drawing.Height)).Intersects)
     {
         return true;
     }
     if (
         start.Intersection(end, new Vector2(0, Drawing.Height), new Vector2(Drawing.Width, Drawing.Height))
             .Intersects)
     {
         return true;
     }
     return
         start.Intersection(end, new Vector2(Drawing.Width, 0), new Vector2(Drawing.Width, Drawing.Height))
             .Intersects;
 }
开发者ID:Lizzaran,项目名称:LeagueSharp-Standalones,代码行数:25,代码来源:VectorExtensions.cs

示例9: SignedDistance

        internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator)
        {
            Vector3 localPosition = position - m_translation;
            Vector3.Transform(ref localPosition, ref m_invRotation, out localPosition);

            var primaryDistance = new Vector2(localPosition.X, localPosition.Z).Length() - m_primaryRadius;
            var signedDistance = new Vector2(primaryDistance, localPosition.Y).Length() - m_secondaryRadius;

            var potentialHalfDeviation = m_potentialHalfDeviation + lodVoxelSize;
            if (signedDistance > potentialHalfDeviation)
                return 1f;
            else if (signedDistance < -potentialHalfDeviation)
                return -1f;

            if (m_enableModulation)
            {
                Debug.Assert(m_deviationFrequency != 0f);
                float normalizer = 0.5f * m_deviationFrequency;
                var tmp = localPosition * normalizer;
                float halfDeviationRatio = (float)macroModulator.GetValue(tmp.X, tmp.Y, tmp.Z);
                signedDistance -= halfDeviationRatio * m_secondaryHalfDeviation;
            }

            if (m_enableModulation && -m_detailSize < signedDistance && signedDistance < m_detailSize)
            {
                Debug.Assert(m_detailFrequency != 0f);
                float normalizer = 0.5f * m_detailFrequency;
                var tmp = localPosition * normalizer;
                signedDistance += m_detailSize * (float)detailModulator.GetValue(tmp.X, tmp.Y, tmp.Z);
            }

            return signedDistance / lodVoxelSize;
        }
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:33,代码来源:MyCsgShapeTorus.cs

示例10: OnUpdate

        public override void OnUpdate(long msec)
        {
            var g2d = Graphics2D.GetInstance ();
            var pos = g2d.GetMousePosition ();

            if (Input.GetKeyDown (KeyCode.Mouse0)) {
                var start = new Vector3 (pos.X, pos.Y, 1000);
                var end = new Vector3 (pos.X, pos.Y, -1000);
                var node = World.Pick (start, end);
                if (node != null) {
                    this.picked = node;
                    this.delta = pos - new Vector2 (node.Position.X, node.Position.Y);
                }
            }
            if (Input.GetKeyUp(KeyCode.Mouse0)) {
                this.picked = null;
            }

            if (picked != null) {
                var t = pos - delta;
                picked.Translation = new Vector3(t.X, t.Y, 0);
            }

            base.OnUpdate (msec);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:25,代码来源:MyFloor.cs

示例11: FindNearestLineCircleIntersections

        public static Vector2 FindNearestLineCircleIntersections(this Vector2 start,
            Vector2 end,
            Vector2 circlePos,
            float radius)
        {
            float t;
            var dx = end.X - start.X;
            var dy = end.Y - start.Y;

            var a = dx * dx + dy * dy;
            var b = 2 * (dx * (start.X - circlePos.X) + dy * (start.Y - circlePos.Y));
            var c = (start.X - circlePos.X) * (start.X - circlePos.X) +
                    (start.Y - circlePos.Y) * (start.Y - circlePos.Y) - radius * radius;

            var det = b * b - 4 * a * c;
            if ((a <= 0.0000001) || (det < 0))
            {
                return Vector2.Zero;
            }
            if (det.Equals(0f))
            {
                t = -b / (2 * a);
                return new Vector2(start.X + t * dx, start.Y + t * dy);
            }

            t = (float)((-b + Math.Sqrt(det)) / (2 * a));
            var intersection1 = new Vector2(start.X + t * dx, start.Y + t * dy);
            t = (float)((-b - Math.Sqrt(det)) / (2 * a));
            var intersection2 = new Vector2(start.X + t * dx, start.Y + t * dy);

            return Vector2.Distance(intersection1, ObjectManager.Player.Position.LSTo2D()) >
                   Vector2.Distance(intersection2, ObjectManager.Player.Position.LSTo2D())
                ? intersection2
                : intersection1;
        }
开发者ID:CainWolf,项目名称:PortAIO,代码行数:35,代码来源:VectorExtensions.cs

示例12: LogoElement

        public LogoElement(InterfaceElement parent, Vector2 location)
            : base(parent, location)
        {
            Opacity = 1f;

            Size = Program.Logo.Size;
        }
开发者ID:andi2,项目名称:ld32-1,代码行数:7,代码来源:LogoElement.cs

示例13: BindWindow

        /// <summary>
        /// Binds to specific events of the provided CoreWindow
        /// </summary>
        /// <param name="nativeWindow">A reference to <see cref="CoreWindow"/> or <see cref="UIElement"/> class.</param>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="nativeWindow"/> is null.</exception>
        /// <exception cref="ArgumentException">Is thrown when <paramref name="nativeWindow"/> is not a <see cref="CoreWindow"/> and not an <see cref="UIElement"/></exception>
        protected override void BindWindow(object nativeWindow)
        {
            if (nativeWindow == null) throw new ArgumentNullException("nativeWindow");
            var window = nativeWindow as CoreWindow;
            if (window != null)
            {
                windowSize = new Size2F((float)window.Bounds.Width, (float)window.Bounds.Height);
                var position = window.PointerPosition;
                pointerPosition = new Vector2((float)position.X/windowSize.Width, (float)position.Y / windowSize.Height);

                window.PointerPressed += HandleWindowPointerEvent;
                window.PointerReleased += HandleWindowPointerEvent;
                window.PointerWheelChanged += HandleWindowPointerEvent;
                window.PointerMoved += HandleWindowPointerEvent;
                window.SizeChanged += window_SizeChanged;
                return;
            }

            uiElement = nativeWindow as FrameworkElement;
            if (uiElement != null)
            {
                windowSize = new Size2F((float)uiElement.ActualWidth, (float)uiElement.ActualHeight);
                uiElement.Loaded += HandleLoadedEvent;
                uiElement.SizeChanged += HandleSizeChangedEvent;
                uiElement.PointerPressed += HandleUIElementPointerEvent;
                uiElement.PointerReleased += HandleUIElementPointerEvent;
                uiElement.PointerWheelChanged += HandleUIElementPointerEvent;
                uiElement.PointerMoved += HandleUIElementPointerEvent;
                uiElement.PointerEntered += HandleUIElementPointerEvent;
                return;
            }

            throw new ArgumentException("Should be an instance of either CoreWindow or UIElement", "nativeWindow");
        }
开发者ID:chantsunman,项目名称:Toolkit,代码行数:40,代码来源:MousePlatformWinRt.cs

示例14: PCircle

 public PCircle( Vector2 position, float radius, int sides, bool filled )
     : base(filled)
 {
     this.position = position;
     this.radius = radius;
     this.sides = sides;
 }
开发者ID:adamxi,项目名称:SharpDXFramework,代码行数:7,代码来源:PCircle.cs

示例15: Offset

 internal Offset(Vector2 vec, int width, int height)
 {
     X = vec.X;
     Y = vec.Y;
     Width = width;
     Height = height;
 }
开发者ID:Deprive,项目名称:Private,代码行数:7,代码来源:Drawings.cs


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