I have a planet that I needs to rotate around it's own Y-axis. I read up some and the way to go seems to be to let
the shader do the work. I have a rotation matrix:
mPlanetRotationMatrix = XMMATRIX(cosf(radiansToRotate), 0.0f, sinf(radiansToRotate), 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
-sinf(radiansToRotate), 0.0f, cosf(radiansToRotate), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
I then multiply my viewMatrix I get from the camera with this rotationMatrix: mCamera->GetViewMatrix(viewMatrix);
planetViewMatrix = XMMatrixMultiply(mPlanetRotationMatrix, viewMatrix);
I then send it to the ColorShader: result = shaderManager->RenderColorShader(direct3D->GetDeviceContext(), mTerrain->GetIndexCount(), worldMatrix, planetViewMatrix, projectionMatrix, tessellationAmount, textureManager->GetTexture(0));
The view matrix(in this class it is called viewMatrix again) is updated every frame in the code: result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, tessellationAmount, texture);
if (!result)
{
return false;
}
RenderShader(deviceContext, indexCount);
Here is the SetShaderParameters code: HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource;
MatrixBufferType *dataPtr;
unsigned int bufferNumber;
TessellationBufferType *dataPtr2;
worldMatrix = XMMatrixTranspose(worldMatrix);
viewMatrix = XMMatrixTranspose(viewMatrix);
projectionMatrix = XMMatrixTranspose(projectionMatrix);
result = deviceContext->Map(mMatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
return false;
}
dataPtr = (MatrixBufferType*)mappedResource.pData;
dataPtr->world = worldMatrix;
dataPtr->view = viewMatrix;
dataPtr->projection = projectionMatrix;
deviceContext->Unmap(mMatrixBuffer, 0);
bufferNumber = 0;
deviceContext->DSSetConstantBuffers(bufferNumber, 1, &mMatrixBuffer);
result = deviceContext->Map(mTessellationBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
return false;
}
dataPtr2 = (TessellationBufferType*)mappedResource.pData;
dataPtr2->tessellationAmount = tessellationAmount;
dataPtr2->padding = XMFLOAT3(0.0f, 0.0f, 0.0f);
deviceContext->Unmap(mTessellationBuffer, 0);
bufferNumber = 0;
deviceContext->HSSetConstantBuffers(bufferNumber, 1, &mTessellationBuffer);
deviceContext->DSSetShaderResources(0, 1, &texture);
return true;
Is there anything obvious that I am missing?Thanks in advance
Toastmastern