public Vector3 MouseOverAxis(IViewportController viewportController, int x, int y) { Ray ray = viewportController.CreateViewportRay(x, y); float th = 0.1f; // thickness float len = 1.1f; // length AxisAlignedBox xBox = CreateOffsetBox(new Vector3(0.0f, -th, -th), new Vector3(len, th, th)); AxisAlignedBox yBox = CreateOffsetBox(new Vector3(-th, 0.0f, -th), new Vector3(th, len, th)); AxisAlignedBox zBox = CreateOffsetBox(new Vector3(-th, -th, 0.0f), new Vector3(th, th, len)); if (ray.Intersects(xBox).first&& !viewportController.CameraController.IsLookingDownAxis(Vector3.UNIT_X)) { return(Vector3.UNIT_X); } if (ray.Intersects(yBox).first&& !viewportController.CameraController.IsLookingDownAxis(Vector3.UNIT_Y)) { return(Vector3.UNIT_Y); } if (ray.Intersects(zBox).first&& !viewportController.CameraController.IsLookingDownAxis(Vector3.UNIT_Z)) { return(Vector3.UNIT_Z); } return(Vector3.ZERO); }
public new void MouseUp(IViewportController viewportController, MouseEventArgs e) { if (Editor.SelectionBox.SelectedObject != null) { Editor.SelectionBox.MouseUp(viewportController, e); } else { Ray ray = viewportController.CreateViewportRay(e.X, e.Y); ISelectableObject selectedObject = null; float d = float.MaxValue; foreach (ISelectableObject selectable in Editor.SelectableObjects) { Pair <bool, float> pair = selectable.RayIntersects(ray, viewportController); if (pair.first && pair.second < d) { d = pair.second; selectedObject = selectable; } } Editor.SelectionBox.SelectedObject = selectedObject; } }
public static Block SelectBlock(IViewportController viewportController, int x, int y) { Ray ray = viewportController.CreateViewportRay(x, y); Block hitBlock = null; float d = float.MaxValue; foreach (Block block in Editor.Blocks) { Pair <bool, float> pair = ray.Intersects(block.BoundingBox); if (pair.first && pair.second < d) { d = pair.second; hitBlock = block; } } return(hitBlock); }
public static Block SelectBlock(IViewportController viewportController, int x, int y) { Ray ray = viewportController.CreateViewportRay(x, y); Block hitBlock = null; float d = float.MaxValue; foreach (Block block in Editor.Blocks) { Pair<bool, float> pair = ray.Intersects(block.BoundingBox); if (pair.first && pair.second < d) { d = pair.second; hitBlock = block; } } return hitBlock; }
public Vector3 MouseOverAxis(IViewportController viewportController, int x, int y) { Ray ray = viewportController.CreateViewportRay(x, y); float th = 0.1f; // thickness float len = 1.1f; // length AxisAlignedBox xBox = CreateOffsetBox(new Vector3(0.0f, -th, -th), new Vector3(len, th, th)); AxisAlignedBox yBox = CreateOffsetBox(new Vector3(-th, 0.0f, -th), new Vector3(th, len, th)); AxisAlignedBox zBox = CreateOffsetBox(new Vector3(-th, -th, 0.0f), new Vector3(th, th, len)); if (ray.Intersects(xBox).first && !viewportController.CameraController.IsLookingDownAxis(Vector3.UNIT_X)) return Vector3.UNIT_X; if (ray.Intersects(yBox).first && !viewportController.CameraController.IsLookingDownAxis(Vector3.UNIT_Y)) return Vector3.UNIT_Y; if (ray.Intersects(zBox).first && !viewportController.CameraController.IsLookingDownAxis(Vector3.UNIT_Z)) return Vector3.UNIT_Z; return Vector3.ZERO; }