public static void RenderDebugAABB(this WorldView worldView, Graphics2D graphics2D, AxisAlignedBoundingBox bounds) { Vector3 renderPosition = bounds.Center; Vector2 objectCenterScreenSpace = worldView.GetScreenPosition(renderPosition); Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y); graphics2D.Circle(objectCenterScreenSpace, 5, Color.Magenta); for (int i = 0; i < 4; i++) { graphics2D.Circle(worldView.GetScreenPosition(bounds.GetTopCorner(i)), 5, Color.Magenta); graphics2D.Circle(worldView.GetScreenPosition(bounds.GetBottomCorner(i)), 5, Color.Magenta); } RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection; for (int i = 0; i < 4; i++) { screenBoundsOfObject3D.ExpandToInclude(worldView.GetScreenPosition(bounds.GetTopCorner(i))); screenBoundsOfObject3D.ExpandToInclude(worldView.GetScreenPosition(bounds.GetBottomCorner(i))); } graphics2D.Circle(screenBoundsOfObject3D.Left, screenBoundsOfObject3D.Bottom, 5, Color.Cyan); graphics2D.Circle(screenBoundsOfObject3D.Left, screenBoundsOfObject3D.Top, 5, Color.Cyan); graphics2D.Circle(screenBoundsOfObject3D.Right, screenBoundsOfObject3D.Bottom, 5, Color.Cyan); graphics2D.Circle(screenBoundsOfObject3D.Right, screenBoundsOfObject3D.Top, 5, Color.Cyan); }
public static void RenderAabb(this WorldView world, AxisAlignedBoundingBox bounds, Matrix4X4 matrix, Color color, double width, double extendLineLength = 0) { GLHelper.PrepareFor3DLineRender(true); Frustum frustum = world.GetClippingFrustum(); for (int i = 0; i < 4; i++) { Vector3 sideStartPosition = Vector3.Transform(bounds.GetBottomCorner(i), matrix); Vector3 sideEndPosition = Vector3.Transform(bounds.GetTopCorner(i), matrix); Vector3 bottomStartPosition = sideStartPosition; Vector3 bottomEndPosition = Vector3.Transform(bounds.GetBottomCorner((i + 1) % 4), matrix); Vector3 topStartPosition = sideEndPosition; Vector3 topEndPosition = Vector3.Transform(bounds.GetTopCorner((i + 1) % 4), matrix); if (extendLineLength > 0) { GLHelper.ExtendLineEnds(ref sideStartPosition, ref sideEndPosition, extendLineLength); GLHelper.ExtendLineEnds(ref topStartPosition, ref topEndPosition, extendLineLength); GLHelper.ExtendLineEnds(ref bottomStartPosition, ref bottomEndPosition, extendLineLength); } // draw each of the edge lines (4) and their touching top and bottom lines (2 each) world.Render3DLineNoPrep(frustum, sideStartPosition, sideEndPosition, color, width); world.Render3DLineNoPrep(frustum, topStartPosition, topEndPosition, color, width); world.Render3DLineNoPrep(frustum, bottomStartPosition, bottomEndPosition, color, width); } GL.Enable(EnableCap.Lighting); }
private void RenderBounds(AxisAlignedBoundingBox aabb) { Color color = Color.Red; // the bottom RenderLine(transform.Peek(), aabb.GetBottomCorner(0), aabb.GetBottomCorner(1), color); RenderLine(transform.Peek(), aabb.GetBottomCorner(1), aabb.GetBottomCorner(2), color); RenderLine(transform.Peek(), aabb.GetBottomCorner(2), aabb.GetBottomCorner(3), color); RenderLine(transform.Peek(), aabb.GetBottomCorner(3), aabb.GetBottomCorner(0), color); // the top RenderLine(transform.Peek(), aabb.GetTopCorner(0), aabb.GetTopCorner(1), color); RenderLine(transform.Peek(), aabb.GetTopCorner(1), aabb.GetTopCorner(2), color); RenderLine(transform.Peek(), aabb.GetTopCorner(2), aabb.GetTopCorner(3), color); RenderLine(transform.Peek(), aabb.GetTopCorner(3), aabb.GetTopCorner(0), color); // the sides RenderLine(transform.Peek(), new Vector3(aabb.minXYZ.X, aabb.minXYZ.Y, aabb.minXYZ.Z), new Vector3(aabb.minXYZ.X, aabb.minXYZ.Y, aabb.maxXYZ.Z), color); RenderLine(transform.Peek(), new Vector3(aabb.maxXYZ.X, aabb.minXYZ.Y, aabb.minXYZ.Z), new Vector3(aabb.maxXYZ.X, aabb.minXYZ.Y, aabb.maxXYZ.Z), color); RenderLine(transform.Peek(), new Vector3(aabb.minXYZ.X, aabb.maxXYZ.Y, aabb.minXYZ.Z), new Vector3(aabb.minXYZ.X, aabb.maxXYZ.Y, aabb.maxXYZ.Z), color); RenderLine(transform.Peek(), new Vector3(aabb.maxXYZ.X, aabb.maxXYZ.Y, aabb.minXYZ.Z), new Vector3(aabb.maxXYZ.X, aabb.maxXYZ.Y, aabb.maxXYZ.Z), color); }
private void RenderBounds(AxisAlignedBoundingBox aabb) { RGBA_Bytes color = RGBA_Bytes.Red; // the bottom RenderLine(transform.Peek(), aabb.GetBottomCorner(0), aabb.GetBottomCorner(1), color); RenderLine(transform.Peek(), aabb.GetBottomCorner(1), aabb.GetBottomCorner(2), color); RenderLine(transform.Peek(), aabb.GetBottomCorner(2), aabb.GetBottomCorner(3), color); RenderLine(transform.Peek(), aabb.GetBottomCorner(3), aabb.GetBottomCorner(0), color); // the top RenderLine(transform.Peek(), aabb.GetTopCorner(0), aabb.GetTopCorner(1), color); RenderLine(transform.Peek(), aabb.GetTopCorner(1), aabb.GetTopCorner(2), color); RenderLine(transform.Peek(), aabb.GetTopCorner(2), aabb.GetTopCorner(3), color); RenderLine(transform.Peek(), aabb.GetTopCorner(3), aabb.GetTopCorner(0), color); // the sides RenderLine(transform.Peek(), new Vector3(aabb.minXYZ.x, aabb.minXYZ.y, aabb.minXYZ.z), new Vector3(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.z), color); RenderLine(transform.Peek(), new Vector3(aabb.maxXYZ.x, aabb.minXYZ.y, aabb.minXYZ.z), new Vector3(aabb.maxXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.z), color); RenderLine(transform.Peek(), new Vector3(aabb.minXYZ.x, aabb.maxXYZ.y, aabb.minXYZ.z), new Vector3(aabb.minXYZ.x, aabb.maxXYZ.y, aabb.maxXYZ.z), color); RenderLine(transform.Peek(), new Vector3(aabb.maxXYZ.x, aabb.maxXYZ.y, aabb.minXYZ.z), new Vector3(aabb.maxXYZ.x, aabb.maxXYZ.y, aabb.maxXYZ.z), color); }
public Vector3 GetCornerPosition(IObject3D item, int quadrantIndex) { AxisAlignedBoundingBox originalSelectedBounds = item.GetAxisAlignedBoundingBox(); Vector3 cornerPosition = originalSelectedBounds.GetBottomCorner(quadrantIndex); return(SetBottomControlHeight(originalSelectedBounds, cornerPosition)); }
private void View3DWidget_AfterDraw(object sender, DrawEventArgs e) { if (view3DWidget?.HasBeenClosed == false && this.TrackingObject != null) { // Account for loading items in InsertionGroups - inherit parent transform var offset = TrackingObject.Parent?.Matrix ?? Matrix4X4.Identity; AxisAlignedBoundingBox bounds = TrackingObject.GetAxisAlignedBoundingBox(offset); Vector3 renderPosition = bounds.GetBottomCorner(2); Vector2 cornerScreenSpace = view3DWidget.Object3DControlLayer.World.GetScreenPosition(renderPosition) - new Vector2(20, 0); e.Graphics2D.PushTransform(); Affine currentGraphics2DTransform = e.Graphics2D.GetTransform(); Affine accumulatedTransform = currentGraphics2DTransform * Affine.NewTranslation(cornerScreenSpace.X, cornerScreenSpace.Y); e.Graphics2D.SetTransform(accumulatedTransform); progressBar.OnDraw(e.Graphics2D); if (!string.IsNullOrEmpty(this.State)) { e.Graphics2D.DrawString(this.State, 0, -20, 11); } e.Graphics2D.PopTransform(); } }
private void View3DWidget_AfterDraw(object sender, DrawEventArgs e) { if (view3DWidget?.HasBeenClosed == false && this.TrackingObject != null) { // Account for loading items in InsertionGroups - inherit parent transform var offset = TrackingObject.Parent?.Matrix ?? Matrix4X4.Identity; AxisAlignedBoundingBox bounds = TrackingObject.GetAxisAlignedBoundingBox(offset); Vector3 renderPosition = bounds.GetBottomCorner(2); Vector2 cornerScreenSpace = view3DWidget.Object3DControlLayer.World.GetScreenPosition(renderPosition) - new Vector2(20, 10) * GuiWidget.DeviceScale; e.Graphics2D.PushTransform(); Affine currentGraphics2DTransform = e.Graphics2D.GetTransform(); Affine accumulatedTransform = currentGraphics2DTransform * Affine.NewTranslation(cornerScreenSpace.X, cornerScreenSpace.Y); e.Graphics2D.SetTransform(accumulatedTransform); progressBar.OnDraw(e.Graphics2D); if (!string.IsNullOrEmpty(this.State)) { var stringPrinter = new TypeFacePrinter(this.State, 9, new Vector2(0, -20)); var textBounds = stringPrinter.LocalBounds; textBounds.Inflate(textBounds.Height / 4); e.Graphics2D.Render(new RoundedRect(textBounds, textBounds.Height / 4), theme.BackgroundColor); stringPrinter.Render(e.Graphics2D, theme.TextColor); } e.Graphics2D.PopTransform(); } }
private Vector3 GetDeltaToOtherSideXy(IObject3D selectedItem) { AxisAlignedBoundingBox currentSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); int cornerIndex; Vector3 cornerPosition = GetCornerPosition(selectedItem, out cornerIndex); Vector3 cornerPositionCcw = currentSelectedBounds.GetBottomCorner((cornerIndex + 1) % 4); Vector3 cornerPositionCw = currentSelectedBounds.GetBottomCorner((cornerIndex + 3) % 4); double xDirection = cornerPositionCcw.X - cornerPosition.X; if (xDirection == 0) { xDirection = cornerPositionCw.X - cornerPosition.X; } double yDirection = cornerPositionCcw.Y - cornerPosition.Y; if (yDirection == 0) { yDirection = cornerPositionCw.Y - cornerPosition.Y; } return(new Vector3(xDirection, yDirection, cornerPosition.Z)); }
public override List <WidgetAndPosition> FindDescendants(IEnumerable <string> namesToSearchFor, List <WidgetAndPosition> foundChildren, RectangleDouble touchingBounds, SearchType seachType, bool allowInvalidItems = true) { foreach (var child in Scene.Children) { string object3DName = child.Name; if (object3DName == null && child.MeshPath != null) { object3DName = Path.GetFileName(child.MeshPath); } bool nameFound = false; foreach (var nameToSearchFor in namesToSearchFor) { if (seachType == SearchType.Exact) { if (object3DName == nameToSearchFor) { nameFound = true; } } else { if (nameToSearchFor == "" || object3DName.Contains(nameToSearchFor)) { nameFound = true; } } } if (nameFound) { AxisAlignedBoundingBox bounds = child.GetBVHData().GetAxisAlignedBoundingBox(); RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection; for (int i = 0; i < 4; i++) { screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetTopCorner(i))); screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetBottomCorner(i))); } if (touchingBounds.IsTouching(screenBoundsOfObject3D)) { Vector3 renderPosition = bounds.Center; Vector2 objectCenterScreenSpace = this.World.GetScreenPosition(renderPosition); Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y); foundChildren.Add(new WidgetAndPosition(this, screenPositionOfObject3D, object3DName)); } } } return(base.FindDescendants(namesToSearchFor, foundChildren, touchingBounds, seachType, allowInvalidItems)); }
public Vector3 GetCornerPosition(IObject3D objectBeingRotated, out int cornerIndexOut) { cornerIndexOut = 0; AxisAlignedBoundingBox currentSelectedBounds = objectBeingRotated.GetAxisAlignedBoundingBox(Matrix4X4.Identity); Vector3 bestZCornerPosition = Vector3.Zero; int xCornerIndex = 0; Vector3 bestXCornerPosition = Vector3.Zero; int yCornerIndex = 1; Vector3 bestYCornerPosition = Vector3.Zero; int zCornerIndex = 2; double bestCornerZ = double.PositiveInfinity; // get the closest z on the bottom in view space for (int cornerIndex = 0; cornerIndex < 4; cornerIndex++) { Vector3 cornerPosition = currentSelectedBounds.GetBottomCorner(cornerIndex); Vector3 cornerScreenSpace = InteractionContext.World.GetScreenSpace(cornerPosition); if (cornerScreenSpace.Z < bestCornerZ) { zCornerIndex = cornerIndex; bestCornerZ = cornerScreenSpace.Z; bestZCornerPosition = cornerPosition; bestZCornerPosition = SetBottomControlHeight(currentSelectedBounds, bestZCornerPosition); Vector3 testCornerPosition = currentSelectedBounds.GetBottomCorner((cornerIndex + 1) % 4); if (testCornerPosition.Y == cornerPosition.Y) { xCornerIndex = (cornerIndex + 1) % 4; yCornerIndex = (cornerIndex + 3) % 4; } else { xCornerIndex = (cornerIndex + 3) % 4; yCornerIndex = (cornerIndex + 1) % 4; } bestXCornerPosition = currentSelectedBounds.GetBottomCorner(xCornerIndex); bestXCornerPosition.Z = currentSelectedBounds.MaxXYZ.Z; bestYCornerPosition = currentSelectedBounds.GetBottomCorner(yCornerIndex); bestYCornerPosition.Z = currentSelectedBounds.MaxXYZ.Z; } } switch (RotationAxis) { case 0: cornerIndexOut = xCornerIndex; return(bestXCornerPosition); case 1: cornerIndexOut = yCornerIndex; return(bestYCornerPosition); case 2: cornerIndexOut = zCornerIndex; return(bestZCornerPosition); } return(bestZCornerPosition); }
public override void FindNamedChildrenRecursive(string nameToSearchFor, List <WidgetAndPosition> foundChildren, RectangleDouble touchingBounds, SearchType seachType, bool allowInvalidItems = true) { foreach (InteractionVolume child in interactionLayer.InteractionVolumes) { string object3DName = child.Name; bool nameFound = false; if (seachType == SearchType.Exact) { if (object3DName == nameToSearchFor) { nameFound = true; } } else { if (nameToSearchFor == "" || object3DName.Contains(nameToSearchFor)) { nameFound = true; } } if (nameFound && child.CollisionVolume != null) { AxisAlignedBoundingBox bounds = child.CollisionVolume.GetAxisAlignedBoundingBox(); bounds = bounds.NewTransformed(child.TotalTransform); RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection; for (int i = 0; i < 4; i++) { screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetTopCorner(i))); screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetBottomCorner(i))); } if (touchingBounds.IsTouching(screenBoundsOfObject3D)) { Vector3 renderPosition = bounds.Center; Vector2 objectCenterScreenSpace = this.World.GetScreenPosition(renderPosition); Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y); foundChildren.Add(new WidgetAndPosition(this, screenPositionOfObject3D, object3DName, child)); } } } foreach (var child in scene.Children) { string object3DName = child.Name; if (object3DName == null && child.MeshPath != null) { object3DName = Path.GetFileName(child.MeshPath); } bool nameFound = false; if (seachType == SearchType.Exact) { if (object3DName == nameToSearchFor) { nameFound = true; } } else { if (nameToSearchFor == "" || object3DName.Contains(nameToSearchFor)) { nameFound = true; } } if (nameFound) { AxisAlignedBoundingBox bounds = child.TraceData().GetAxisAlignedBoundingBox(); RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection; for (int i = 0; i < 4; i++) { screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetTopCorner(i))); screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetBottomCorner(i))); } if (touchingBounds.IsTouching(screenBoundsOfObject3D)) { Vector3 renderPosition = bounds.Center; Vector2 objectCenterScreenSpace = this.World.GetScreenPosition(renderPosition); Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y); foundChildren.Add(new WidgetAndPosition(this, screenPositionOfObject3D, object3DName, child)); } } } base.FindNamedChildrenRecursive(nameToSearchFor, foundChildren, touchingBounds, seachType, allowInvalidItems); }