zoukankan      html  css  js  c++  java
  • 【DirectX12】第六章-练习

    练习3.

    (a)

    //LINELIST
    
        std::array<VPosData, 8> posData = {
            VPosData({ XMFLOAT3(-2.0f, -1.0f, +1.0f) }),
            VPosData({ XMFLOAT3(-1.5f, +1.0f, +1.0f) }),
            VPosData({ XMFLOAT3(-1.0f, -0.3f, +1.0f) }),
            VPosData({ XMFLOAT3(-0.3f, +0.7f, +1.0f) }),
            VPosData({ XMFLOAT3(-0.0f, -0.3f, +1.0f) }),
            VPosData({ XMFLOAT3(+1.0f, +0.7f, +1.0f) }),
            VPosData({ XMFLOAT3(+2.0f, +0.0f, +1.0f) }),
            VPosData({ XMFLOAT3(+2.7f, +1.5f, +1.0f) }),
        };
    
        std::array<std::uint16_t, 36> indices =
        {
            0,1,2,
            1,2,3,
            2,3,4,
            3,4,5,
            4,5,6,
            5,6,7,
        };

     (b)

    //LINELIST
    
        std::array<std::uint16_t, 36> indices =
        {
            0,1,2,3,4,5,6,7
        };

    (c)

    //LINELIST
    std::array<std::uint16_t, 36> indices =
        {
            0,1,
            1,2,
            0,2,
            1,3,
            2,3,
            3,4,
            2,4,
            3,5,
            4,5,
            5,6,
            4,6,
            5,7,
            6,7
        };

    练习4:

    //TRIANGLESTRIP
    
    std::array<VPosData, 5> posData = {
            VPosData({ XMFLOAT3(-1.0f, -1.0f, -1.0f) }),
            VPosData({ XMFLOAT3(+1.0f, -1.0f, -1.0f) }),
            VPosData({ XMFLOAT3(+1.0f, -1.0f, +1.0f) }),
            VPosData({ XMFLOAT3(-1.0f, -1.0f, +1.0f) }),
            VPosData({ XMFLOAT3(-0.0f, +0.78f, +0.0f) }),
    
        };
    
        std::array<VColorData, 5> colorData{
            VColorData({ XMFLOAT4(Colors::Green) }),
            VColorData({ XMFLOAT4(Colors::Green) }),
            VColorData({ XMFLOAT4(Colors::Green) }),
            VColorData({ XMFLOAT4(Colors::Green) }),
            VColorData({ XMFLOAT4(Colors::Red) })
        };
    
        std::array<std::uint16_t, 36> indices =
        {
            0,1,2,
            0,3,2,
    
            0,1,4,
            0,3,4,
            1,2,4,
            2,3,4,
        };

     在update中添加代码获得旋转效果:

        XMMATRIX Ry;
    
        static float Y = 0.0f;
        Ry = XMMatrixRotationY(Y);
        Y += 0.001;  
        XMStoreFloat4x4(&mWorld, Ry);

    添加另一个图形(新建buffer):

    BoxApp.cpp

    ①修改ommandList:

    std::unique_ptr<MeshGeometry> mBoxGeo02 = nullptr;
    mCommandList->IASetVertexBuffers(0, 1, &mBoxGeo02->VertexBufferView());//设置顶点buffer视图,起始接口也为0,顶点buffer数量依旧为1个
    
    mCommandList->IASetIndexBuffer(&mBoxGeo02->IndexBufferView());//设置索引buffer视图
    
    mCommandList->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);//不变 
    
    mCommandList->SetGraphicsRootDescriptorTable(0, mCbvHeap->GetGPUDescriptorHandleForHeapStart());
    mCommandList->DrawIndexedInstanced( mBoxGeo02->DrawArgs["cww"].IndexCount, 1, 0, 0, 0);//改变drawargs里的字符串,因为是另一个物体,用不同名字以区分
  • 相关阅读:
    asp读书笔记(二)内置对象
    网上收集的关于iframe的自适应高度代码js的
    第一遇到地震,虽然小点
    给网友写的控制页面元素高度的代码(js)
    给用户控件添加可枚举的属性
    标记(Tagging)能给网站带来的7大益处
    代码最重要的读者不再是编译器、解释器或者电脑,而是人!
    亚洲超大数据库会议(XLDB Asia 2012)
    每年15万美元!这是开发人员解决构造问题的总成本!
    华章IT图书书讯(2012年第7期)
  • 原文地址:https://www.cnblogs.com/liez/p/7492743.html
Copyright © 2011-2022 走看看