D3DTS_WORLD transform not working..

Started by
4 comments, last by Nik02 16 years, 9 months ago
void mesh::RenderMesh(ID3DXEffect* mFX)
{
	D3DXHANDLE   mWhiteTex;
	D3DXHANDLE   mhTex;
	D3DXHANDLE   mhMtrl;

	D3DXMATRIX pos;
	D3DXMatrixTranslation(&pos, 78, 50, 69);
	dev->SetTransform(D3DTS_WORLD, &pos);
	

	for(UINT j = 0; j < mSceneMtrls.size(); ++j)
	{
		HR(mFX->SetValue(mhMtrl, &mSceneMtrls[j], sizeof(Mtrl)));
	
		// If there is a texture, then use.
		if(mSceneTextures[j] != 0)
		{
			HR(mFX->SetTexture(mhTex, mSceneTextures[j]));
		}

		// But if not, then set a pure white texture.  When the texture color
		// is multiplied by the color from lighting, it is like multiplying by
		// 1 and won't change the color from lighting.
		else
		{
			HR(mFX->SetTexture(mhTex, mSceneTextures[j]));
		}
	
		//HR(mFX->SetTexture(mhNormalMap, mSceneNormalMaps[j]));

		HR(mFX->CommitChanges());
		dev->SetTransform(D3DTS_WORLD, &pos);
		HR(model->DrawSubset(j));
	}
}
basically I want the model to render at pos, though no matter what pos is set to the transform isn't working, it's always placed at the origin for some reason.
Advertisement
Are you calling

dev->SetTransform(D3DTS_WORLD, &pos);

Twice on purpose or is that a mistake?
Quote:Original post by Kiryn
Are you calling

dev->SetTransform(D3DTS_WORLD, &pos);

Twice on purpose or is that a mistake?


well I don't think it matters, though I've tried calling it once inside the loop, once outside the loop and inside and outside the loop. If it doesn't work once it isn't going to work any other way but it's wortha shot regardless :P
Does your effect/technique use a vertex shader? The fixed-function transforms (Dev::SetTransform()) and lighting are disabled if a vertex shader is enabled.

Niko Suni

Quote:Original post by Nik02
Does your effect/technique use a vertex shader? The fixed-function transforms (Dev::SetTransform()) and lighting are disabled if a vertex shader is enabled.


oh ok, I see.

Yes it is, I'm still new to shaders so it was a pretty obvious mistake.

I just went through the DX sdk and it looks like I should use something along the lines of mFX->SetMatrix(), if I don't get this to work I'll come back though I have a strong hunch it's what I'm supposed to use.
Effect::SetMatrix is a good choice here. In your vertex shader function, you can use that matrix to transform the geometry.

Do note that you have to communicate your view and projection transforms to the shader too, in order to achieve similar results to the fixed pipeline.

Niko Suni

This topic is closed to new replies.

Advertisement