本文整理汇总了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);
}
示例2: ListBoxTextItem
public ListBoxTextItem(string displayName, string itemValue)
: base(displayName)
{
Padding = new BorderDouble(3);
ItemValue = itemValue;
MinimumSize = new Vector2(Width, Height);
}
示例3: SetNewState
private void SetNewState(VelocityComponentState state)
{
if (_lastState != null)
_previousState = _lastState;
_lastState = state;
Velocity = new Vector2(state.VelocityX, state.VelocityY);
}
示例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();
}
示例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);
}
}
}
示例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;
}
示例7: TrackBallController
public TrackBallController(Vector2 screenCenter, double trackBallRadius)
{
rotationStart = new Vector3();
rotationCurrent = new Vector3();
this.screenCenter = screenCenter;
this.rotationTrackingRadius = trackBallRadius;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例12: LogoElement
public LogoElement(InterfaceElement parent, Vector2 location)
: base(parent, location)
{
Opacity = 1f;
Size = Program.Logo.Size;
}
示例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");
}
示例14: PCircle
public PCircle( Vector2 position, float radius, int sides, bool filled )
: base(filled)
{
this.position = position;
this.radius = radius;
this.sides = sides;
}
示例15: Offset
internal Offset(Vector2 vec, int width, int height)
{
X = vec.X;
Y = vec.Y;
Width = width;
Height = height;
}