With the following class derived from ViewportLayout you can draw the infinite world axes as shown in the following image:
namespace WindowsApplication1 { internal class MyViewportLayout : SingleViewportLayout { protected override void DrawOverlay(DrawSceneParams myParams) { base.DrawOverlay(myParams); Point3D pt1 = WorldToScreen(0, 0, 0); // X axis Point3D pt2 = WorldToScreen(1, 0, 0); DrawInfiniteLine(pt1, pt2, Color.Red); // Y axis pt2 = WorldToScreen(0, 1, 0); DrawInfiniteLine(pt1, pt2, Color.Green); // Z axis pt2 = WorldToScreen(0, 0, 1); DrawInfiniteLine(pt1, pt2, Color.Blue); } private void DrawInfiniteLine(Point3D pt1, Point3D pt2, Color color) { Viewport viewport = Viewports[ActiveViewport]; Segment2D screenLineX = new Segment2D(pt1, pt2); int[] viewFrame = new int[] { viewport.Location.X, Height - viewport.Location.Y - viewport.Size.Height, viewport.Size.Width, viewport.Size.Height }; int left = viewFrame[0]; int right = viewFrame[0] + viewFrame[2]; int bottom = viewFrame[1]; int top = viewFrame[1] + viewFrame[3] - 1; Point2D lowerLeft = new Point2D(left, bottom); Point2D lowerRight = new Point2D(right, bottom); Point2D upperLeft = new Point2D(left, top); Point2D upperRight = new Point2D(right, top); Segment2D[] screenLines = new Segment2D[] { new Segment2D(lowerLeft, lowerRight), new Segment2D(upperLeft, upperRight), new Segment2D(lowerLeft, upperLeft), new Segment2D(lowerRight, upperRight) }; Point2D ptAxis1 = null, ptAxis2 = null; // Compute the intersection of the infinite screen line against the lower and upper border of the viewport Segment2D.IntersectionLine(screenLineX, screenLines[0], out ptAxis1); Segment2D.IntersectionLine(screenLineX, screenLines[1], out ptAxis2); bool clipAgainstVertical = true; if (ptAxis1 == null || ptAxis2 == null) { // Compute the intersection of the infinite screen line against the left and right border of the viewport clipAgainstVertical = false; Segment2D.IntersectionLine(screenLineX, screenLines[2], out ptAxis1); Segment2D.IntersectionLine(screenLineX, screenLines[3], out ptAxis2); } if (ptAxis1 != null && ptAxis2 != null) { Segment2D myLine = new Segment2D(ptAxis1, ptAxis2); Point2D clippedPt1 = null, clippedPt2 = null; if (ptAxis1.X < ptAxis2.X) { clippedPt1 = ptAxis1; clippedPt2 = ptAxis2; } else { clippedPt2 = ptAxis1; clippedPt1 = ptAxis2; } // Compute the intersection of the screen line against the other 2 borders of the viewport Point2D clipped; if (Segment2D.Intersection(myLine, screenLines[(clipAgainstVertical) ? 2 : 0], out clipped)) clippedPt1 = clipped; if (Segment2D.Intersection(myLine, screenLines[(clipAgainstVertical) ? 3 : 1], out clipped)) clippedPt2 = clipped; gl.LineWidth(1); gl.Color3ub(color.R, color.G, color.B); gl.Begin(gl.LINES); clippedPt1.DrawGL(); clippedPt2.DrawGL(); gl.End(); } } } }
Comments
Is there a way to get the axes behind an object that is also in the view port so that the lines are not always on top?
Currently not, but we could add a method in Eyeshot 7 to draw the axes (or whatever other geometry) always behind all the objects in the scene. Would that suit your needs?
I think so.
Devdept should consider offering an appropriate entity for coordinate system with several properties for adjustment (axis length in pixel + infinite, behind(on top), axis label visibility,...).
Did the behind all of the objects functionality ever get added for a later version of eyeshot?
Please sign in to leave a comment.