Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
        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);
        }
Пример #6
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, bool startArrow = false, bool endArrow = false)
 {
     GL.PushAttrib(AttribMask.EnableBit);
     GLHelper.PrepareFor3DLineRender(doDepthTest);
     world.Render3DLineNoPrep(clippingFrustum, start, end, color, width, startArrow, endArrow);
     GL.PopAttrib();
 }
Пример #7
0
        public void RenderToGlRecursive(BoxPrimitive objectToProcess)
        {
            if (objectToProcess.CreateCentered)
            {
                //objectToProcess.Size;
            }
            else
            {
            }

            var partColor = new ColorF(.8, .8, 1).ToColor();

            GLHelper.Render(CreateBox(objectToProcess.GetAxisAlignedBoundingBox()), partColor);
        }
Пример #8
0
        public static void Render3DLineNoPrep(this WorldView world, Frustum clippingFrustum, Vector3 start, Vector3 end, Color color, double width = 1)
        {
            if (clippingFrustum.ClipLine(ref start, ref end))
            {
                double unitsPerPixelStart = world.GetWorldUnitsPerScreenPixelAtPosition(start);
                double unitsPerPixelEnd   = world.GetWorldUnitsPerScreenPixelAtPosition(end);

                Vector3   delta           = start - end;
                var       deltaLength     = delta.Length;
                Matrix4X4 rotateTransform = Matrix4X4.CreateRotation(new Quaternion(Vector3.UnitX + new Vector3(.0001, -.00001, .00002), -delta / deltaLength));
                Matrix4X4 scaleTransform  = Matrix4X4.CreateScale(deltaLength, 1, 1);
                Vector3   lineCenter      = (start + end) / 2;
                Matrix4X4 lineTransform   = scaleTransform * rotateTransform * Matrix4X4.CreateTranslation(lineCenter);

                var startScale = unitsPerPixelStart * width;
                var endScale   = unitsPerPixelEnd * width;
                for (int i = 0; i < unscaledLineMesh.Vertices.Count; i++)
                {
                    var vertexPosition = unscaledLineMesh.Vertices[i];
                    if (vertexPosition.X < 0)
                    {
                        scaledLineMesh.Vertices[i] = new Vector3Float(vertexPosition.X, vertexPosition.Y * startScale, vertexPosition.Z * startScale);
                    }
                    else
                    {
                        scaledLineMesh.Vertices[i] = new Vector3Float(vertexPosition.X, vertexPosition.Y * endScale, vertexPosition.Z * endScale);
                    }
                }

                if (true)
                {
                    GL.Color4(color.Red0To255, color.Green0To255, color.Blue0To255, color.Alpha0To255);

                    if (color.Alpha0To1 < 1)
                    {
                        GL.Enable(EnableCap.Blend);
                    }
                    else
                    {
                        //GL.Disable(EnableCap.Blend);
                    }

                    GL.MatrixMode(MatrixMode.Modelview);
                    GL.PushMatrix();
                    GL.MultMatrix(lineTransform.GetAsFloatArray());

                    GL.Begin(BeginMode.Triangles);
                    for (int faceIndex = 0; faceIndex < scaledLineMesh.Faces.Count; faceIndex++)
                    {
                        var face     = scaledLineMesh.Faces[faceIndex];
                        var vertices = scaledLineMesh.Vertices;
                        var position = vertices[face.v0];
                        GL.Vertex3(position.X, position.Y, position.Z);
                        position = vertices[face.v1];
                        GL.Vertex3(position.X, position.Y, position.Z);
                        position = vertices[face.v2];
                        GL.Vertex3(position.X, position.Y, position.Z);
                    }
                    GL.End();
                    GL.PopMatrix();
                }
                else
                {
                    scaledLineMesh.MarkAsChanged();

                    GLHelper.Render(scaledLineMesh, color, lineTransform, RenderTypes.Shaded);
                }
            }
        }
Пример #9
0
        public void RenderToGlRecursive(Csg.Solids.MeshContainer objectToProcess)
        {
            var partColor = new ColorF(.8, .8, 1).ToColor();

            GLHelper.Render(objectToProcess.GetMesh(), partColor);
        }
Пример #10
0
        public void RenderToGlRecursive(Cylinder.CylinderPrimitive objectToProcess)
        {
            var partColor = new ColorF(.8, .8, 1).ToColor();

            GLHelper.Render(CreateCylinder(objectToProcess), partColor);
        }
Пример #11
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);
 }