Jump to content

  • Log In with Google      Sign In   
  • Create Account

World Matrix and Constant Buffer problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 28 March 2013 - 09:59 PM

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[i].indexBuff, DXGI_FORMAT_R32_UINT, 0);
		//Set the grounds vertex buffer
		deviceContext->IASetVertexBuffers(0, 1, &m_NewMD5Model.subsets[i].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[i].texArrayIndex]);
		deviceContext->PSSetSamplers(0, 1, &m_CubesTexSamplerState);
		deviceContext->RSSetState(m_RSCullNone);

		//Draw
		deviceContext->DrawIndexed(m_NewMD5Model.subsets[i].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


Edited by Xooch, 28 March 2013 - 10:18 PM.


Sponsor:

#2 Steve_Segreto   Crossbones+   -  Reputation: 1532

Like
0Likes
Like

Posted 28 March 2013 - 10:13 PM

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;



#3 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 28 March 2013 - 10:17 PM

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



#4 Steve_Segreto   Crossbones+   -  Reputation: 1532

Like
1Likes
Like

Posted 28 March 2013 - 10:20 PM

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.


Edited by Steve_Segreto, 28 March 2013 - 10:44 PM.


#5 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 28 March 2013 - 10:28 PM

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?



#6 Steve_Segreto   Crossbones+   -  Reputation: 1532

Like
0Likes
Like

Posted 28 March 2013 - 10:34 PM

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?


Edited by Steve_Segreto, 28 March 2013 - 10:36 PM.


#7 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 28 March 2013 - 10:40 PM

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"


Edited by Xooch, 28 March 2013 - 10:41 PM.


#8 Steve_Segreto   Crossbones+   -  Reputation: 1532

Like
0Likes
Like

Posted 28 March 2013 - 10:42 PM

No i just said do this

 

D3DXMatrixTranspose( &WVP, &WVP ); 



#9 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 28 March 2013 - 11:02 PM

Aye I did that

 

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

 

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



#10 Steve_Segreto   Crossbones+   -  Reputation: 1532

Like
1Likes
Like

Posted 29 March 2013 - 12:05 AM

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!


Edited by Steve_Segreto, 31 March 2013 - 12:41 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS