Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 28 February 2012 - 07:32 AM
Posted 28 February 2012 - 10:51 AM
Posted 01 March 2012 - 04:03 PM
Vert0 = new Vector2(center); Vert1.x = center.x + Math.Cos(theta) * Radius; Vert1.y = center.y + Math.Sin(theta) * Radius; Vert2.x = center.x + Math.Cos(theta + stepsize) * Radius; Vert2.y = center.y + Math.Sin(theta + stepsize) * Radius;
Eric Nevala
Indie Developer | Spellbound | Dev blog | Twitter | Unreal Engine 4
Posted 01 March 2012 - 04:12 PM
If you use an texture with an alpha channel, you just need to draw a few triangles in a triangle fan:
There are 8 slices, so each triangle is 12.5%. If you want to draw 68% of the image, draw the first 5 tris fully (68 mod 12.5) and figure out the position of the corner vertex in the 6th tri (cos of the angle you want to draw * 1/2 the length of the full square). The u/v coord is proportional to the full length of the segment.
You only need one alpha-only texture for the shape, and then you can use different texture for the color.
Is this thread of any use to you?
You can do this pretty easily with primitives. If you're still using .NET 3.5, you can use a Triangle Fan. If you're using .NET 4.0, the triangle fan is gone so you can only use triangle lists or triangle strips (more verts, yuck!). The coloring can be accomplished by using vertext colors. I created a very similar project to show days, hours, minutes, and seconds with four pies. If you include enough triangles, you can create a circle ;)
The basic idea is to find a center position for your pie fan. Every triangle will have one of its verticies at this center position. Then, you want to be able to create a function which accepts a percentage value (0->100%) and figures out from there how many triangles to draw and where they should be placed. You may want to use an angle or radian value as an alternative (or overloaded member function). You'll also want to feed in the radius to indicate how large your pie should be. After you have all of this information, it's just a matter of using simple trigonometery to figure out where to place the other two verticies for your triangles.
It should look something like this:Vert0 = new Vector2(center); Vert1.x = center.x + Math.Cos(theta) * Radius; Vert1.y = center.y + Math.Sin(theta) * Radius; Vert2.x = center.x + Math.Cos(theta + stepsize) * Radius; Vert2.y = center.y + Math.Sin(theta + stepsize) * Radius;
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.