• 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 ); 

  • 相关阅读:
    Javascript的IE和Firefox兼容性汇编(转)
    JSP里request变量列表
    C#中的接口(转)
    寒羽对帝国的理解(通向高手之路)(转)
    怎样获得Sqlserver 2000得实例列表和运行在一个实例上得数据库列表(转)
    jsp文件上传的处理(转)
    用户不上你的网站的50个原因
    慈勤强的JFolder1.0版代码(JSP)
    管理常用SQL语句
    .net 取得访问的url
  • 原文地址:https://www.cnblogs.com/sifenkesi/p/1956212.html
Copyright © 2020-2023  润新知