XNA Creators Club Online
Page 1 of 1 (10 items)
Sort Posts: Previous Next

draw filled shape from points

Last post 7/8/2009 5:56 AM by Roonda. 9 replies.
  • 6/24/2009 3:02 PM

    draw filled shape from points

    How can I go about creating a shape from a series of points in 2D space? I want to have 8 points, each of which I can move around to create various shapes such as rectangles, octagons, diamonds, and anywhere in between. I pretty much need up, down, left, right, and the 4 corners between them. This all makes sense, but how do I draw it on the screen?
  • 6/24/2009 4:29 PM In reply to

    Re: draw filled shape from points

    Hi, I just came on quick to read some posts, and I don't have time to help you too much, but try looking up tessellation. There are lots of articles out there, and that is what you're trying to do.

    If you find what your looking for, post it here so that other people can read it :-)
    Kyle Zimmerman
    Anti-Force
    Follow me on Twitter! : Twitter
    Working on: ElectroStatic | AntiForce Editor
  • 6/24/2009 4:43 PM In reply to

    Re: draw filled shape from points

    You need to create a set of triangles connecting these points, then draw those triangles (most easily done using DrawUserPrimitives).

    If your shapes are always going to be convex, this is very easy to do: just render the list of points as a triangle fan.

    If you need to support concave or self-intersecting shapes, you will first need to tessellate the polygon formed by your 8 vertices into a number f convex polygons (or triangles, which are by definition convex). The algorithms for doing this can be somewhat subtle but are well understood.
    XNA Framework Developer - blog - homepage
  • 6/24/2009 6:47 PM In reply to

    Re: draw filled shape from points

    I think I'm doing this wrong. No errors, but nothing shows up on the screen.

    ScreenManager.GraphicsDevice.DrawUserPrimitives<Vector2>(player.type, player.corner, 0, 7);

    also I am using the gamestatemanagement sample, so that is why I have ScreenManager
  • 6/24/2009 6:51 PM In reply to

    Re: draw filled shape from points

    You need to set a shader and vertex declaration before you draw. See "How To: Draw Points, Lines, and Other 3D Primitives" in the Game Studio docs.
    XNA Framework Developer - blog - homepage
  • 6/25/2009 11:25 PM In reply to
    • (0)
    • premium membership
    • Posts 74

    Re: draw filled shape from points

    forget shaders, and advanced functions.  take the first point and then use 2 for loops to get every arangement of points.  That will gve you 3 points.  Draw every possible tryangle and the unique convex figure determented by your eight points will apear.
  • 6/25/2009 11:46 PM In reply to

    Re: draw filled shape from points

    You can't just "forget shaders" if you want to draw any kind of graphics to the screen using the XNA Framework. You need a shader: it is not possible to render anything without one.
    XNA Framework Developer - blog - homepage
  • 7/7/2009 8:36 PM In reply to
    • (0)
    • premium membership
    • Posts 74

    Re: draw filled shape from points

    Texture2D target; target = Content.Load<Texture2D>("target");
            spriteBatch.Begin(); spriteBatch.Draw(target, Vector2.Zero, Color.White); spriteBatch.End();

    No shader needed.

     

  • 7/7/2009 8:44 PM In reply to

    Re: draw filled shape from points

    SpriteBatch uses its own internal shader.  You don't have to declare your own to use SpriteBatch, but don't confuse that with "no shader needed".
  • 7/8/2009 5:56 AM In reply to

    Re: draw filled shape from points

    As other people have said, you'll need to tesselate your polygon (convert it to triangles). This isn't trivial if you need to support concave polygons. If you want a head start, the Farseer physics engine has code to do this. It also has code for drawing those triangles as simple filled shapes.
Page 1 of 1 (10 items) Previous Next