示例#1
0
        /// <summary>
        /// Adds a triangle to be rendered for a set amount of time.
        /// </summary>
        /// <param name="a">The first vertex of the triangle.</param>
        /// <param name="b">The second vertex of the triangle.</param>
        /// <param name="c">The third vertex of the triangle.</param>
        /// <param name="color">The color in which to draw the triangle.</param>
        /// <param name="life">The amount of time, in seconds, to keep rendering the triangle.</param>
        public static void AddTriangle(Vector3 a, Vector3 b, Vector3 c, Color color, float life)
        {
            // Get a SimpleShape we can use to draw the triangle
            SimpleShape shape = GetShapeForLines(3, life);

            // Add the vertices to the shape
            shape.Vertices[0] = new VertexPositionColor(a, color);
            shape.Vertices[1] = new VertexPositionColor(b, color);
            shape.Vertices[2] = new VertexPositionColor(b, color);
            shape.Vertices[3] = new VertexPositionColor(c, color);
            shape.Vertices[4] = new VertexPositionColor(c, color);
            shape.Vertices[5] = new VertexPositionColor(a, color);
        }
示例#2
0
        public override GeoObjectList GenerateContent(CompoundShape shape, Plane plane)
        {
            GeoObjectList res = new GeoObjectList();

            for (int i = 0; i < shape.SimpleShapes.Length; ++i)
            {
                SimpleShape ss = shape.SimpleShapes[i].Clone();
                ss.Flatten(); // es entstehen Shapes mit Polylinien, das ist für Faces schlecht
                Face fc = Face.MakeFace(new PlaneSurface(plane), ss);
                fc.ColorDef = color;
                res.Add(fc);
            }
            return(res);
        }
示例#3
0
        /// <summary>
        /// Adds a bounding sphere to be rendered for a set amount of time.
        /// </summary>
        /// <param name="sphere">The bounding sphere to render.</param>
        /// <param name="color">The color in which to draw the bounding sphere.</param>
        /// <param name="life">The amount of time, in seconds, to keep rendering the bounding sphere.</param>
        public static void AddBoundingSphere(BoundingSphere sphere, Color color, float life)
        {
            // Get a SimpleShape we can use to draw the sphere
            SimpleShape shape = GetShapeForLines(sphereLineCount, life);

            // Iterate our unit sphere vertices
            for (int i = 0; i < unitSphere.Length; i++)
            {
                // Compute the vertex position by transforming the point by the radius and center of the sphere
                Vector3 vertPos = unitSphere[i] * sphere.Radius + sphere.Center;

                // Add the vertex to the shape
                shape.Vertices[i] = new VertexPositionColor(vertPos, color);
            }
        }
示例#4
0
        /// <summary>
        /// Adds a bounding box to be rendered for a set amount of time.
        /// </summary>
        /// <param name="box">The bounding box to render.</param>
        /// <param name="color">The color in which to draw the bounding box.</param>
        /// <param name="life">The amount of time, in seconds, to keep rendering the bounding box.</param>
        public static void AddBoundingBox(BoundingBox box, Color color, float life)
        {
            // Get a SimpleShape we can use to draw the box
            SimpleShape shape = GetShapeForLines(12, life);

            // Get the corners of the box
            box.GetCorners(corners);

            // Fill in the vertices for the bottom of the box
            shape.Vertices[0] = new VertexPositionColor(corners[0], color);
            shape.Vertices[1] = new VertexPositionColor(corners[1], color);
            shape.Vertices[2] = new VertexPositionColor(corners[1], color);
            shape.Vertices[3] = new VertexPositionColor(corners[2], color);
            shape.Vertices[4] = new VertexPositionColor(corners[2], color);
            shape.Vertices[5] = new VertexPositionColor(corners[3], color);
            shape.Vertices[6] = new VertexPositionColor(corners[3], color);
            shape.Vertices[7] = new VertexPositionColor(corners[0], color);

            // Fill in the vertices for the top of the box
            shape.Vertices[8]  = new VertexPositionColor(corners[4], color);
            shape.Vertices[9]  = new VertexPositionColor(corners[5], color);
            shape.Vertices[10] = new VertexPositionColor(corners[5], color);
            shape.Vertices[11] = new VertexPositionColor(corners[6], color);
            shape.Vertices[12] = new VertexPositionColor(corners[6], color);
            shape.Vertices[13] = new VertexPositionColor(corners[7], color);
            shape.Vertices[14] = new VertexPositionColor(corners[7], color);
            shape.Vertices[15] = new VertexPositionColor(corners[4], color);

            // Fill in the vertices for the vertical sides of the box
            shape.Vertices[16] = new VertexPositionColor(corners[0], color);
            shape.Vertices[17] = new VertexPositionColor(corners[4], color);
            shape.Vertices[18] = new VertexPositionColor(corners[1], color);
            shape.Vertices[19] = new VertexPositionColor(corners[5], color);
            shape.Vertices[20] = new VertexPositionColor(corners[2], color);
            shape.Vertices[21] = new VertexPositionColor(corners[6], color);
            shape.Vertices[22] = new VertexPositionColor(corners[3], color);
            shape.Vertices[23] = new VertexPositionColor(corners[7], color);
        }
示例#5
0
 protected void ApplyPaint(SimpleShape shape) {
     if (_paint is Color) {
         shape.GetFill().SetForegroundColor((Color)_paint);
     }
 }
示例#6
0
 protected void ApplyStroke(SimpleShape shape) {
     if (_stroke is BasicStroke){
         BasicStroke bs = (BasicStroke)_stroke;
         shape.SetLineWidth(bs.GetLineWidth());
         float[] dash = bs.GetDashArray();
         if (dash != null) {
             //TODO: implement more dashing styles
             shape.SetLineDashing(Line.PEN_DASH);
         }
     }
 }
示例#7
0
    public static void paint(SimpleShape shape, Graphics2D graphics){
        Rectangle2D anchor = shape.GetLogicalAnchor2D();
        java.awt.Shape outline = shape.GetOutline();

        //flip vertical
        if(shape.GetFlipVertical()){
            graphics.translate(anchor.GetX(), anchor.GetY() + anchor.Height);
            graphics.scale(1, -1);
            graphics.translate(-anchor.GetX(), -anchor.GetY());
        }
        //flip horizontal
        if(shape.GetFlipHorizontal()){
            graphics.translate(anchor.GetX() + anchor.Width, anchor.GetY());
            graphics.scale(-1, 1);
            graphics.translate(-anchor.GetX() , -anchor.GetY());
        }

        //rotate transform
        double angle = shape.GetRotation();

        if(angle != 0){
            double centerX = anchor.GetX() + anchor.Width/2;
            double centerY = anchor.GetY() + anchor.Height/2;

            graphics.translate(centerX, centerY);
            graphics.rotate(Math.ToRadians(angle));
            graphics.translate(-centerX, -centerY);
        }

        //fill
        Color FillColor = shape.GetFill().GetForegroundColor();
        if (FillColor != null) {
            //TODO: implement gradient and texture fill patterns
            graphics.SetPaint(FillColor);
            graphics.Fill(outline);
        }

        //border
        Color lineColor = shape.GetLineColor();
        if (lineColor != null){
            graphics.SetPaint(lineColor);
            float width = (float)shape.GetLineWidth();

            int dashing = shape.GetLineDashing();
            //TODO: implement more dashing styles
            float[] dashptrn = null;
            switch(dashing){
                case Line.PEN_SOLID:
                    dashptrn = null;
                    break;
                case Line.PEN_PS_DASH:
                    dashptrn = new float[]{width, width};
                    break;
                case Line.PEN_DOTGEL:
                    dashptrn = new float[]{width*4, width*3};
                    break;
               default:
                    logger.log(POILogger.WARN, "unsupported dashing: " + dashing);
                    dashptrn = new float[]{width, width};
                    break;
            }

            Stroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashptrn, 0.0f);
            graphics.SetStroke(stroke);
            graphics.Draw(outline);
        }
    }
示例#8
0
 /// <summary>
 /// A method used for sorting our cached shapes based on the size of their vertex arrays.
 /// </summary>
 private static int CachedShapesSort(SimpleShape s1, SimpleShape s2)
 {
     return(s1.Vertices.Length.CompareTo(s2.Vertices.Length));
 }
示例#9
0
        /// <summary>
        /// Draws the shapes that were added to the renderer and are still alive.
        /// </summary>
        /// <param name="gameTime">The current game timestamp.</param>
        /// <param name="view">The view matrix to use when rendering the shapes.</param>
        /// <param name="projection">The projection matrix to use when rendering the shapes.</param>
        public static void Draw(GameTime gameTime, Matrix view, Matrix projection)
        {
            // Update our effect with the matrices.
            effect.View       = view;
            effect.Projection = projection;

            // Calculate the total number of vertices we're going to be rendering.
            int vertexCount = 0;

            foreach (var shape in activeShapes)
            {
                vertexCount += shape.LineCount * 2;
            }

            // If we have some vertices to draw
            if (vertexCount > 0)
            {
                // Make sure our array is large enough
                if (verts.Length < vertexCount)
                {
                    // If we have to resize, we make our array twice as large as necessary so
                    // we hopefully won't have to resize it for a while.
                    verts = new VertexPositionColor[vertexCount * 2];
                }

                // Now go through the shapes again to move the vertices to our array and
                // add up the number of lines to draw.
                int lineCount = 0;
                int vertIndex = 0;
                foreach (SimpleShape shape in activeShapes)
                {
                    lineCount += shape.LineCount;
                    int shapeVerts = shape.LineCount * 2;
                    for (int i = 0; i < shapeVerts; i++)
                    {
                        verts[vertIndex++] = shape.Vertices[i];
                    }
                }

                // Start our effect to begin rendering.
                effect.CurrentTechnique.Passes[0].Apply();

                // We draw in a loop because the Reach profile only supports 65,535 primitives. While it's
                // not incredibly likely, if a game tries to render more than 65,535 lines we don't want to
                // crash. We handle this by doing a loop and drawing as many lines as we can at a time, capped
                // at our limit. We then move ahead in our vertex array and draw the next set of lines.
                int vertexOffset = 0;
                while (lineCount > 0)
                {
                    // Figure out how many lines we're going to draw
                    int linesToDraw = Math.Min(lineCount, 65535);

                    // Draw the lines
                    graphics.DrawUserPrimitives(PrimitiveType.LineList, verts, vertexOffset, linesToDraw);

                    // Move our vertex offset ahead based on the lines we drew
                    vertexOffset += linesToDraw * 2;

                    // Remove these lines from our total line count
                    lineCount -= linesToDraw;
                }
            }

            // Go through our active shapes and retire any shapes that have expired to the
            // cache list.
            bool resort = false;

            for (int i = activeShapes.Count - 1; i >= 0; i--)
            {
                SimpleShape s = activeShapes[i];
                s.Lifetime -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (s.Lifetime <= 0)
                {
                    cachedShapes.Add(s);
                    activeShapes.RemoveAt(i);
                    resort = true;
                }
            }

            // If we move any shapes around, we need to resort the cached list
            // to ensure that the smallest shapes are first in the list.
            if (resort)
            {
                cachedShapes.Sort(CachedShapesSort);
            }
        }