我想画那幅画。
现在我尝试顶点缓冲区,DrawPrimitive 是 D3DPT_LINESTRIP。但不是我想要的效果。
所以有什么比有效的吗???
请给我一些建议。谢谢你。
这可能是一种选择,不是最佳选择,但可以实现该网格
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;
}
};
注意:只是一个带有线条的网格,所以你需要画一个实心平面,才能得到你想要的结果。
您可以使用DrawPrimitive
withD3DPT_TRIANGLESTRIP
用于飞机。然后D3DPT_LINELIST
用深度偏差绘制索引线。这样,即使他们躺在飞机上,你也不会受到任何 z 战。
我会给你介绍一本书Introduction to 3D programming with DirectX
,它在第 8 章第 4 节中详细介绍了如何做到这一点。