2013-07-23 3 views
1

그 그림을 그려 내고 싶습니다. enter image description here어떻게 DirectX를 사용하여 그리드 (평면)를 만들거나 그리거나 렌더링 할 수 있습니까?

이제 정점 버퍼를 시도하고 DrawPrimitive는 D3DPT_LINESTRIP입니다. 하지만 나는 효과가 없다.

그래서 어떤면에서는 효과가 있습니까?

제게 조언 해주세요. 고맙습니다.

+1

"내가 원하지 않는 효과"란 무엇을 의미합니까? 실제로 무엇을 얻었습니까? –

답변

0

DrawPrimitiveD3DPT_TRIANGLESTRIP을 비행기에 사용할 수 있습니다. 그런 다음 D3DPT_LINELIST 뒤에 깊이 바이어스으로 색인 된 선을 그립니다. 이 방법은, 비록 그들이 비행기에 누워 있더라도, 당신은 어떠한 z-fighting도 얻지 못할 것입니다.

1

내가 당신에게 책 Introduction to 3D programming with DirectX을 소개합니다, 그것은,이 옵션이 될 수있다 4.

1

좋은 8 장에서이 작업을 수행하는 방법에 대한 세부 사항 섹션이 최적이 아니라 그 격자를 achive 것

void DrawGrid (float32 Size, CColor Color, int32 GridX, int32 GridZ) 
{ 
    // Check if the size of the grid is null 
     if(Size <= 0) 
       return; 

    // Calculate the data 
    DWORD grid_color_aux = Color.GetUint32Argb(); 
    float32 GridXStep = Size/GridX; 
    float32 GridZStep = Size/GridZ; 
    float32 halfSize = Size * 0.5f; 

    // Set the attributes to the paint device 
    m_pD3DDevice->SetTexture(0,NULL); 
    m_pD3DDevice->SetFVF(CUSTOMVERTEX::getFlags()); 

    // Draw the lines of the X axis 
    for(float32 i = -halfSize; i <= halfSize ; i+= GridXStep) 
    { 
    CUSTOMVERTEX v[] = 
     { {i, 0.0f, -halfSize, grid_color_aux}, {i, 0.0f, halfSize, grid_color_aux} }; 

    m_pD3DDevice->DrawPrimitiveUP(D3DPT_LINELIST,1, v,sizeof(CUSTOMVERTEX)); 
    } 

    // Draw the lines of the Z axis 
    for(float32 i = -halfSize; i <= halfSize ; i+= GridZStep) 
    { 
    CUSTOMVERTEX v[] = 
    { {-halfSize, 0.0f, i, grid_color_aux}, {halfSize, 0.0f, i, grid_color_aux} }; 

    m_pD3DDevice->DrawPrimitiveUP(D3DPT_LINELIST,1, v,sizeof(CUSTOMVERTEX)); 
    } 
} 

CUSTOMVERTEX 구조체 :

struct CUSTOMVERTEX 
{ 
     float32 x, y, z; 
     DWORD color; 
     static unsigned int getFlags() 
     { 
       return D3DFVF_CUSTOMVERTEX; 
     } 
}; 

참고 : 순서대로, 고체면을 그릴 필요하므로 라인 만 그리드,인가 원하는 결과를 얻을 수 있습니다.