本文整理汇总了C#中Sledge.UI.Viewport2D.ScreenToWorld方法的典型用法代码示例。如果您正苦于以下问题:C# Viewport2D.ScreenToWorld方法的具体用法?C# Viewport2D.ScreenToWorld怎么用?C# Viewport2D.ScreenToWorld使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sledge.UI.Viewport2D
的用法示例。
在下文中一共展示了Viewport2D.ScreenToWorld方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTransformationMatrix
public override Matrix4? GetTransformationMatrix(Viewport2D viewport, ViewportEvent e, BaseBoxTool.BoxState state, Document doc, IEnumerable<Widget> activeWidgets)
{
var origin = viewport.ZeroUnusedCoordinate((state.PreTransformBoxStart + state.PreTransformBoxEnd) / 2);
var rw = activeWidgets.OfType<RotationWidget>().FirstOrDefault();
if (rw != null) origin = rw.GetPivotPoint();
var forigin = viewport.Flatten(origin);
var origv = (state.MoveStart - forigin).Normalise();
var newv = (viewport.ScreenToWorld(e.X, viewport.Height - e.Y) - forigin).Normalise();
var angle = DMath.Acos(Math.Max(-1, Math.Min(1, origv.Dot(newv))));
if ((origv.Cross(newv).Z < 0)) angle = 2 * DMath.PI - angle;
var shf = KeyboardState.Shift;
var def = Select.RotationStyle;
var snap = (def == RotationStyle.SnapOnShift && shf) || (def == RotationStyle.SnapOffShift && !shf);
if (snap)
{
var deg = angle * (180 / DMath.PI);
var rnd = Math.Round(deg / 15) * 15;
angle = rnd * (DMath.PI / 180);
}
Matrix4 rotm;
if (viewport.Direction == Viewport2D.ViewDirection.Top) rotm = Matrix4.CreateRotationZ((float)angle);
else if (viewport.Direction == Viewport2D.ViewDirection.Front) rotm = Matrix4.CreateRotationX((float)angle);
else rotm = Matrix4.CreateRotationY((float)-angle); // The Y axis rotation goes in the reverse direction for whatever reason
var mov = Matrix4.CreateTranslation((float)-origin.X, (float)-origin.Y, (float)-origin.Z);
var rot = Matrix4.Mult(mov, rotm);
return Matrix4.Mult(rot, Matrix4.Invert(mov));
}
示例2: BeforeRender2D
public void BeforeRender2D(Viewport2D viewport)
{
_offset = 3 / (double)viewport.Zoom;
_fadeDistance = 200 / (double)viewport.Zoom;
var mp = viewport.PointToClient(Control.MousePosition);
_mousePos = viewport.ScreenToWorld(new Coordinate(mp.X, viewport.Height - mp.Y, 0));
GL.Enable(EnableCap.LineSmooth);
GL.Begin(BeginMode.Lines);
}
示例3: GetTransformationMatrix
public override Matrix4? GetTransformationMatrix(Viewport2D viewport, ViewportEvent e, BaseBoxTool.BoxState state, Document doc)
{
var shearUpDown = state.Handle == BaseBoxTool.ResizeHandle.Left || state.Handle == BaseBoxTool.ResizeHandle.Right;
var shearTopRight = state.Handle == BaseBoxTool.ResizeHandle.Top || state.Handle == BaseBoxTool.ResizeHandle.Right;
var nsmd = viewport.ScreenToWorld(e.X, viewport.Height - e.Y) - state.MoveStart;
var mouseDiff = SnapIfNeeded(nsmd, doc);
if (KeyboardState.Shift)
{
mouseDiff = doc.Snap(nsmd, doc.Map.GridSpacing / 2);
}
var relative = viewport.Flatten(state.PreTransformBoxEnd - state.PreTransformBoxStart);
var shearOrigin = (shearTopRight) ? state.PreTransformBoxStart : state.PreTransformBoxEnd;
var shearAmount = new Coordinate(mouseDiff.X / relative.Y, mouseDiff.Y / relative.X, 0);
if (!shearTopRight) shearAmount *= -1;
var shearMatrix = Matrix4.Identity;
var sax = (float)shearAmount.X;
var say = (float)shearAmount.Y;
switch (viewport.Direction)
{
case Viewport2D.ViewDirection.Top:
if (shearUpDown) shearMatrix.M12 = say;
else shearMatrix.M21 = sax;
break;
case Viewport2D.ViewDirection.Front:
if (shearUpDown) shearMatrix.M23 = say;
else shearMatrix.M32 = sax;
break;
case Viewport2D.ViewDirection.Side:
if (shearUpDown) shearMatrix.M13 = say;
else shearMatrix.M31 = sax;
break;
}
var stran = Matrix4.CreateTranslation((float)-shearOrigin.X, (float)-shearOrigin.Y, (float)-shearOrigin.Z);
var shear = Matrix4.Mult(stran, shearMatrix);
return Matrix4.Mult(shear, Matrix4.Invert(stran));
}
示例4: GetStateAtPoint
private State GetStateAtPoint(int x, int y, Viewport2D viewport)
{
var cam = GetCamera();
if (cam == null) return State.None;
var p = viewport.ScreenToWorld(x, y);
var pos = viewport.Flatten(cam.Item1);
var look = pos + (viewport.Flatten(cam.Item2) - pos).Normalise() * 50 / viewport.Zoom;
var d = 5 / viewport.Zoom;
if (p.X >= pos.X - d && p.X <= pos.X + d && p.Y >= pos.Y - d && p.Y <= pos.Y + d) return State.MovingPosition;
//todo... if (p.X >= look.X - d && p.X <= look.X + d && p.Y >= look.Y - d && p.Y <= look.Y + d) return State.MovingLook;
return State.None;
}
示例5: GetVerticesAtPoint
public override List<VMPoint> GetVerticesAtPoint(int x, int y, Viewport2D viewport)
{
var verts = MainTool.GetVerticesAtPoint(x, y, viewport);
var p = viewport.ScreenToWorld(x, y);
var d = 8 / viewport.Zoom; // Tolerance value = 8 pixels
var c = viewport.Flatten(_origin.Coordinate);
if (p.X >= c.X - d && p.X <= c.X + d && p.Y >= c.Y - d && p.Y <= c.Y + d)
{
verts.Insert(0, _origin);
}
return verts;
}
示例6: MouseHoverWhenDrawn
protected virtual void MouseHoverWhenDrawn(Viewport2D viewport, ViewportEvent e)
{
var now = viewport.ScreenToWorld(e.X, viewport.Height - e.Y);
var start = viewport.Flatten(State.BoxStart);
var end = viewport.Flatten(State.BoxEnd);
var handle = GetHandle(now, start, end, HandleWidth / viewport.Zoom);
if (handle.HasValue)
{
viewport.Cursor = CursorForHandle(handle.Value);
State.Handle = handle.Value;
State.Action = BoxAction.ReadyToResize;
State.ActiveViewport = viewport;
}
else
{
viewport.Cursor = Cursors.Default;
State.Action = BoxAction.Drawn;
State.ActiveViewport = null;
}
}
示例7: LeftMouseDownToResize
protected virtual void LeftMouseDownToResize(Viewport2D viewport, ViewportEvent e)
{
State.ActiveViewport = viewport;
State.Action = BoxAction.DownToResize;
State.MoveStart = viewport.ScreenToWorld(e.X, viewport.Height - e.Y);
State.PreTransformBoxStart = State.BoxStart;
State.PreTransformBoxEnd = State.BoxEnd;
}
示例8: LeftMouseDownToDraw
protected virtual void LeftMouseDownToDraw(Viewport2D viewport, ViewportEvent e)
{
State.ActiveViewport = viewport;
State.Action = BoxAction.DownToDraw;
State.BoxStart = SnapIfNeeded(viewport.Expand(viewport.ScreenToWorld(e.X, viewport.Height - e.Y)));
State.BoxEnd = State.BoxStart;
State.Handle = ResizeHandle.BottomLeft;
OnBoxChanged();
}
示例9: GetResizeDistance
protected virtual Coordinate GetResizeDistance(Viewport2D viewport, ViewportEvent e)
{
var origin = GetResizeOrigin(viewport);
if (origin == null) return null;
var before = State.MoveStart;
var after = viewport.ScreenToWorld(e.X, viewport.Height - e.Y);
return SnapIfNeeded(origin + after - before) - origin;
}
示例10: SelectionTest
private MapObject SelectionTest(Viewport2D viewport, ViewportEvent e)
{
// Create a box to represent the click, with a tolerance level
var unused = viewport.GetUnusedCoordinate(new Coordinate(100000, 100000, 100000));
var tolerance = 4 / viewport.Zoom; // Selection tolerance of four pixels
var used = viewport.Expand(new Coordinate(tolerance, tolerance, 0));
var add = used + unused;
var click = viewport.Expand(viewport.ScreenToWorld(e.X, viewport.Height - e.Y));
var box = new Box(click - add, click + add);
var centerHandles = Sledge.Settings.Select.DrawCenterHandles;
var centerOnly = Sledge.Settings.Select.ClickSelectByCenterHandlesOnly;
// Get the first element that intersects with the box, selecting or deselecting as needed
return Document.Map.WorldSpawn.GetAllNodesIntersecting2DLineTest(box, centerHandles, centerOnly).FirstOrDefault();
}
示例11: GetStateAtPoint
private State GetStateAtPoint(int x, int y, Viewport2D viewport, out Camera activeCamera)
{
var d = 5 / viewport.Zoom;
foreach (var cam in GetCameras())
{
var p = viewport.ScreenToWorld(x, y);
var pos = viewport.Flatten(cam.EyePosition);
var look = viewport.Flatten(cam.LookPosition);
activeCamera = cam;
if (p.X >= pos.X - d && p.X <= pos.X + d && p.Y >= pos.Y - d && p.Y <= pos.Y + d) return State.MovingPosition;
if (p.X >= look.X - d && p.X <= look.X + d && p.Y >= look.Y - d && p.Y <= look.Y + d) return State.MovingLook;
}
activeCamera = null;
return State.None;
}
示例12: GetStateAtPoint
private ClipState GetStateAtPoint(int x, int y, Viewport2D viewport)
{
if (_clipPlanePoint1 == null || _clipPlanePoint2 == null || _clipPlanePoint3 == null) return ClipState.None;
var p = viewport.ScreenToWorld(x, y);
var p1 = viewport.Flatten(_clipPlanePoint1);
var p2 = viewport.Flatten(_clipPlanePoint2);
var p3 = viewport.Flatten(_clipPlanePoint3);
var d = 5 / viewport.Zoom;
if (p.X >= p1.X - d && p.X <= p1.X + d && p.Y >= p1.Y - d && p.Y <= p1.Y + d) return ClipState.MovingPoint1;
if (p.X >= p2.X - d && p.X <= p2.X + d && p.Y >= p2.Y - d && p.Y <= p2.Y + d) return ClipState.MovingPoint2;
if (p.X >= p3.X - d && p.X <= p3.X + d && p.Y >= p3.Y - d && p.Y <= p3.Y + d) return ClipState.MovingPoint3;
return ClipState.None;
}
示例13: OverrideViewportContextMenu
public override void OverrideViewportContextMenu(ViewportContextMenu menu, Viewport2D vp, ViewportEvent e)
{
menu.Items.Clear();
var point = vp.ScreenToWorld(e.X, vp.Height - e.Y);
var loc = vp.Flatten(_location);
if ((loc-point).VectorMagnitude() < 10)
{
var item = new ToolStripMenuItem("Create Object");
item.Click += (sender, args) => CreateEntity(_location);
menu.Items.Add(item);
}
}
示例14: ViewportRightClick
public void ViewportRightClick(Viewport2D vp, ViewportEvent e)
{
ViewportContextMenu.Instance.AddNonSelectionItems(_document, vp);
if (!_document.Selection.IsEmpty() && !_document.Selection.InFaceSelection && ToolManager.ActiveTool is SelectTool)
{
var selectionBoundingBox = _document.Selection.GetSelectionBoundingBox();
var point = vp.ScreenToWorld(e.X, vp.Height - e.Y);
var start = vp.Flatten(selectionBoundingBox.Start);
var end = vp.Flatten(selectionBoundingBox.End);
if (point.X >= start.X && point.X <= end.X && point.Y >= start.Y && point.Y <= end.Y)
{
// Clicked inside the selection bounds
ViewportContextMenu.Instance.AddSelectionItems(_document, vp);
}
}
if (ToolManager.ActiveTool != null) ToolManager.ActiveTool.OverrideViewportContextMenu(ViewportContextMenu.Instance, vp, e);
if (ViewportContextMenu.Instance.Items.Count > 0) ViewportContextMenu.Instance.Show(vp, e.X, e.Y);
}
示例15: GetBoxCoordinatesForSelectionResize
private Tuple<Coordinate, Coordinate> GetBoxCoordinatesForSelectionResize(Viewport2D viewport, ViewportEvent e, BaseBoxTool.BoxState state, Document document)
{
if (state.Action != BaseBoxTool.BoxAction.Resizing) return Tuple.Create(state.BoxStart, state.BoxEnd);
var now = SnapIfNeeded(viewport.ScreenToWorld(e.X, viewport.Height - e.Y), document);
var cstart = viewport.Flatten(state.BoxStart);
var cend = viewport.Flatten(state.BoxEnd);
switch (state.Handle)
{
case BaseBoxTool.ResizeHandle.TopLeft:
cstart.X = Math.Min(now.X, cend.X - 1);
cend.Y = Math.Max(now.Y, cstart.Y + 1);
break;
case BaseBoxTool.ResizeHandle.Top:
cend.Y = Math.Max(now.Y, cstart.Y + 1);
break;
case BaseBoxTool.ResizeHandle.TopRight:
cend.X = Math.Max(now.X, cstart.X + 1);
cend.Y = Math.Max(now.Y, cstart.Y + 1);
break;
case BaseBoxTool.ResizeHandle.Left:
cstart.X = Math.Min(now.X, cend.X - 1);
break;
case BaseBoxTool.ResizeHandle.Center:
var cdiff = cend - cstart;
cstart = viewport.Flatten(state.PreTransformBoxStart) + now - SnapIfNeeded(state.MoveStart, document);
cend = cstart + cdiff;
break;
case BaseBoxTool.ResizeHandle.Right:
cend.X = Math.Max(now.X, cstart.X + 1);
break;
case BaseBoxTool.ResizeHandle.BottomLeft:
cstart.X = Math.Min(now.X, cend.X - 1);
cstart.Y = Math.Min(now.Y, cend.Y - 1);
break;
case BaseBoxTool.ResizeHandle.Bottom:
cstart.Y = Math.Min(now.Y, cend.Y - 1);
break;
case BaseBoxTool.ResizeHandle.BottomRight:
cend.X = Math.Max(now.X, cstart.X + 1);
cstart.Y = Math.Min(now.Y, cend.Y - 1);
break;
default:
throw new ArgumentOutOfRangeException();
}
return SnapBoxCoordinatesIfNeeded(viewport, state, document, cstart, cend);
}