# Rotating object

This topic is 802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

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,
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;
}



	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;

deviceContext->Unmap(mTessellationBuffer, 0);

bufferNumber = 0;

deviceContext->HSSetConstantBuffers(bufferNumber, 1, &mTessellationBuffer);

return true;

Is there anything obvious that I am missing?

Toastmastern Edited by Toastmastern

##### Share on other sites
This is going to sound silly, but have you made sure radiansToRotate is changing to a different value every frame?

##### Share on other sites

This is going to sound silly, but have you made sure radiansToRotate is changing to a different value every frame?

It is, what I found was that the radiansToRotate was always so small and I forgotten that it would work this way, I had to add radiansToRotate to the old radiansToRotate all the time to increase it. I tried a different approach before and that one had me only use the difference every frame and not the total amount. Now I only have 1 bug left that I will sort out tonight(something with my gameTime class that gets the difference wrong when the second mark goes from 59 to 0 or something like that)

//Toastmastern

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013638
×