public static void RenderAabb(this WorldView world, AxisAlignedBoundingBox bounds, Matrix4X4 matrix, Color color, double lineWidth = 1, double extendLineLength = 0)
        {
            GLHelper.PrepareFor3DLineRender(true);

            Frustum frustum = world.GetClippingFrustum();

            for (int i = 0; i < 4; i++)
            {
                Vector3 sideStartPosition = Vector3Ex.Transform(bounds.GetBottomCorner(i), matrix);
                Vector3 sideEndPosition   = Vector3Ex.Transform(bounds.GetTopCorner(i), matrix);

                Vector3 bottomStartPosition = sideStartPosition;
                Vector3 bottomEndPosition   = Vector3Ex.Transform(bounds.GetBottomCorner((i + 1) % 4), matrix);

                Vector3 topStartPosition = sideEndPosition;
                Vector3 topEndPosition   = Vector3Ex.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, lineWidth);
                world.Render3DLineNoPrep(frustum, topStartPosition, topEndPosition, color, lineWidth);
                world.Render3DLineNoPrep(frustum, bottomStartPosition, bottomEndPosition, color, lineWidth);
            }

            GL.Enable(EnableCap.Lighting);
        }
        public static void RenderAxis(this WorldView world, Vector3 position, Matrix4X4 matrix, double size, double lineWidth)
        {
            GLHelper.PrepareFor3DLineRender(true);

            Frustum frustum = world.GetClippingFrustum();
            Vector3 length  = Vector3.One * size;

            for (int i = 0; i < 3; i++)
            {
                var min = position;
                min[i] -= length[i];
                Vector3 start = Vector3Ex.Transform(min, matrix);

                var max = position;
                max[i] += length[i];
                Vector3 end = Vector3Ex.Transform(max, matrix);

                var color = Agg.Color.Red;
                switch (i)
                {
                case 1:
                    color = Agg.Color.Green;
                    break;

                case 2:
                    color = Agg.Color.Blue;
                    break;
                }

                // draw each of the edge lines (4) and their touching top and bottom lines (2 each)
                world.Render3DLineNoPrep(frustum, start, end, color, lineWidth);
            }

            GL.Enable(EnableCap.Lighting);
        }
        public static void RenderPathOutline(this WorldView world, Matrix4X4 worldMatrix, IVertexSource path, Color color, double lineWidth = 1)
        {
            GLHelper.PrepareFor3DLineRender(true);
            Frustum frustum = world.GetClippingFrustum();

            Vector3 firstPosition = default(Vector3);
            Vector3 prevPosition  = default(Vector3);

            foreach (var vertex in path.Vertices())
            {
                if (vertex.command == ShapePath.FlagsAndCommand.MoveTo)
                {
                    firstPosition = prevPosition = new Vector3(vertex.position).Transform(worldMatrix);
                }
                else if (vertex.command == ShapePath.FlagsAndCommand.LineTo)
                {
                    var position = new Vector3(vertex.position).Transform(worldMatrix);
                    world.Render3DLineNoPrep(frustum, prevPosition, position, color, lineWidth);
                    prevPosition = position;
                }
                else if (vertex.command.HasFlag(ShapePath.FlagsAndCommand.FlagClose))
                {
                    world.Render3DLineNoPrep(frustum, prevPosition, firstPosition, color, lineWidth);
                }
            }

            // turn the lighting back on
            GL.Enable(EnableCap.Lighting);
        }
        public static void RenderRing(this WorldView world,
                                      Matrix4X4 worldMatrix,
                                      Vector3 center,
                                      double diameter,
                                      int sides,
                                      Color ringColor,
                                      double lineWidth = 1,
                                      double phase     = 0,
                                      bool zBuffered   = true)
        {
            GLHelper.PrepareFor3DLineRender(zBuffered);
            Frustum frustum = world.GetClippingFrustum();

            for (int i = 0; i < sides; i++)
            {
                var startAngle    = MathHelper.Tau * i / sides + phase;
                var rotatedPoint  = new Vector3(Math.Cos(startAngle), Math.Sin(startAngle), 0) * diameter / 2;
                var sideTop       = Vector3Ex.Transform(center + rotatedPoint, worldMatrix);
                var sideBottom    = Vector3Ex.Transform(center + rotatedPoint, worldMatrix);
                var endAngle      = MathHelper.Tau * (i + 1) / sides + phase;
                var rotated2Point = new Vector3(Math.Cos(endAngle), Math.Sin(endAngle), 0) * diameter / 2;
                var topStart      = sideTop;
                var topEnd        = Vector3Ex.Transform(center + rotated2Point, worldMatrix);

                if (ringColor != Color.Transparent)
                {
                    world.Render3DLineNoPrep(frustum, topStart, topEnd, ringColor, lineWidth);
                }
            }

            // turn the lighting back on
            GL.Enable(EnableCap.Lighting);
        }
        public static void RenderCylinderOutline(this WorldView world, Matrix4X4 worldMatrix, Vector3 center, double diameter, double height, int sides, Color topBottomRingColor, Color sideLinesColor, double lineWidth = 1, double extendLineLength = 0, double phase = 0)
        {
            GLHelper.PrepareFor3DLineRender(true);
            Frustum frustum = world.GetClippingFrustum();

            for (int i = 0; i < sides; i++)
            {
                var startAngle    = MathHelper.Tau * i / sides + phase;
                var rotatedPoint  = new Vector3(Math.Cos(startAngle), Math.Sin(startAngle), 0) * diameter / 2;
                var sideTop       = Vector3Ex.Transform(center + rotatedPoint + new Vector3(0, 0, height / 2), worldMatrix);
                var sideBottom    = Vector3Ex.Transform(center + rotatedPoint + new Vector3(0, 0, -height / 2), worldMatrix);
                var endAngle      = MathHelper.Tau * (i + 1) / sides + phase;
                var rotated2Point = new Vector3(Math.Cos(endAngle), Math.Sin(endAngle), 0) * diameter / 2;
                var topStart      = sideTop;
                var topEnd        = Vector3Ex.Transform(center + rotated2Point + new Vector3(0, 0, height / 2), worldMatrix);
                var bottomStart   = sideBottom;
                var bottomEnd     = Vector3Ex.Transform(center + rotated2Point + new Vector3(0, 0, -height / 2), worldMatrix);

                if (extendLineLength > 0)
                {
                    GLHelper.ExtendLineEnds(ref sideTop, ref sideBottom, extendLineLength);
                }

                if (sideLinesColor != Color.Transparent)
                {
                    world.Render3DLineNoPrep(frustum, sideTop, sideBottom, sideLinesColor, lineWidth);
                }

                if (topBottomRingColor != Color.Transparent)
                {
                    world.Render3DLineNoPrep(frustum, topStart, topEnd, topBottomRingColor, lineWidth);
                    world.Render3DLineNoPrep(frustum, bottomStart, bottomEnd, topBottomRingColor, lineWidth);
                }
            }
        }
 /// <summary>
 /// Draw a line in the scene in 3D but scale it such that it appears as a 2D line in the view.
 /// </summary>
 /// <param name="world"></param>
 /// <param name="clippingFrustum">This is a cache of the frustum from world.
 /// Much faster to pass this way if drawing lots of lines.</param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="color"></param>
 /// <param name="doDepthTest"></param>
 /// <param name="width"></param>
 public static void Render3DLine(this WorldView world, Frustum clippingFrustum, Vector3 start, Vector3 end, Color color, bool doDepthTest = true, double width = 1, bool startArrow = false, bool endArrow = false)
 {
     GL.PushAttrib(AttribMask.EnableBit);
     GLHelper.PrepareFor3DLineRender(doDepthTest);
     world.Render3DLineNoPrep(clippingFrustum, start, end, color, width, startArrow, endArrow);
     GL.PopAttrib();
 }
Esempio n. 7
0
 /// <summary>
 /// Draw a line in the scene in 3D but scale it such that it appears as a 2D line in the view.
 /// </summary>
 /// <param name="world"></param>
 /// <param name="clippingFrustum">This is a cache of the frustum from world.
 /// Much faster to pass this way if drawing lots of lines.</param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="color"></param>
 /// <param name="doDepthTest"></param>
 /// <param name="width"></param>
 public static void Render3DLine(this WorldView world, Frustum clippingFrustum, Vector3 start, Vector3 end, Color color, bool doDepthTest = true, double width = 1)
 {
     GLHelper.PrepareFor3DLineRender(doDepthTest);
     world.Render3DLineNoPrep(clippingFrustum, start, end, color, width);
 }