• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tim Lawton

World Matrix and Constant Buffer problem

9 posts in this topic

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
0

Share this post


Link to post
Share on other sites

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;

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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
1

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

Aye I did that

 

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

 

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

0

Share this post


Link to post
Share on other sites

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
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0