how to draw a circle with 'Bresenham'

Started by
16 comments, last by tcige 11 years ago

So do I understand you correctly that you want to draw a filled shape (circle in this case) and use Bresenham's algorithm (which is used mostly for drawing circle contour) ?

The difference between D3DFVF_XYZRHW and D3DFVF_XYZ is that the RHW version skips vertex shader / projection part ie. it assumes that the data is already transformed. D3DFVF_XYZ doesn't skip transformation and projection so you'll need to provide a correct world, view and projection matrix in order to draw correctly.

If you are drawing 2d shapes on the screen then the RHW version should do the trick. However, you may accomplish the same with D3DFVD_XYZ but you'll need correct matrices for it to work correctly. Do you need to draw circles in 3d space?

Cheers!

Advertisement

So do I understand you correctly that you want to draw a filled shape (circle in this case) and use Bresenham's algorithm (which is used mostly for drawing circle contour) ?

The difference between D3DFVF_XYZRHW and D3DFVF_XYZ is that the RHW version skips vertex shader / projection part ie. it assumes that the data is already transformed. D3DFVF_XYZ doesn't skip transformation and projection so you'll need to provide a correct world, view and projection matrix in order to draw correctly.

If you are drawing 2d shapes on the screen then the RHW version should do the trick. However, you may accomplish the same with D3DFVD_XYZ but you'll need correct matrices for it to work correctly. Do you need to draw circles in 3d space?

Cheers!

yeah, that's what i mean, in 3d space

even i increase the radius and adjust the parameter of D3DXMatrixLookAtLH to suit the radius, the effect is awful

+1 What kauna said.

Alternative fast sin/cos


float fast_sin(float rad)
{
    static const float B = 4 / D3DX_PI;
    static const float C = -4 / (D3DX_PI * D3DX_PI);

    float y = B * rad + C * rad * std::abs(rad);
    return y;
}

float fast_cos(float rad)
{
    static const float B = 4 / D3DX_PI;
    static const float C = -4 / (D3DX_PI * D3DX_PI);

    rad += 1.57079632f;
    float y = B * rad + C * rad * std::abs(rad);
    return y;
}

http://devmaster.net/forums/topic/4648-fast-and-accurate-sinecosine/

My code above is just an example, you could precalculate most stuff at init time, no need to do that every frame.

is this fast cos/sin authoritative and cos/sin acceptable in reality?

I am using it for my particle system, for me visually there is no noticeable difference between these and standard sin/cos. Why not try and see?

I am using it for my particle system, for me visually there is no noticeable difference between these and standard sin/cos. Why not try and see?

thanks, i will try and this remind me of the 'hacker's delight'

then what about Bresenham, can it be used in D3DFVF_XYZ

Note for these function to work properly you must wrap your rad parameter -PI - PI

then what about Bresenham, can it be used in D3DFVF_XYZ

I don't think so. The Bresenham's circle algorithm is suitable to drawing a circles in 2d. It was developed when drawing single pixels to the screen was the slowest thing ever... that's like some decades ago.

Just create a mesh using the given functions (as smooth as required) and I can guarantee that the sin and cos functions aren't the performance bottle neck. If you store the geometry inside a vertex buffer, it'll be enough to create the mesh once at the start up.

Give some screenshots to show what you want and what you have accomplished. It is really difficult to read people's mind you know.

Cheers!

then what about Bresenham, can it be used in D3DFVF_XYZ

I don't think so. The Bresenham's circle algorithm is suitable to drawing a circles in 2d. It was developed when drawing single pixels to the screen was the slowest thing ever... that's like some decades ago.

Just create a mesh using the given functions (as smooth as required) and I can guarantee that the sin and cos functions aren't the performance bottle neck. If you store the geometry inside a vertex buffer, it'll be enough to create the mesh once at the start up.

Give some screenshots to show what you want and what you have accomplished. It is really difficult to read people's mind you know.

Cheers!

thanks a lot

i'm new to directx, and someone says cosf/sinf's efficiency is much slower than Bresenham

finally i find difficult to apply it to 3d, and i'll be glad to use cosf/sinf because it needs only a few lines

This topic is closed to new replies.

Advertisement