/// <summary> /// Create a new point helper. /// </summary> public PointHelper() { enabled = false; selectedAxes = GizmoSelectedAxes.NONE; instances.Add(this); }
/// <summary> /// Determines which axes have been selected by a hovering mouse. /// </summary> /// <param name="Near"></param> /// <param name="Far"></param> /// <param name="Viewport"></param> /// <param name="Projection"></param> /// <param name="View"></param> /// <param name="cam">viewport camera</param> /// <returns></returns> public GizmoSelectedAxes CheckHit(Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, EditorCamera cam) { if (!enabled) { return(GizmoSelectedAxes.NONE); } float dist = Direct3D.Extensions.Distance(cam.Position, position) * 0.0825f; MatrixStack transform = new MatrixStack(); transform.Push(); Matrix transformMatrix = (isTransformLocal) ? localTransformMatrix : globalTransformMatrix; if (pivot == Pivot.CenterOfMass && isTransformLocal) { // we'll need to correct for the difference in local transform and current position variable (which will be in world space) //Vector3 localMatrixGlobalPosition = Vector3.Zero * localTransformMatrix.; Vector3 localPos = (Vector3)Vector3.Transform(Vector3.Zero, localTransformMatrix); Vector3 offset = position - localPos; transformMatrix = Matrix.Multiply(localTransformMatrix, Matrix.Translation(offset)); } transform.LoadMatrix(transformMatrix); transform.NJScale(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist)); switch (mode) { case (TransformMode.TRANFORM_MOVE): if (Gizmo.XMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.X_AXIS); } if (Gizmo.YMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Y_AXIS); } if (Gizmo.ZMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Z_AXIS); } if (!isTransformLocal) // don't even look for these if the transform is local. { if (Gizmo.XYMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.XY_AXIS); } if (Gizmo.ZXMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.XZ_AXIS); } if (Gizmo.ZYMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.ZY_AXIS); } } break; case (TransformMode.TRANSFORM_ROTATE): if (Gizmo.XRotateMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.X_AXIS); } if (Gizmo.YRotateMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Y_AXIS); } if (Gizmo.ZRotateMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Z_AXIS); } break; case (TransformMode.TRANSFORM_SCALE): if (Gizmo.XScaleMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.X_AXIS); } if (Gizmo.YScaleMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Y_AXIS); } if (Gizmo.ZScaleMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Z_AXIS); } break; default: selectedAxes = GizmoSelectedAxes.NONE; break; } return(GizmoSelectedAxes.NONE); }
private void Panel1_MouseMove(object sender, MouseEventArgs e) { if (!loaded) { return; } Point evloc = e.Location; if (lastmouse == Point.Empty) { lastmouse = evloc; return; } Point chg = evloc - (Size)lastmouse; if (e.Button == MouseButtons.Middle) { // all cam controls are now bound to the middle mouse button if (cam.mode == 0) { if (zoomKeyDown) { cam.Position += cam.Look * (chg.Y * cam.MoveSpeed); } else if (lookKeyDown) { cam.Yaw = unchecked ((ushort)(cam.Yaw - chg.X * 0x10)); cam.Pitch = unchecked ((ushort)(cam.Pitch - chg.Y * 0x10)); } else if (!lookKeyDown && !zoomKeyDown) // pan { cam.Position += cam.Up * (chg.Y * cam.MoveSpeed); cam.Position += cam.Right * (chg.X * cam.MoveSpeed) * -1; } } else if (cam.mode == 1) { if (zoomKeyDown) { cam.Distance += (chg.Y * cam.MoveSpeed) * 3; } else if (lookKeyDown) { cam.Yaw = unchecked ((ushort)(cam.Yaw - chg.X * 0x10)); cam.Pitch = unchecked ((ushort)(cam.Pitch - chg.Y * 0x10)); } else if (!lookKeyDown && !zoomKeyDown) // pan { cam.FocalPoint += cam.Up * (chg.Y * cam.MoveSpeed); cam.FocalPoint += cam.Right * (chg.X * cam.MoveSpeed) * -1; } } DrawLevel(); } if (e.Button == MouseButtons.Left) { if (transformGizmo != null) { //transformGizmo.TransformAffected(chg.X / 2, chg.Y / 2, cam); //throw new System.NotImplementedException(); } DrawLevel(); Rectangle scrbnds = Screen.GetBounds(Cursor.Position); if (Cursor.Position.X == scrbnds.Left) { Cursor.Position = new Point(scrbnds.Right - 2, Cursor.Position.Y); evloc = new Point(evloc.X + scrbnds.Width - 2, evloc.Y); } else if (Cursor.Position.X == scrbnds.Right - 1) { Cursor.Position = new Point(scrbnds.Left + 1, Cursor.Position.Y); evloc = new Point(evloc.X - scrbnds.Width + 1, evloc.Y); } if (Cursor.Position.Y == scrbnds.Top) { Cursor.Position = new Point(Cursor.Position.X, scrbnds.Bottom - 2); evloc = new Point(evloc.X, evloc.Y + scrbnds.Height - 2); } else if (Cursor.Position.Y == scrbnds.Bottom - 1) { Cursor.Position = new Point(Cursor.Position.X, scrbnds.Top + 1); evloc = new Point(evloc.X, evloc.Y - scrbnds.Height + 1); } } else if (e.Button == MouseButtons.None) { float mindist = cam.DrawDistance; // initialize to max distance, because it will get smaller on each check Vector3 mousepos = new Vector3(e.X, e.Y, 0); Viewport viewport = d3ddevice.Viewport; Matrix proj = d3ddevice.GetTransform(TransformState.Projection); Matrix view = d3ddevice.GetTransform(TransformState.View); Vector3 Near, Far; Near = mousepos; Near.Z = 0; Far = Near; Far.Z = -1; if (transformGizmo != null) { GizmoSelectedAxes oldSelection = transformGizmo.SelectedAxes; transformGizmo.SelectedAxes = transformGizmo.CheckHit(Near, Far, viewport, proj, view, cam); if (oldSelection != transformGizmo.SelectedAxes) { transformGizmo.Draw(d3ddevice, cam); } } } lastmouse = evloc; }
/// <summary> /// Determines which axes have been selected by a hovering mouse. /// </summary> /// <param name="Near"></param> /// <param name="Far"></param> /// <param name="Viewport"></param> /// <param name="Projection"></param> /// <param name="View"></param> /// <param name="cam">viewport camera</param> /// <returns></returns> public GizmoSelectedAxes CheckHit(Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, EditorCamera cam) { if (!enabled) return GizmoSelectedAxes.NONE; MatrixStack transform = new MatrixStack(); transform.Push(); float dist = Direct3D.Extensions.Distance(cam.Position, position) * 0.0825f; transform.TranslateLocal(position.X, position.Y, position.Z); transform.RotateXYZLocal(rotation.X, rotation.Y, rotation.Z); transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist)); Vector3 pos = Vector3.Unproject(Near, Viewport, Projection, View, transform.Top); Vector3 dir = Vector3.Subtract(pos, Vector3.Unproject(Far, Viewport, Projection, View, transform.Top)); IntersectInformation info; switch (mode) { case (TransformMode.TRANFORM_MOVE): if (Gizmo.XMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.X_AXIS; if (Gizmo.YMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.Y_AXIS; if (Gizmo.ZMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.Z_AXIS; if (!isTransformLocal) // don't even look for these if the transform is local. { if (Gizmo.XYMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.XY_AXIS; if (Gizmo.ZXMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.XZ_AXIS; if (Gizmo.ZYMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.ZY_AXIS; } break; case (TransformMode.TRANSFORM_ROTATE): if (Gizmo.XRotateMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.X_AXIS; if (Gizmo.YRotateMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.Y_AXIS; if (Gizmo.ZRotateMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.Z_AXIS; break; case (TransformMode.TRANSFORM_SCALE): if (Gizmo.XScaleMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.X_AXIS; if (Gizmo.YScaleMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.Y_AXIS; if (Gizmo.ZScaleMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.Z_AXIS; break; default: selectedAxes = GizmoSelectedAxes.NONE; break; } return GizmoSelectedAxes.NONE; }
public void SetPoint(Vertex point) { affectedPoint = point; enabled = true; selectedAxes = GizmoSelectedAxes.NONE; }
private void Panel1_MouseMove(object sender, MouseEventArgs e) { if (!isStageLoaded) { return; } bool draw = false; bool gizmo = false; switch (e.Button) { case MouseButtons.Middle: break; case MouseButtons.Left: if (transformGizmo.TransformGizmoMove(cam.mouseDelta, cam, selectedItems)) { unsaved = true; if (transformGizmo.SelectedAxes != GizmoSelectedAxes.NONE) { gizmo = true; } NeedPropertyRefresh = true; } foreach (PointHelper pointHelper in PointHelper.Instances) { if (pointHelper.TransformAffected(cam.mouseDelta.X / 2 * cam.MoveSpeed, cam.mouseDelta.Y / 2 * cam.MoveSpeed, cam)) { unsaved = true; } } draw = true; break; case MouseButtons.None: Vector3 mousepos = new Vector3(e.X, e.Y, 0); Viewport viewport = d3ddevice.Viewport; Matrix proj = d3ddevice.GetTransform(TransformState.Projection); Matrix view = d3ddevice.GetTransform(TransformState.View); Vector3 Near = mousepos; Near.Z = 0; Vector3 Far = Near; Far.Z = -1; GizmoSelectedAxes oldSelection = transformGizmo.SelectedAxes; transformGizmo.SelectedAxes = transformGizmo.CheckHit(Near, Far, viewport, proj, view, cam); if (oldSelection != transformGizmo.SelectedAxes) { draw = true; break; } foreach (PointHelper pointHelper in PointHelper.Instances) { GizmoSelectedAxes oldHelperAxes = pointHelper.SelectedAxes; pointHelper.SelectedAxes = pointHelper.CheckHit(Near, Far, viewport, proj, view, cam); if (oldHelperAxes != pointHelper.SelectedAxes) { pointHelper.Draw(d3ddevice, cam); draw = true; } } break; } mouseBounds = (wrapAroundScreenEdgesToolStripMenuItem.Checked) ? Screen.GetBounds(ClientRectangle) : RenderPanel.RectangleToScreen(RenderPanel.Bounds); EditorCamera.CameraUpdateFlags camresult = cam.UpdateCamera(new Point(Cursor.Position.X, Cursor.Position.Y), mouseBounds, lookKeyDown, zoomKeyDown, cameraKeyDown, hideCursorDuringCameraMovementToolStripMenuItem.Checked, gizmo); if (camresult.HasFlag(EditorCamera.CameraUpdateFlags.Redraw) || draw) { NeedRedraw = true; } }
/// <summary> /// Determines which axes have been selected by a hovering mouse. /// </summary> /// <param name="Near"></param> /// <param name="Far"></param> /// <param name="Viewport"></param> /// <param name="Projection"></param> /// <param name="View"></param> /// <param name="cam">viewport camera</param> /// <returns></returns> public GizmoSelectedAxes CheckHit(Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, EditorCamera cam) { if (!enabled) { return(GizmoSelectedAxes.NONE); } MatrixStack transform = new MatrixStack(); transform.Push(); float dist = Direct3D.Extensions.Distance(cam.Position, position) * 0.0825f; transform.TranslateLocal(position.X, position.Y, position.Z); transform.RotateXYZLocal(rotation.X, rotation.Y, rotation.Z); transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist)); Vector3 pos = Vector3.Unproject(Near, Viewport, Projection, View, transform.Top); Vector3 dir = Vector3.Subtract(pos, Vector3.Unproject(Far, Viewport, Projection, View, transform.Top)); IntersectInformation info; switch (mode) { case (TransformMode.TRANFORM_MOVE): if (Gizmo.XMoveMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.X_AXIS); } if (Gizmo.YMoveMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.Y_AXIS); } if (Gizmo.ZMoveMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.Z_AXIS); } if (!isTransformLocal) // don't even look for these if the transform is local. { if (Gizmo.XYMoveMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.XY_AXIS); } if (Gizmo.ZXMoveMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.XZ_AXIS); } if (Gizmo.ZYMoveMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.ZY_AXIS); } } break; case (TransformMode.TRANSFORM_ROTATE): if (Gizmo.XRotateMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.X_AXIS); } if (Gizmo.YRotateMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.Y_AXIS); } if (Gizmo.ZRotateMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.Z_AXIS); } break; case (TransformMode.TRANSFORM_SCALE): if (Gizmo.XScaleMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.X_AXIS); } if (Gizmo.YScaleMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.Y_AXIS); } if (Gizmo.ZScaleMesh.Intersect(pos, dir, out info)) { return(GizmoSelectedAxes.Z_AXIS); } break; default: selectedAxes = GizmoSelectedAxes.NONE; break; } return(GizmoSelectedAxes.NONE); }
/// <summary> /// Determines which axes have been selected by a hovering mouse. /// </summary> /// <param name="Near"></param> /// <param name="Far"></param> /// <param name="Viewport"></param> /// <param name="Projection"></param> /// <param name="View"></param> /// <param name="cam">viewport camera</param> /// <returns></returns> public GizmoSelectedAxes CheckHit(Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, EditorCamera cam) { if (!enabled) { return(GizmoSelectedAxes.NONE); } float dist = Direct3D.Extensions.Distance(cam.Position, position) * 0.0825f; MatrixStack transform = new MatrixStack(); transform.Push(); Matrix transformMatrix = (isTransformLocal) ? localTransformMatrix : globalTransformMatrix; transform.LoadMatrix(transformMatrix); transform.NJScale(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist)); switch (mode) { case (TransformMode.TRANFORM_MOVE): if (Gizmo.XMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.X_AXIS); } if (Gizmo.YMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Y_AXIS); } if (Gizmo.ZMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Z_AXIS); } if (!isTransformLocal) // don't even look for these if the transform is local. { if (Gizmo.XYMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.XY_AXIS); } if (Gizmo.ZXMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.XZ_AXIS); } if (Gizmo.ZYMoveMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.ZY_AXIS); } } break; case (TransformMode.TRANSFORM_ROTATE): if (Gizmo.XRotateMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.X_AXIS); } if (Gizmo.YRotateMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Y_AXIS); } if (Gizmo.ZRotateMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Z_AXIS); } break; case (TransformMode.TRANSFORM_SCALE): if (Gizmo.XScaleMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.X_AXIS); } if (Gizmo.YScaleMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Y_AXIS); } if (Gizmo.ZScaleMesh.CheckHit(Near, Far, Viewport, Projection, View, transform).IsHit) { return(GizmoSelectedAxes.Z_AXIS); } break; default: selectedAxes = GizmoSelectedAxes.NONE; break; } return(GizmoSelectedAxes.NONE); }