本文整理汇总了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;
}