Jump to content
  • Advertisement
Sign in to follow this  
Toastmastern

Rotating object

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

If you intended to correct an error in the post then please contact us.

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,
							  -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 Edited by Toastmastern

Share this post


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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!