0

大家好,我正处于一个真正的绑定中,我目前正在使用 Frank d Luna http://www.d3dcoder.net/d3d11.htm使用 DirectX11 进行 3d 游戏编程中的 directx11 教程 Shapes 示例,我目前正在尝试添加一个我可以独立于第一个立方体放置的第二个立方体,我创建了它,当我构建项目时,两个立方体现在都消失了,我认为问题出在几何生成器上。

请帮忙 :(

    void ShapesApp::BuildGeometryBuffers()

{ GeometryGenerator::MeshData 框;

//added
GeometryGenerator::MeshData boxtwo;


GeometryGenerator::MeshData grid;
GeometryGenerator::MeshData sphere;
GeometryGenerator::MeshData cylinder;

GeometryGenerator geoGen;

geoGen.CreateBox(1.0f, 1.0f, 1.0f, box);

geoGen.CreateBox(1.0f, 1.0f, 1.0f, boxtwo);
geoGen.CreateGrid(20.0f, 30.0f, 60, 40, grid);
geoGen.CreateSphere(0.5f, 20, 20, sphere);
//geoGen.CreateGeosphere(0.5f, 2, sphere);
geoGen.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20, cylinder);

// Cache the vertex offsets to each object in the concatenated vertex buffer.
//added


mBoxVertexOffset      = 0;
mBoxtwoVertexOffset = box.Vertices.size();
mGridVertexOffset     = mBoxtwoVertexOffset + boxtwo.Vertices.size();
mSphereVertexOffset   = mGridVertexOffset + grid.Vertices.size();
mCylinderVertexOffset = mSphereVertexOffset + sphere.Vertices.size();



// Cache the index count of each object.

mBoxIndexCount      = box.Indices.size();
//added
mBoxtwoIndexCount   = boxtwo.Indices.size();
mGridIndexCount     = grid.Indices.size();
mSphereIndexCount   = sphere.Indices.size();
mCylinderIndexCount = cylinder.Indices.size();


// Cache the starting index for each object in the concatenated index buffer.
mBoxIndexOffset      = 0;
//added
mBoxtwoIndexOffset      = mBoxIndexCount;
mGridIndexOffset     = mBoxtwoIndexOffset + mBoxtwoIndexCount;
mSphereIndexOffset   = mGridIndexOffset + mGridIndexCount;
mCylinderIndexOffset = mSphereIndexOffset + mSphereIndexCount;



UINT totalVertexCount = 

    box.Vertices.size() + 
    //added
    boxtwo.Vertices.size() + 
    grid.Vertices.size() + 
    sphere.Vertices.size() +
    cylinder.Vertices.size();

UINT totalIndexCount = 
    mBoxIndexCount + 
    //added
mBoxtwoIndexCount + 
    mGridIndexCount + 
    mSphereIndexCount +
    mCylinderIndexCount;
4

1 回答 1

0

您似乎正确地完成了第一部分,但还有更多内容。

  • 然后您需要为第二个框添加顶点位置
  • 在向量索引缓冲区中插入第二个框的索引
  • 添加代码以绘制第二个框
  • 创建第二个盒子世界矩阵来定位它

我建议你再读一遍本章,在继续阅读之前完全理解每一章并能够正确修改其示例非常重要,否则你会在后面的章节中遇到很多问题。

这是一个带有代码更改的补丁,添加了第二个框:

    --- D:/MyStuff/Book Files/Frank Luna/DVD/Code/Chapter 6 Drawing in Direct3D/Shapes/ShapesDemoOriginal.cpp   Mon May 09 22:10:02 2011
    +++ D:/MyStuff/Book Files/Frank Luna/DVD/Code/Chapter 6 Drawing in Direct3D/Shapes/ShapesDemo.cpp   Fri Jan 11 12:37:54 2013
    @@ -58,0 +59 @@
    +   XMFLOAT4X4 mBoxWorld2;
    @@ -65,0 +67 @@
    +   int mBoxVertexOffset2;
    @@ -70,0 +73 @@
    +   UINT mBoxIndexOffset2;
    @@ -75,0 +79 @@
    +   UINT mBoxIndexCount2;
    @@ -122,0 +127,4 @@
    +   XMMATRIX boxScale2 = XMMatrixScaling(1.0f, 1.0f, 1.0f);
    +   XMMATRIX boxOffset2 = XMMatrixTranslation(2.0f, 0.5f, 0.0f);
    +   XMStoreFloat4x4(&mBoxWorld2, XMMatrixMultiply(boxScale2, boxOffset2));
    +
    @@ -226,0 +235,6 @@
    +       
    +       // Draw the box2.
    +       world = XMLoadFloat4x4(&mBoxWorld2);
    +       mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&(world*viewProj)));
    +       mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
    +       md3dImmediateContext->DrawIndexed(mBoxIndexCount2, mBoxIndexOffset2,         mBoxVertexOffset2);
    @@ -303,0 +318 @@
    +   GeometryGenerator::MeshData box2;
    @@ -309,0 +325 @@
    +   geoGen.CreateBox(1.0f, 1.0f, 1.0f, box2);
    @@ -317 +333,2 @@
    -   mGridVertexOffset     = box.Vertices.size();
    +   mBoxVertexOffset2     = box.Vertices.size();
    +   mGridVertexOffset     = box.Vertices.size() + box2.Vertices.size();
    @@ -322,0 +340 @@
    +   mBoxIndexCount2     = box2.Indices.size();
    @@ -329 +347,2 @@
    -   mGridIndexOffset     = mBoxIndexCount;
    +   mBoxIndexOffset2     = mBoxIndexCount;
    +   mGridIndexOffset     = mBoxIndexOffset2 + mBoxIndexCount2;
    @@ -334,0 +354 @@
    +       box2.Vertices.size() + 
    @@ -340,0 +361 @@
    +       mBoxIndexCount2 + 
    @@ -360,0 +382,6 @@
    +   for(size_t i = 0; i < box2.Vertices.size(); ++i, ++k)
    +   {
    +       vertices[k].Pos   = box2.Vertices[i].Position;
    +       vertices[k].Color = black;
    +   }
    +
    @@ -394,0 +422 @@
    +   indices.insert(indices.end(), box2.Indices.begin(), box2.Indices.end());
于 2013-01-11T19:04:00.453 回答