https://www.google.com.hk/search?q=draw+circle+by+Direct3D&source=hp&ei=VEPJYYv9IPnh7_UPrp-h6Aw&oq=draw+circle+by+Direct3D&gs_lcp=ChFtb2JpbGUtZ3dzLXdpei1ocBADOgIIKToLCC4QgAQQxwEQowI6BQgAEIAEOgsILhCABBDHARDRAzoFCC4QgAQ6CwguEIAEEMcBEK8BOgQILhATOgQIABATOgYIABAeEBM6CAgAEAgQHhATOgQIABAeOgUIIRCgAToHCCEQChCgAUoFCD4SATFKBQg_EgExSgUIExIBMVCDMVjj1wFg-OUBaAFwAHgAgAGYBIgBpzmSAQoyLTE2LjcuMC4xmAEAoAEBsAEA&sclient=mobile-:
void Dx11Renderer::DrawCircleInternal( int x0, int y0, int radius, int r, int g, int b, int a )
{
if( this->bIsInitialized == false )
return;
if( m_pDevice == NULL || m_pDeviceContext == NULL )
return;
int NUMPOINTS = 24;
UINT viewportNumber = 1;
D3D11_VIEWPORT vp;
this->m_pDeviceContext->RSGetViewports( &viewportNumber, &vp );
COLOR_VERTEX* v = NULL;
D3D11_MAPPED_SUBRESOURCE mapData;
if( FAILED( this->m_pDeviceContext->Map( m_pVertexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &mapData ) ) )
return;
v = ( COLOR_VERTEX* ) mapData.pData;
//float WedgeAngle = ( float )( ( 2 * D3DX_PI ) / NUMPOINTS );
//for( int i = 0; i <= NUMPOINTS; i++ )
//{
// float Theta = ( float )( i * WedgeAngle );
// float x = (float)( x0 + radius * cos( Theta ) );
// float y = (float)( y0 - radius * sin( Theta ) );
// float xx0 = 2.0f * ( x - 0.5f ) / vp.Width - 1.0f;
// float yy0 = 1.0f - 2.0f * ( y - 0.5f ) / vp.Height;
// v[i].Position.x = xx0;
// v[i].Position.y = yy0;
// v[i].Position.z = 0.0f;
// v[i].Color.r = ( ( FLOAT ) r / 255.0f );
// v[i].Color.g = ( ( FLOAT ) g / 255.0f );
// v[i].Color.b = ( ( FLOAT ) b / 255.0f );
// v[i].Color.a = ( ( FLOAT ) a / 255.0f );
//}
int f = 1 - radius;
int ddF_x = 1;
int ddF_y = -2 * radius;
int x = 0;
int y = radius;
int i = 4;
v[0].Position.x = 2.0f * ( x0 - 0.5f ) / vp.Width - 1.0f;
v[0].Position.y = 1.0f - 2.0f * ( (y0 + radius) - 0.5f ) / vp.Height;
v[0].Position.z = 0.0f;
v[0].Color.r = ( ( FLOAT ) r / 255.0f );
v[0].Color.g = ( ( FLOAT ) g / 255.0f );
v[0].Color.b = ( ( FLOAT ) b / 255.0f );
v[0].Color.a = ( ( FLOAT ) a / 255.0f );
v[1].Position.x = 2.0f * ( x0 - 0.5f ) / vp.Width - 1.0f;
v[1].Position.y = 1.0f - 2.0f * ( (y0 - radius) - 0.5f ) / vp.Height;
v[1].Position.z = 0.0f;
v[1].Color.r = ( ( FLOAT ) r / 255.0f );
v[1].Color.g = ( ( FLOAT ) g / 255.0f );
v[1].Color.b = ( ( FLOAT ) b / 255.0f );
v[1].Color.a = ( ( FLOAT ) a / 255.0f );
v[2].Position.x = 2.0f * ( (x0 + radius) - 0.5f ) / vp.Width - 1.0f;
v[2].Position.y = 1.0f - 2.0f * ( y0 - 0.5f ) / vp.Height;
v[2].Position.z = 0.0f;
v[2].Color.r = ( ( FLOAT ) r / 255.0f );
v[2].Color.g = ( ( FLOAT ) g / 255.0f );
v[2].Color.b = ( ( FLOAT ) b / 255.0f );
v[2].Color.a = ( ( FLOAT ) a / 255.0f );
v[3].Position.x = 2.0f * ( (x0 - radius) - 0.5f ) / vp.Width - 1.0f;
v[3].Position.y = 1.0f - 2.0f * ( y0 - 0.5f ) / vp.Height;
v[3].Position.z = 0.0f;
v[3].Color.r = ( ( FLOAT ) r / 255.0f );
v[3].Color.g = ( ( FLOAT ) g / 255.0f );
v[3].Color.b = ( ( FLOAT ) b / 255.0f );
v[3].Color.a = ( ( FLOAT ) a / 255.0f );
while(x < y)
{
if(f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
v[i].Position.x = 2.0f * ( (x0 + x) - 0.5f ) / vp.Width - 1.0f;
v[i].Position.y = 1.0f - 2.0f * ( (y0 + y) - 0.5f ) / vp.Height;
v[i].Position.z = 0.0f;
v[i].Color.r = ( ( FLOAT ) r / 255.0f );
v[i].Color.g = ( ( FLOAT ) g / 255.0f );
v[i].Color.b = ( ( FLOAT ) b / 255.0f );
v[i].Color.a = ( ( FLOAT ) a / 255.0f );
v[i+1].Position.x = 2.0f * ( (x0 - x) - 0.5f ) / vp.Width - 1.0f;
v[i+1].Position.y = 1.0f - 2.0f * ( (y0 + y) - 0.5f ) / vp.Height;
v[i+1].Position.z = 0.0f;
v[i+1].Color.r = ( ( FLOAT ) r / 255.0f );
v[i+1].Color.g = ( ( FLOAT ) g / 255.0f );
v[i+1].Color.b = ( ( FLOAT ) b / 255.0f );
v[i+1].Color.a = ( ( FLOAT ) a / 255.0f );
v[i+2].Position.x = 2.0f * ( (x0 + x) - 0.5f ) / vp.Width - 1.0f;
v[i+2].Position.y = 1.0f - 2.0f * ( (y0 - y) - 0.5f ) / vp.Height;
v[i+2].Position.z = 0.0f;
v[i+2].Color.r = ( ( FLOAT ) r / 255.0f );
v[i+2].Color.g = ( ( FLOAT ) g / 255.0f );
v[i+2].Color.b = ( ( FLOAT ) b / 255.0f );
v[i+2].Color.a = ( ( FLOAT ) a / 255.0f );
v[i+3].Position.x = 2.0f * ( (x0 - x) - 0.5f ) / vp.Width - 1.0f;
v[i+3].Position.y = 1.0f - 2.0f * ( (y0 - y) - 0.5f ) / vp.Height;
v[i+3].Position.z = 0.0f;
v[i+3].Color.r = ( ( FLOAT ) r / 255.0f );
v[i+3].Color.g = ( ( FLOAT ) g / 255.0f );
v[i+3].Color.b = ( ( FLOAT ) b / 255.0f );
v[i+3].Color.a = ( ( FLOAT ) a / 255.0f );
v[i+4].Position.x = 2.0f * ( (x0 + y) - 0.5f ) / vp.Width - 1.0f;
v[i+4].Position.y = 1.0f - 2.0f * ( (y0 + x) - 0.5f ) / vp.Height;
v[i+4].Position.z = 0.0f;
v[i+4].Color.r = ( ( FLOAT ) r / 255.0f );
v[i+4].Color.g = ( ( FLOAT ) g / 255.0f );
v[i+4].Color.b = ( ( FLOAT ) b / 255.0f );
v[i+4].Color.a = ( ( FLOAT ) a / 255.0f );
v[i+5].Position.x = 2.0f * ( (x0 - y) - 0.5f ) / vp.Width - 1.0f;
v[i+5].Position.y = 1.0f - 2.0f * ( (y0 + x) - 0.5f ) / vp.Height;
v[i+5].Position.z = 0.0f;
v[i+5].Color.r = ( ( FLOAT ) r / 255.0f );
v[i+5].Color.g = ( ( FLOAT ) g / 255.0f );
v[i+5].Color.b = ( ( FLOAT ) b / 255.0f );
v[i+5].Color.a = ( ( FLOAT ) a / 255.0f );
v[i+6].Position.x = 2.0f * ( (x0 + y) - 0.5f ) / vp.Width - 1.0f;
v[i+6].Position.y = 1.0f - 2.0f * ( (y0 - x) - 0.5f ) / vp.Height;
v[i+6].Position.z = 0.0f;
v[i+6].Color.r = ( ( FLOAT ) r / 255.0f );
v[i+6].Color.g = ( ( FLOAT ) g / 255.0f );
v[i+6].Color.b = ( ( FLOAT ) b / 255.0f );
v[i+6].Color.a = ( ( FLOAT ) a / 255.0f );
v[i+7].Position.x = 2.0f * ( (x0 - y) - 0.5f ) / vp.Width - 1.0f;
v[i+7].Position.y = 1.0f - 2.0f * ( (y0 - x) - 0.5f ) / vp.Height;
v[i+7].Position.z = 0.0f;
v[i+7].Color.r = ( ( FLOAT ) r / 255.0f );
v[i+7].Color.g = ( ( FLOAT ) g / 255.0f );
v[i+7].Color.b = ( ( FLOAT ) b / 255.0f );
v[i+7].Color.a = ( ( FLOAT ) a / 255.0f );
NUMPOINTS = i+7;
i+=8;
}
this->m_pDeviceContext->Unmap( m_pVertexBuffer, NULL );
this->m_pDeviceContext->IASetInputLayout( m_pInputLayout );
UINT Stride = sizeof( COLOR_VERTEX );
UINT Offset = 0;
this->m_pDeviceContext->IASetVertexBuffers( 0, 1, &m_pVertexBuffer, &Stride, &Offset );
this->m_pDeviceContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST );
D3DX11_TECHNIQUE_DESC techDesc;
if( FAILED( m_pTechnique->GetDesc( &techDesc ) ) )
return;
for( UINT p = 0; p < techDesc.Passes; ++p )
{
m_pTechnique->GetPassByIndex( p )->Apply( 0, this->m_pDeviceContext );
this->m_pDeviceContext->Draw( NUMPOINTS, 0 );
}
}gws-wiz-hp