大家好,我正处于真正的绑定状态,我目前正在使用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;
答案 0 :(得分: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());