• Tutorial 5: 3D Transformation


    D3D中,变换就是通过和一个变换矩阵相乘来执行的。

    D3D中有3中基本的图元变换方式:

    平移translation (where it lies in space relative to the origin):

      XMMatrixTranslation

      XMMatrixTranslationFromVector

    旋转rotation (its direction in relation to the x, y, z frame):

      XMMatrixRotationX

      XMMatrixRotationY

      XMMatrixRotationZ

      XMMatrixRotationAxis

    缩放scaling (its distance from origin):

      XMMatrixRotationAxis

    复杂的运动(变换)都可以用以上基本变换复合而成。

    深度缓存的使用:(深度缓存就是一个2D texture,所以我们使用CreateTexture2D来创建深度缓存)

        ID3D11Texture2D*        g_pDepthStencil = NULL;

        ID3D11DepthStencilView* g_pDepthStencilView = NULL;

        // Create depth stencil texture创建深度模板纹理

        D3D11_TEXTURE2D_DESC descDepth;

        ZeroMemory( &descDepth, sizeof(descDepth) );

        descDepth.Width = width;

        descDepth.Height = height;

        descDepth.MipLevels = 1;

        descDepth.ArraySize = 1;

        descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; //A 32-bit z-buffer format that uses 24 bits for the depth channel and 8 bits for the stencil                                  //channel.

        descDepth.SampleDesc.Count = 1;

        descDepth.SampleDesc.Quality = 0;

        descDepth.Usage = D3D11_USAGE_DEFAULT;

        descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;

        descDepth.CPUAccessFlags = 0;

        descDepth.MiscFlags = 0;

        hr = g_pd3dDevice->CreateTexture2D( &descDepth, NULL, &g_pDepthStencil );

        if( FAILED( hr ) )

            return hr;

     

        // Create the depth stencil view创建深度模板视图

        D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;

         ZeroMemory( &descDSV, sizeof(descDSV) );

        descDSV.Format = descDepth.Format;

        descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;//The resource will be accessed as a 2D texture.

        descDSV.Texture2D.MipSlice = 0;

        hr = g_pd3dDevice->CreateDepthStencilView( g_pDepthStencil, &descDSV, &g_pDepthStencilView );

        if( FAILED( hr ) )

            return hr;

     

         //将render targets和depth-stencil buffer绑定到设备的Output-merger state

        g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView);

     

        //每一帧render之前,需要清空深度模板视图 Clear the depth buffer to 1.0 (max depth)

        g_pImmediateContext->ClearDepthStencilView( g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 ); 

  • 相关阅读:
    python 并发编程 多线程 event
    python 并发编程 多线程 定时器
    python 并发编程 多线程 信号量
    linux top 查看CPU命令
    python 并发编程 多线程 GIL与多线程
    python 并发编程 多线程 死锁现象与递归锁
    python 并发编程 多线程 GIL与Lock
    python GIL全局解释器锁与互斥锁 目录
    python 并发编程 多线程 GIL全局解释器锁基本概念
    执行python程序 出现三部曲
  • 原文地址:https://www.cnblogs.com/sifenkesi/p/1956212.html
Copyright © 2020-2023  润新知