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


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

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


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

示例1: Draw

bool MyRender::Draw()
{
  static float dfi = 0.02f;
  static float fi = 0.0f;
  static float radius = 30.0f;
  
  float dz = radius * (cos(fi + dfi) - cos(fi));
  float dx = radius * (sin(fi + dfi) - sin(fi));
  m_car->RotateY(dfi);
  m_car->Translate(dx, 0, dz);
  fi += dfi;
  if (fi > XM_2PI)
    fi -= XM_2PI;

  ConstantBuffer cb;

  m_camera->Update();
  XMMATRIX view = XMLoadFloat4x4(&(m_camera->GetViewMatrix()));

  // add all projectors 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->GetProjectorLightsNumber(); j++, lightIndex++)
    {
      ProjectorLight *projector = object->GetProjectorAt(j);
      XMMATRIX projectorWorldMatrix = (XMLoadFloat4x4(&(object->GetWorldMatrix())));
      XMMATRIX projectorRotationMatrix = (XMLoadFloat4x4(&(object->GetRotationMatrix())));
      XMVECTOR tempPos = XMLoadFloat4(&(XMFLOAT4(projector->Pos.x, projector->Pos.y, projector->Pos.z, 1)));
      XMVECTOR tempDir = XMLoadFloat4(&(XMFLOAT4(projector->Direction.x, projector->Direction.y, projector->Direction.z, 1)));

      XMVECTOR projectorPos = XMVector4Transform(tempPos, projectorWorldMatrix);
      XMVECTOR projectorDir = XMVector4Transform(tempDir, projectorRotationMatrix);

      XMStoreFloat4(cb.vLightPos + lightIndex, projectorPos);
      XMStoreFloat4(cb.vLightDir + lightIndex, projectorDir);
	    cb.vLightColor[lightIndex] = projector->Color;
    }
  }
  // add all point 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->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;
//.........这里部分代码省略.........
开发者ID:Aspirisha,项目名称:CompGraphics,代码行数:101,代码来源:MyRender.cpp


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