i created an app the initializes directx11 and then created a scenenode class that mimicks irrlicht scenenode.
i am having trouble understanding the matrix's being passed to my simple shader though and could use some help understanding.
in the scenenode i use the same methods as irrlicht (position, rotation, scale) and use the same updateabsoluteposition() each frame.
when passing params to the shader, i am stuck at the worldMatrix.
if I pass in a default world matrix the cube is rendered and everything is fine, but the cube is rendered only at the original location. I assume that, in order to move / rotate the cube, i need to pass a different worldMatrix to the shader (i.e. a scenenode specific matrix) which i had assumed would be the result of the getAbsoluteTransformation() but it doesnt seem to work.
a little code......
in scenenode (assume absoluteposition is identical to irrlicht node function)
Code: Select all
void SN_Cube::render()
{
unsigned int stride;
unsigned int offset;
// Set vertex buffer stride and offset.
stride = sizeof(VertexType);
offset = 0;
// Set the vertex buffer to active in the input assembler so it can be rendered.
getEngine()->getd3dImmediateContext()->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
// Set the index buffer to active in the input assembler so it can be rendered.
getEngine()->getd3dImmediateContext()->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
// Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
getEngine()->getd3dImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
// getShader()->m_ObjectTransform = getAbsoluteTransformation();
getShader()->m_ObjectTransform = getAbsoluteTransformation();
}
Code: Select all
bool CSShader_Color::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
XMMATRIX projectionMatrix)
{
HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource;
MatrixBufferType* dataPtr;
unsigned int bufferNumber;
// Transpose the matrices to prepare them for the shader.
worldMatrix = m_ObjectTransform;
worldMatrix = DirectX::XMMatrixTranspose(worldMatrix);
viewMatrix = DirectX::XMMatrixTranspose(viewMatrix);
projectionMatrix = DirectX::XMMatrixTranspose(projectionMatrix);
// Lock the constant buffer so it can be written to.
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if(FAILED(result))
{
return false;
}
// Get a pointer to the data in the constant buffer.
dataPtr = (MatrixBufferType*)mappedResource.pData;
// Copy the matrices into the constant buffer.
dataPtr->world = worldMatrix;
dataPtr->view = viewMatrix;
dataPtr->projection = projectionMatrix;
// Unlock the constant buffer.
deviceContext->Unmap(m_matrixBuffer, 0);
// Set the position of the constant buffer in the vertex shader.
bufferNumber = 0;
// Finanly set the constant buffer in the vertex shader with the updated values.
deviceContext->VSSetConstantBuffers(bufferNumber, 1, &m_matrixBuffer);
return true;
}
I know that m_ObjectTransform is a wrong way to do things but i am just testing..........
so the issue / question becomes
why does setting worldView to the scenenode's transform cause nothing to be rendered and how should I do this?