Jump to content
  • Advertisement
Sign in to follow this  
GameObject

Creating a filled Bresenham's ellipse

This topic is 1025 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the following code to create a Bresenham's ellipse for a voxel game. While this is complete and works great to create nice ellipse outlines, I'm struggling to figure out how I might convert this to create a filled ellipse. I was thinking of perhaps doing some sort of flood fill, but not entirely sure how I might implement it. I thought maybe I will save the map points and do a line scan across from left to right boundary and fill in between.

 

I was hoping someone might have an example of something more efficient and working. The code below is C# but more interested in how it will work and I can just convert to c#. 

void DrawEllipse(int xc, int yPos, int zc, int width, int height, VoxelInfo voxelInfo)
    {
        int a2 = width * width;
        int b2 = height * height;
        int fa2 = 4 * a2, fb2 = 4 * b2;
        int x, z, sigma;

        for (x = 0, z = height, sigma = 2 * b2 + a2 * (1 - 2 * height); b2 * x <= a2 * z; x++)
        {
            voxelInfo.chunk.SetVoxel(xc + x, yPos, zc + z, 9, true);
            voxelInfo.chunk.SetVoxel(xc - x, yPos, zc + z, 9, true);
            voxelInfo.chunk.SetVoxel(xc + x, yPos, zc - z, 9, true);
            voxelInfo.chunk.SetVoxel(xc - x, yPos, zc - z, 9, true);

            if (sigma >= 0)
            {
                sigma += fa2 * (1 - z);
                z--;
            }
            sigma += b2 * ((4 * x) + 6);
        }

        for (x = width, z = 0, sigma = 2 * a2 + b2 * (1 - 2 * width); a2 * z <= b2 * x; z++)
        {
            voxelInfo.chunk.SetVoxel(xc + x, yPos, zc + z, 9, true);
            voxelInfo.chunk.SetVoxel(xc - x, yPos, zc + z, 9, true);
            voxelInfo.chunk.SetVoxel(xc + x, yPos, zc - z, 9, true);
            voxelInfo.chunk.SetVoxel(xc - x, yPos, zc - z, 9, true);

            if (sigma >= 0)
            {
                sigma += fb2 * (1 - x);
                x--;
            }
            sigma += a2 * ((4 * z) + 6);
        }
    }
Edited by GameObject

Share this post


Link to post
Share on other sites
Advertisement
The fun starts when you decide to draw thick ellipses. wink.png Edited by MarkS

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!