Sign in to follow this  
michamoo

(Question) How to make Circle Minimap?

Recommended Posts

Hello, I have small question.. I have game and.. I had there Square Minimap, but now I need Circle minimap. I tried something on internet, but when I used Filled Minimap, it have just color of minimap, and when I used normal rendering, it´s circle, but there is just one circle line, and in that circle isn´t anything, it´s empty. I´m using Device->SetTexture(0, pMINIMAP);

Working one : (square)

int nRng;int nPos; m_pTZOOMSCROLL->GetScrollPos(nRng, nPos);m_pTMAP->m_fTSCALE = TMINIMAP_INIT_SCALE / powf(TMINIMAP_SCALE_FACTOR, (FLOAT)nPos); CRect rect(0, 0,TMINIMAPTEX_SIZE,TMINIMAPTEX_SIZE); rect.OffsetRect(m_rc.left + m_rcAREA.left - (190 - m_rcAREA.Width()) / 0.85,  m_rc.top + m_rcAREA.top - (190 - m_rcAREA.Height()) / 0.65); TNLVERTEX vRECT[4] = {{ FLOAT(rect.left), FLOAT(rect.top), 0.5f, 1.0f, 0xFFFFFFFF, 0.0f, 0.0f},{ FLOAT(rect.right), FLOAT(rect.top), 0.5f, 1.0f, 0xFFFFFFFF, 1.0f, 0.0f},{ FLOAT(rect.left), FLOAT(rect.bottom), 0.5f, 1.0f, 0xFFFFFFFF, 0.0f, 1.0f},{ FLOAT(rect.right), FLOAT(rect.bottom), 0.5f, 1.0f, 0xFFFFFFFF, 1.0f, 1.0f}};FLOAT fMIP = 0.0f; m_pDevice->m_pDevice->SetSamplerState( 0, D3DSAMP_MIPMAPLODBIAS, *((LPDWORD) &fMIP));m_pDevice->m_pDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);m_pDevice->m_pDevice->SetTexture( 0, m_pTMINIMAP);m_pDevice->m_pDevice->SetFVF(T3DFVF_TNLVERTEX);m_pDevice->m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2, vRECT, sizeof(TNLVERTEX));

Not working one :

int nRng;int nPos; m_pTZOOMSCROLL->GetScrollPos(nRng, nPos);m_pTMAP->m_fTSCALE = TMINIMAP_INIT_SCALE / powf(TMINIMAP_SCALE_FACTOR, (FLOAT)nPos); CPoint rect(TMINIMAPTEX_SIZE); rect.Offset(m_rc.left + m_rcAREA.left - (190 - m_rcAREA.Width()) / 0.85, m_rc.top + m_rcAREA.top - (190 - m_rcAREA.Height()) / 0.65);    const int NUMPOINTS = 30;     TNLVERTEX Circle[NUMPOINTS + 1];     float WedgeAngle = ( float )( ( 2 * D3DX_PI ) / NUMPOINTS ); FLOAT fMIP = 0.0f;      for( int i = 0; i m_pDevice->SetSamplerState( 0, D3DSAMP_MIPMAPLODBIAS, *((LPDWORD) &fMIP));m_pDevice->m_pDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);m_pDevice->m_pDevice->SetTexture( 0, m_pTMINIMAP);m_pDevice->m_pDevice->SetFVF(D3DFVF_TL);    m_pDevice->m_pDevice->DrawPrimitiveUP( D3DPT_LINESTRIP, NUMPOINTS, Circle, sizeof( TNLVERTEX ) );Thanks for any help!
Edited by Josh Petrie

Share this post


Link to post
Share on other sites

I guess you can use multi-texturing with a quad. Have a texture with the shape of what you want and use it as alpha. You may need to move away from fixed pipeline. Or use the stencil buffer.

Edited by Tispe

Share this post


Link to post
Share on other sites
1. Use a triangle fan (D3DPT_TRIANGLEFAN).
2. Use correct tex coords, something like this:

Circle[i].m_fU = (float)( 0.5 + 0.5 * cos( Theta ) );
Circle[i].m_fV = (float)( 0.5 - 0.5 * sin( Theta ) );
(Edit: Copy paste fail correction)
3. Your primitive count is off by one. Use NUMPOINTS + 1. Hmmm, wait, no you don't need to duplicate the start point for a fan. Edited by unbird

Share this post


Link to post
Share on other sites

I edited both, but now it don´t appear, I can´t see anything. I tried just with TriangleFan and U and V same as before, and it don´t work too. If we will resolve it, I can give you some money.

Share this post


Link to post
Share on other sites

Save the money for your girlfriend wink.png

 

Ok, general debugging hints:

 

1. Always check the HRESULT returned from API calls (With the FAILED/SUCCEEDED macro).
2. Use the D3D debug layer, for D3D9 this is enabled with the DirectX Control Panel. Then watch the output log in Visual Studio.
3. Use [url="http://blogs.msdn.com/b/manders/archive/2006/12/15/a-painless-introduction-to-pix-for-windows.aspx"]PIX[/url] or another graphics debugger.

 

Hmmm, I might have done a mistake with the primitive count. The amount is number_of_vertices - 2 for fans. Sorry 'bout that.

Edited by unbird

Share this post


Link to post
Share on other sites

That is +- problem, because this game is really big and it can´t be debugged in VS, cause it have big datafolder. anyway, maybe it can be problem too, I´m using VS 2003. And I will give you money, I´m not rich, but something I can give you :D 
And thanks for all your help!

Share this post


Link to post
Share on other sites

So it can look like this? 

    const int NUMPOINTS = 30;     TNLVERTEX Circle[NUMPOINTS + 1];     float WedgeAngle = ( float )( ( 2 * D3DX_PI ) / NUMPOINTS ); FLOAT fMIP = 0.0f;      for( int i = 0; i m_pDevice->SetSamplerState( 0, D3DSAMP_MIPMAPLODBIAS, *((LPDWORD) &fMIP));m_pDevice->m_pDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);m_pDevice->m_pDevice->SetTexture( 0, m_pTMINIMAP);m_pDevice->m_pDevice->SetFVF(D3DFVF_TL);    m_pDevice->m_pDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, NUMPOINTS-2, Circle, sizeof( TNLVERTEX ) ); 
Edited by Josh Petrie

Share this post


Link to post
Share on other sites

The primitive count is probably fine, but the texcoords are bad again.

 

And seriously, start proper error checking of those HRESULTs.

 

Hmmm, maybe a culling problem: Try disable culling (SetRenderState) or reverse the winding of those points (negate Theta). 

Share this post


Link to post
Share on other sites

So, I little bit edited code. Now it looks like this : http://prntscr.com/6rpibs But that is again that what I said.

   TNLVERTEX verts[CIRCLE_RESOLUTION+1];float WedgeAngle = ( float )( ( 2 * D3DX_PI ) / CIRCLE_RESOLUTION );    for (int i = 0; i < CIRCLE_RESOLUTION+1; i++)    { float Theta        = ( float )( i * WedgeAngle );         verts[i].m_fPosX = rect.x + 152*cos(D3DX_PI*(i/(CIRCLE_RESOLUTION/2.0f)));        verts[i].m_fPosY = rect.y + 152*sin(D3DX_PI*(i/(CIRCLE_RESOLUTION/2.0f)));        verts[i].m_fPosZ = 0;        verts[i].m_fRHW = 1;        verts[i].m_dwColor = 0xFFFFFFFF;verts[i].m_fU = (float)( 0.5 + 0.5 * cos( Theta ) );verts[i].m_fV = (float)( 0.5 - 0.5 * sin( Theta ) );    }m_pDevice->m_pDevice->SetTexture(0, m_pTMINIMAP);    m_pDevice->m_pDevice->SetFVF(VERTEX_2D_DIF::FVF);    m_pDevice->m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, CIRCLE_RESOLUTION-1, &verts, sizeof(TNLVERTEX));
Edited by Josh Petrie

Share this post


Link to post
Share on other sites

I have one more small problem. This minimap is rotated by 180° . It was by 90°, so I just changed in U and V sin to cos and cos to sin. But it´s still 180°. It isn´t big problem, but.. It don´t looks like nice :D

Code : 

   TNLVERTEX verts[CIRCLE_RESOLUTION+1];
float WedgeAngle = ( float )( ( 2 * D3DX_PI ) / CIRCLE_RESOLUTION );
rect.x -= 110;
rect.y += 82;
    for (int i = 0; i < CIRCLE_RESOLUTION+1; i++)
    {
 float Theta        = ( float )( i * WedgeAngle ); 
 
        verts[i].m_fPosX = rect.x + 98*cos(D3DX_PI*(i/(CIRCLE_RESOLUTION/2.0f)));
        verts[i].m_fPosY = rect.y + 98*sin(D3DX_PI*(i/(CIRCLE_RESOLUTION/2.0f)));
        verts[i].m_fPosZ = 0;
        verts[i].m_fRHW = 1.0f;
        verts[i].m_dwColor = 0xFFFFFFFF;
verts[i].m_fU = (float)( 0.5 + 0.5 * sin( Theta ) );
verts[i].m_fV = (float)( 0.5 - 0.5 * cos( Theta ) );
    }
FLOAT fMIP = 0.0f;
 
m_pDevice->m_pDevice->SetSamplerState( 0, D3DSAMP_MIPMAPLODBIAS, *((LPDWORD) &fMIP));
m_pDevice->m_pDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
m_pDevice->m_pDevice->SetTexture(0, m_pTMINIMAP);
    m_pDevice->m_pDevice->SetFVF(T3DFVF_TNLVERTEX);
    m_pDevice->m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, CIRCLE_RESOLUTION, &verts, sizeof(TNLVERTEX));
As I said, I don´t have problem with giving money, so If someone will really help me, I will give him some $.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this