World Matrix and Constant Buffer problem

Started by
8 comments, last by Steve_Segreto 11 years ago

Not sure what to think on this, really confused.

I'll try to explain what I need to do best I can, its quite alot..

Firstly I have this method:


void MD5::RenderBuffers(ID3D11DeviceContext* deviceContext)
{
	unsigned int stride;
	unsigned int offset;

	//Set the vertex and pixel shaders that will be used to render this model
	deviceContext->VSSetShader(m_vertexShader, NULL, 0);
	deviceContext->PSSetShader(m_pixelShader, NULL, 0);

	//Set vertex buffer stride and offset
	stride = sizeof(VertexType); 
	offset = 0;

	for(int i = 0; i < m_NewMD5Model.numSubsets; i ++)
	{
		//Set the grounds index buffer
		deviceContext->IASetIndexBuffer(m_NewMD5Model.subsets.indexBuff, DXGI_FORMAT_R32_UINT, 0);
		//Set the grounds vertex buffer
		deviceContext->IASetVertexBuffers(0, 1, &m_NewMD5Model.subsets.vertBuff, &stride, &offset);

		WVP = world * view * projection;
		m_cbPerObj.WVP = XMMatrixTranspose(WVP);		
		m_cbPerObj.World = XMMatrixTranspose(m_smilesWorld);	
		m_cbPerObj.hasTexture = true;
		m_cbPerObj.hasNormMap = false;
		deviceContext->UpdateSubresource(cbPerObjectBuffer, 0, NULL, &m_cbPerObj, 0, 0);
		deviceContext->VSSetConstantBuffers(0, 1, &cbPerObjectBuffer);
		deviceContext->PSSetConstantBuffers(1, 1, &cbPerObjectBuffer);
		deviceContext->PSSetShaderResources(0, 1, &m_meshSRV[m_NewMD5Model.subsets.texArrayIndex]);
		deviceContext->PSSetSamplers(0, 1, &m_CubesTexSamplerState);
		deviceContext->RSSetState(m_RSCullNone);

		//Draw
		deviceContext->DrawIndexed(m_NewMD5Model.subsets.indices.size(), 0, 0 );
	}
}

This method is used to render an MD5 model, by applying World Matrix properties and other values such as that from the shader.

This line here:


D3DXMATRIX WVP;

WVP = world * view * projection;

World, View and Projection need to know about this struct in the header file


		struct MatrixBufferType
		{
			D3DXMATRIX world;
			D3DXMATRIX view;
			D3DXMATRIX projection;
		};

but instead return errors like this:

errorwl.png

Once these have correct values, I will be able to apply values to the WVP and World variables which reside inside the cbPerObj struct:




		struct cbPerObject
		{
			XMMATRIX WVP;
			XMMATRIX World;
			BOOL hasTexture;
			BOOL hasNormMap;
		};

Which will finally give the correctly values for the variables within the UpdateSubresource parameters...


		m_cbPerObj.WVP = XMMatrixTranspose(WVP);		
		m_cbPerObj.World = XMMatrixTranspose(m_smilesWorld);	
		m_cbPerObj.hasTexture = true;
		m_cbPerObj.hasNormMap = false;
		deviceContext->UpdateSubresource(cbPerObjectBuffer, 0, NULL, &m_cbPerObj, 0, 0);

But I'm not sure where I am going wrong, I'm aware theres a few crosses between XMMATRIX and D3DXMATRIX, these can be shortly after my first problem. Can anyone help?

EDIT:

I put the world, view, and projection matrix into the parameter of the method like so


void MD5::RenderBuffers(ID3D11DeviceContext* deviceContext, D3DXMATRIX worldMatrix, D3DXMATRIX viewMatrix, D3DXMATRIX projectionMatrix)

It has fixed the problem, I also changed a few XMMatrix and XMMatrixTranspose to it's D3DX Counter Part, which should makes things a bit smoother. Next problem I'm having this error I'm not sure what to make of it, it's asking for a pointer, any ideas?



		WVP = worldMatrix * viewMatrix * projectionMatrix;
		m_cbPerObj.WVP = D3DXMatrixTranspose(WVP);		
		m_cbPerObj.World = D3DXMatrixTranspose(m_smilesWorld);	

errorqn.png

Advertisement

What on earth? Sounds like you just need to either define world,view,projection or create an instance of that MatrixBufferType struct and use dotted notation like this:

MatrixBufferType mbt;

WVP = mbt.world * mbt.view * mbt.projection;

Hi mate, thanks for the quick reply. I've discovered I needed to put them into the parameters (as they need to be passed though to the next class where the camera class can pick it up).

I've added a sneaky edit to the end of my original post as I now have a new problem. If you could have a look at my latest problem and give me some insight that'd be highly appreciated. Thank you

If something asks for a pointer, put this in front of the variable '&'

D3DXMatrixTranspose( &WVP )

It's called the "address-of" operator if you want to Google it.

I did this and it demands I make &WVP a function.

I did this and I obtain a new issue I'm also not sure how to resolve.

errorsuq.png

It is also asking for a second value for the parameter, const D3DXMATRIX *pM

error2tp.png

Any ideas here?

It's only asking for &WVP to be a function because you typed a '(' afterwards - so don't do that smile.png Of course WVP isn't a function, its a matrix object!

D3DXMatrixTranspose() does take two functions. The first parameter is the destination of the transpose and the second parameter is the source.

If 'T' is the transpose operation, like '+' is the addition operation then:

D3DXMatrixTranspose( &WVP, &WVP );

would mean

WVP = T(WVP)

Are you basically trying to convert a DX11 function into a DX9 one?

No, it's all DX11.

I did what you said, but the equal symbol is throwing this error at me now:

"Error: no operator "=" matches these operands"

No i just said do this

D3DXMatrixTranspose( &WVP, &WVP );

Aye I did that


m_cbPerObj.WVP = D3DXMatrixTranspose(&WVP, &WVP);	

Now the equal symbol is throwing that error, any idea why?

I give up ... you need to learn how to program before you attempt stuff like this.

D3DXMatrixTranspose() doesn't return a D3DXMATRIX, it returns an HRESULT.

So just do this:

D3DXMatrixTranspose( &m_cbPerObj.WVP, &WVP );

don't add anything else

EDIT:

Xooch, I don't want to discourage you or be mean to you. However I still feel you need to brush up on basic programming concepts, like functions, function parameters, function return values, pass by value, pass by reference,

Good luck to you!

This topic is closed to new replies.

Advertisement