這個問題是繼續「why D3DXCreateCylinder is not creating a cylinder?」。我可以繪製圓柱體,但它只是將其繪製爲。爲什麼D3DXCreateCylinder製成網狀着色/材料不工作?
的代碼如下
void draw_Cylinder(void){
D3DXMATRIX rot_matrix;
D3DXMATRIX trans_matrix;
D3DXMATRIX world_matrix;
static float rot_triangle=0.0f;
static float rot_triangle2=0.0f;
D3DXMatrixRotationY(&rot_matrix,rot_triangle); //Rotate the cylinder
D3DXMatrixRotationX(&rot_matrix,rot_triangle2); //Rotate the cylinder
D3DXMatrixTranslation(&trans_matrix,2.0f,0,20.0f); //Shift it 2 units to the left
D3DXMatrixMultiply(&world_matrix,&rot_matrix,&trans_matrix);
D3DMATERIAL9 material;// = new D3DMATERIAL9();
ZeroMemory(&material, sizeof(D3DMATERIAL9));
// Set the RGBA for diffuse reflection.
material.Diffuse.r = 0.5f;
material.Diffuse.g = 0.0f;
material.Diffuse.b = 0.5f;
material.Diffuse.a = 1.0f;
// Set the RGBA for ambient reflection.
material.Ambient.r = 0.5f;
material.Ambient.g = 0.0f;
material.Ambient.b = 0.5f;
material.Ambient.a = 1.0f;
// Set the color and sharpness of specular highlights.
material.Specular.r = 1.0f;
material.Specular.g = 1.0f;
material.Specular.b = 1.0f;
material.Specular.a = 1.0f;
material.Power = 2.0f;
// Set the RGBA for emissive color.
material.Emissive.r = 0.0f;
material.Emissive.g = 0.0f;
material.Emissive.b = 0.0f;
material.Emissive.a = 0.0f;
g_d3d_device->SetMaterial(&material);
g_d3d_device->SetTexture(0,NULL);
g_d3d_device->SetTransform(D3DTS_WORLD,&world_matrix);
m_ppMeshCylinder->DrawSubset(0);
////Render from our Vertex Buffer
//g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST, //PrimitiveType
// 0, //StartVertex
// g_pyramid_count); //PrimitiveCount
rot_triangle+=0.0007f;
if(rot_triangle > D3DX_PI*2)
{
rot_triangle-=D3DX_PI*2;
}
rot_triangle2+=0.0007f;
if(rot_triangle2 > D3DX_PI*2)
{
rot_triangle2-=D3DX_PI*2;
}
}
或下載項目。 我已經吸引了我的代碼在這裏「project code」 我想繪製它具有三維陰影通常任何3D網格,如果默認呈現。 我不太瞭解材料。或者它是顯卡的問題(我只是想:D)。
另外我在哪裏可以得到信息和樣品ABT SetRenderState
你之前還設置過光源嗎?如果沒有,你需要這樣做。 – casablanca 2011-04-13 14:52:27
好吧,它在同一個項目中工作後,我添加了一個燈..但不是在主項目(另一個單獨的項目)。我試過它的頂點方式如下對於它來說不是必需的。對我來說真的很艱難。 'pTempEarthMesh-> CloneMeshFVF(0,D3DFVF_MY_VERTEX,g_pd3dDevice,&g_pEarthMesh); CUSTOMVERTEX * pVertices = NULL; pTempVertexBuffer-> Lock(0,0,(void **)&pVertices,0); {for(int i = 0; i
Rick2047
2011-04-13 15:22:25
它適用於我鏈接到的項目。 – Rick2047 2011-04-18 07:42:35