Cannot render scene with scale

Started by
5 comments, last by Buckeye 13 years, 5 months ago
Hello anybody. My first shader renders a mesh so well in this state
void DrawModel (MyMesh Model, LPDIRECT3DTEXTURE9 * meshTextures) {	Effect->SetTechnique("Simplest");	D3DXMATRIX mTranslation;	D3DXMatrixTranslation(&mTranslation, 0, 0, 0);	Effect->SetMatrix("xWorldViewProjection", &(matView * matProj * mTranslation));	UINT Passes;	Effect->Begin(&Passes, 0);	for (UINT Pass = 0; Pass < Passes; Pass++)	{		Effect->BeginPass(Pass);		for (DWORD i=0; i<Model.numMaterials; i++)		{			Effect->SetTexture("xTexture", meshTextures);			Effect->CommitChanges();			DXOutDevice->SetMaterial(&(Model.meshMaterials));			Model.Mesh->DrawSubset(i);		}		Effect->EndPass();	}	Effect->End();}

I see a small model
but if i want translate model to (1,1,1)
void DrawModel (MyMesh Model, LPDIRECT3DTEXTURE9 * meshTextures) {	Effect->SetTechnique("Simplest");	D3DXMATRIX mTranslation;	D3DXMatrixTranslation(&mTranslation, 1, 1, 1);	Effect->SetMatrix("xWorldViewProjection", &(matView * matProj * mTranslation));	UINT Passes;	Effect->Begin(&Passes, 0);	for (UINT Pass = 0; Pass < Passes; Pass++)	{		Effect->BeginPass(Pass);		for (DWORD i=0; i<Model.numMaterials; i++)		{			Effect->SetTexture("xTexture", meshTextures);			Effect->CommitChanges();			DXOutDevice->SetMaterial(&(Model.meshMaterials));			Model.Mesh->DrawSubset(i);		}		Effect->EndPass();	}	Effect->End();}

I see only black screen
What is the problem?
Advertisement
I am not into direct x anymore, but it appears to me that you are setting a projection matrix, and that is rather distinct from a model view or world matrices. Look into your reference about how to set the latter two.

sidenote: Your thread title mentions scaling, but your code is about translation.
You can troubleshoot it yourself. Try incrementing the translation to see what happens onscreen.

I.e., instead of a translation of (1,1,1), start with something very small such as (0.05f, 0.05f, 0.05f) and see if that works. Then change it to (0.1f, 0.1f, 0.1f), etc., until you understand what's happening.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Thank a lot for answers. I start with small translation and it is works fine.
your matrix composition is a little bit weird

you do

Effect->SetMatrix("xWorldViewProjection", &(matView * matProj * mTranslation));


but what you most probably want is this

Effect->SetMatrix("xWorldViewProjection", &(mTranslation * matView * matProj));


so you need to do world translation _before_ view transformation - this is why it is called world-view-projection. First do world transform, then view transform then projection.
Thanks for the help. Where can I read about why it is multiplied in order world, view, projection?
Quote:Where can I read about why it is multiplied in order world, view, projection?

For one, Frank Luna's book, Introduction to 3D Game Programming With DirectX 9.0c, Chapter 6.

If you're looking for an explanation, here's another one:

There are two aspects to your question:

1. The order of the matrix multiplication.

2. Why world-then view-then projection.

The order in which matrices are multiplied determines the order in which the transformations are applied to the vertices. For a row-major matrix system like DirectX, the first matrix in order is applied first, then the second, etc. For column-major matrix systems, the last is applied first, then second-to-last, etc. That's how matrix multiplication works. If that's not your question, then ignore this.

The world is applied first to move your vertices from model space to world space. The view matrix is applied second to orient the vertices with respect to the eye (or camera) position which is in the "center of the view." The projection matrix is then applied to locate the vertices within the projection frustum.

Is that any help?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement