当前位置: 首页>>代码示例>>C++>>正文


C++ MyObject::GetIndices方法代码示例

本文整理汇总了C++中MyObject::GetIndices方法的典型用法代码示例。如果您正苦于以下问题:C++ MyObject::GetIndices方法的具体用法?C++ MyObject::GetIndices怎么用?C++ MyObject::GetIndices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyObject的用法示例。


在下文中一共展示了MyObject::GetIndices方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Draw


//.........这里部分代码省略.........
    for (size_t j = 0; j < object->GetPointLightsNumber(); j++, lightIndex++)
    {
      SimpleLight *bulb = object->GetPointLightAt(j);
      XMMATRIX bulbWorldMatrix = (XMLoadFloat4x4(&(object->GetWorldMatrix())));
      XMVECTOR tempPos = XMLoadFloat4(&(XMFLOAT4(bulb->Pos.x, bulb->Pos.y, bulb->Pos.z, 1)));

      XMVECTOR bulbPos = XMVector4Transform(tempPos, bulbWorldMatrix);

      XMStoreFloat4(cb.vBulbLightPos + lightIndex, bulbPos);
	    cb.vBulbLightColor[lightIndex] = bulb->Color;
    }
  }

  // add all directed lights info to constant buffer
  for (size_t i = 0, lightIndex = 0; i < m_scene->GetObjectsNumber(); i++)
  {
    MyObject *object = m_scene->GetObjectAt(i);
    for (size_t j = 0; j < object->GetDirectedLightsNumber(); j++, lightIndex++)
    {
      DirectedLight *dirLight = object->GetDirectedLightAt(j);
      XMMATRIX dirRotationMatrix = (XMLoadFloat4x4(&(object->GetRotationMatrix())));
      XMVECTOR tempDir = XMLoadFloat4(&(XMFLOAT4(dirLight->Dir.x, dirLight->Dir.y, dirLight->Dir.z, 1)));

      XMVECTOR bulbPos = XMVector4Transform(tempDir, dirRotationMatrix);

      XMStoreFloat4(cb.vDirectedLightDir + lightIndex, bulbPos);
	    cb.vDirectedLightColor[lightIndex] = dirLight->Color;
    }
  }

  cb.isLightEnabled[0] = m_enableProjectorLight;
  cb.isLightEnabled[1] = m_enablePointLight;
  cb.isLightEnabled[2] = m_enableDirectedLight;
  cb.isLightEnabled[3] = 0;

  for (size_t idx = 0; idx < m_scene->GetObjectsNumber(); idx++)
  {
    MyObject *object = m_scene->GetObjectAt(idx);

    /****************************************************/

    D3D11_BUFFER_DESC bd;
    RtlZeroMemory(&bd, sizeof(bd));
    bd.Usage = D3D11_USAGE_DEFAULT;
    bd.ByteWidth = sizeof(SimpleVertex) * object->GetVerticesNumber();
	  bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	  bd.CPUAccessFlags = 0;

    D3D11_SUBRESOURCE_DATA data;
    RtlZeroMemory(&data, sizeof(data));
    data.pSysMem = object->GetVertices();

    HRESULT hr = m_pd3dDevice->CreateBuffer(&bd, &data, &m_pVertexBuffer);
    if (FAILED(hr))
    {
      Log::Get()->Err("CreateBuffer error for vertex buffer.");
      return false;
    }
    UINT stride = sizeof(SimpleVertex);
	  UINT offset = 0;

    m_pImmediateContext->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset);
  
    bd.Usage = D3D11_USAGE_DEFAULT;
    bd.ByteWidth = sizeof(UINT) * object->GetIndicesNumber();
	  bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
	  bd.CPUAccessFlags = 0;
	  data.pSysMem = object->GetIndices();
	  hr = m_pd3dDevice->CreateBuffer(&bd, &data, &m_pIndexBuffer);
	  if(FAILED(hr))
    {
      Log::Get()->Err("CreateBuffer error for torus.");
		  return false;
    }
    m_pImmediateContext->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
    m_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    /****************************************************/
    XMMATRIX world = XMLoadFloat4x4(&(object->GetWorldMatrix()));

    cb.mWorld = XMMatrixTranspose(world);
    cb.mView = XMMatrixTranspose(view);
	  cb.mProjection = XMMatrixTranspose(m_Projection);
    cb.vOutputColor = XMFLOAT4(0, 0, 0, 0);
	  m_pImmediateContext->UpdateSubresource(m_pConstantBuffer, 0, NULL, &cb, 0, 0);
  
	  m_pImmediateContext->VSSetShader(m_pVertexShader, NULL, 0);
	  m_pImmediateContext->VSSetConstantBuffers( 0, 1, &m_pConstantBuffer);
    if (object == m_sun) // absolutely black body
	    m_pImmediateContext->PSSetShader(m_pPixelShaderSolid, NULL, 0);
    else
      m_pImmediateContext->PSSetShader(m_pPixelShader, NULL, 0);
	  m_pImmediateContext->PSSetConstantBuffers( 0, 1, &m_pConstantBuffer);
    m_pImmediateContext->DrawIndexed(object->GetIndicesNumber(), 0, 0);

    _RELEASE(m_pVertexBuffer);
    _RELEASE(m_pIndexBuffer);
  }
	return true;
}
开发者ID:Aspirisha,项目名称:CompGraphics,代码行数:101,代码来源:MyRender.cpp


注:本文中的MyObject::GetIndices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。