Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在directx中制作旋转立方体?_Directx_Directx 11 - Fatal编程技术网

如何在directx中制作旋转立方体?

如何在directx中制作旋转立方体?,directx,directx-11,Directx,Directx 11,我正在学习directx编程。昨天我成功地做了一个立方体。 我想做一个旋转的立方体。事实上,我成功了,但我不确定我用的是正确的方法 下面的代码是常用的方式吗?我调用了一个函数来转换顶点位置,并在每一帧上创建新的顶点缓冲区。有没有其他方法不在每个帧上创建顶点缓冲区?有没有更有效的方法来证明绩效 void BoxApp::makeVertex() { Vertex vertices[] = { { XMFLOAT3(-1.0f, -1.0f, -1.0f), (con

我正在学习directx编程。昨天我成功地做了一个立方体。 我想做一个旋转的立方体。事实上,我成功了,但我不确定我用的是正确的方法

下面的代码是常用的方式吗?我调用了一个函数来转换顶点位置,并在每一帧上创建新的顶点缓冲区。有没有其他方法不在每个帧上创建顶点缓冲区?有没有更有效的方法来证明绩效

void BoxApp::makeVertex()
{
    Vertex vertices[] =
    {
        { XMFLOAT3(-1.0f, -1.0f, -1.0f), (const XMFLOAT4)Colors::White },
        { XMFLOAT3(-1.0f, +1.0f, -1.0f), (const XMFLOAT4)Colors::Black },
        { XMFLOAT3(+1.0f, +1.0f, -1.0f), (const XMFLOAT4)Colors::Red },
        { XMFLOAT3(+1.0f, -1.0f, -1.0f), (const XMFLOAT4)Colors::Green },
        { XMFLOAT3(-1.0f, -1.0f, +1.0f), (const XMFLOAT4)Colors::Blue },
        { XMFLOAT3(-1.0f, +1.0f, +1.0f), (const XMFLOAT4)Colors::Yellow },
        { XMFLOAT3(+1.0f, +1.0f, +1.0f), (const XMFLOAT4)Colors::Cyan },
        { XMFLOAT3(+1.0f, -1.0f, +1.0f), (const XMFLOAT4)Colors::Magenta }
    };
    rotating_angle += 0.01;
    for (int i = 0; i < 8; i++) {
        XMStoreFloat3(&vertices[i].pos, XMVector3Transform(XMLoadFloat3(&vertices[i].pos),
            XMMatrixTranslation(0.0f, 1.0f, 1.0f) *
            XMMatrixRotationX(rotating_angle) *
            XMMatrixTranslation(0.0f, -1.0f, -1.0f)
        ));
    }

    D3D11_BUFFER_DESC vbd;
    ... #Set BUFFER_DESC
    D3D11_SUBRESOURCE_DATA vinitData;
    ... #Set SUBRESURCE
    md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB);
}
void-BoxApp::makeVertex()
{
顶点[]=
{
{XMFLOAT3(-1.0f,-1.0f,-1.0f),(常数XMFLOAT4)颜色::白色},
{XMFLOAT3(-1.0f,+1.0f,-1.0f),(常数XMFLOAT4)颜色::黑色},
{XMFLOAT3(+1.0f,+1.0f,-1.0f),(常数XMFLOAT4)颜色::红色},
{XMFLOAT3(+1.0f,-1.0f,-1.0f),(常数XMFLOAT4)颜色::绿色},
{XMFLOAT3(-1.0f,-1.0f,+1.0f),(常数XMFLOAT4)颜色::蓝色},
{XMFLOAT3(-1.0f,+1.0f,+1.0f),(常数XMFLOAT4)颜色::黄色},
{XMFLOAT3(+1.0f,+1.0f,+1.0f),(常数XMFLOAT4)颜色::青色},
{XMFLOAT3(+1.0f,-1.0f,+1.0f),(常数XMFLOAT4)颜色::洋红色}
};
旋转角度+=0.01;
对于(int i=0;i<8;i++){
XMStoreFloat3(&顶点[i].pos),XMVector3Transform(XMLoadFloat3(&顶点[i].pos),
xmmatrixtransation(0.0f,1.0f,1.0f)*
XMMatrixRotationX(旋转角度)*
xmmatrixtransation(0.0f,-1.0f,-1.0f)
));
}
D3D11_BUFFER_DESC vbd;
…#设置缓冲区描述
D3D11_子资源_数据vinitData;
…#集次表层
md3dDevice->CreateBuffer(&vbd,&vinitData,&mBoxVB);
}

将顶点位置设置为局部坐标,并制作从局部坐标到世界坐标的变换矩阵。使用恒定缓冲区将其发送到顶点着色器。

将顶点位置设置为局部坐标,并生成从局部坐标到世界坐标的变换矩阵。使用常量缓冲区将其发送到顶点着色器。

使用常量缓冲区在顶点着色器内部对静态顶点缓冲区进行旋转,更新当前旋转。不要在每个帧上更新。跟踪时间并根据经过的时间进行更新。仅仅一个旋转的立方体就会有大量的FPS。PS:我对DX编程非常在行。不要要求代码!:)您应该查看,尤其是使用恒定缓冲区在顶点着色器中对静态顶点缓冲区进行旋转,在该缓冲区中更新当前旋转。不要在每个帧上更新。跟踪时间并根据经过的时间进行更新。仅仅一个旋转的立方体就会有大量的FPS。PS:我对DX编程非常在行。不要要求代码!:)您应该看看,尤其是