OldSchoolHack

Register / Login English

Polygon in Welt zeichnen

icon Thread: Polygon in Welt zeichnen

Join Date: Aug 2007

Posts: 8643

User-Rating:

199 positive
33 negative
Und so ähnlich gehts in D3D auch. (Ungetestet weil noch nie gemacht)

CPP Code:
  1. //1. Device vorbereiten
  2. device->SetVertexShader(nullptr);
  3. device->SetPixelShader(nullptr);
  4. device->SetTexture(0, nullptr);
  5. device->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
  6.  
  7. device->SetRenderState(D3DRS_ZENABLE, TRUE);
  8. device->SetRenderState(D3DRS_LIGHTING, FALSE);
  9. device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
  10. device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
  11. device->SetRenderState(D3DRS_CLIPPING, FALSE);
  12. device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
  13. device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
  14. device->SetRenderState(D3DRS_SRCBLEND , D3DBLEND_SRCALPHA);
  15. device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTA_TEXTURE);
  16. device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTA_DIFFUSE);
  17.  
  18. //2. Sphere mit D3DXCreateSphere erzeugen
  19.  
  20. //3. Sphere rendern
  21. void DrawMesh(ID3DXMesh *mesh, Vector position, float scale, Color color)
  22. {
  23. LPDIRECT3DVERTEXBUFFER9 temp;
  24. if (SUCCEEDED(mesh->GetVertexBuffer(&temp)))
  25. {
  26. Vertex *vertices;
  27. if (SUCCEEDED(temp->Lock(0, 0, (void**)&vertices, 0)));
  28. {
  29. auto verticesCount = mesh->GetNumVertices();
  30. for (auto i = 0; i < verticesCount; ++i)
  31. {
  32. vertices[i].color = color;
  33. }
  34.  
  35. temp->Unlock();
  36. }
  37.  
  38. temp->Release();
  39. }
  40.  
  41. D3DXMATRIX world;
  42. D3DXMATRIX scaling;
  43.  
  44. D3DXMatrixTranslation(&world, position.x, position.y, position.z);
  45. D3DXMatrixScaling(&scaling, scale, scale, scale);
  46.  
  47. auto transform = scaling * world;
  48. device->SetTransform(D3DTS_WORLD, &transform);
  49.  
  50. mesh->DrawSubset(0);
  51. }

Wie genau du die anderen Matrizen setzen musst (Projection und View) kann ich dir grad nicht sagen und ist sicher spielabhängig.

__________________

Hallo