Skip to main content
gamedev.net
🔒 Locked

Multiply function!

Started by snoddas14 3 replies 600+ views
Original Post
snoddas14
snoddas14
hey! i want to do this mesh load and it goes realy smooth but when it comes to the Multiply funcktion, and i want to use more than one mesh in my Game! i have tryed

D3DXMatrixTranslate(&Translate, x, y ,z);
D3DXMatrixMultiply(&Final, &Final, &Translate);
pd3dDevice->SetTransform(D3DTS_WORLD, &Final);

this code dosent work. so i did this insted.

pd3dDevice->SetTransform(D3DTS_WORLD, &(Translate * Final));

nope dident work either. so irealy hope for Answer!
Programmer101
Programmer101
D3DXMatrixMultiply Should always work. No exceptions. I don't think that multiplying them with the common "*" would work because its a class not an array.

However because you are multiplying "Final" with "Translate" it probably has not been cleared and therefore retains old values which could mess you up.

To clear it use:
D3DXMatrixIdentity(&Final);

Also, if you are only using one type of transformation matrix (translation, rotation, or scaling) you will not need a final matrix and you could use "Translate" as your world matrix rather than wasting computation time on multiplying unnecessary matrices.
snoddas14
snoddas14
nope i still dosent work, may i would help if i send you the code i use so you understand what i have done.

now i did your way!

//The Classvoid LoadObj::GetMesh(const char* filename){	D3DXLoadMeshFromX(filename, D3DXMESH_SYSTEMMEM, pd3dDevice,  NULL, &BuffMat, NULL, &NumMaterial, &ppMesh);	D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)BuffMat->GetBufferPointer();	BuffMaterial = new D3DMATERIAL9[NumMaterial];	BuffTexture = new LPDIRECT3DTEXTURE9[NumMaterial];	for(DWORD i = 0; i < NumMaterial; i++)	{		BuffMaterial = tempMaterials.MatD3D;		BuffMaterial.Ambient = BuffMaterial.Diffuse;		USES_CONVERSION;		if(FAILED(D3DXCreateTextureFromFile(pd3dDevice,			(tempMaterials.pTextureFilename), &BuffTexture)))        BuffTexture = NULL; 	}}void LoadObj::MoveMesh(float x, float y, float z){	for(DWORD i=0; i < NumMaterial; i++)	{			D3DXMatrixTranslation(&Translate, x, y, z);		D3DXMatrixRotationY(&Rotate, D3DXToRadian(180.0f));		D3DXMatrixIdentity(&Final);		pd3dDevice->SetTransform(D3DTS_WORLD, &Final);		pd3dDevice->SetMaterial(&BuffMaterial);        pd3dDevice->SetTexture(0, BuffTexture);		ppMesh->DrawSubset(i);	}}//the WinMainLoadObj *PalmTree = new LoadObj();LoadObj *PalmTree1 = new LoadObj();//the Rendering			PalmTree1->GetMesh("Palm.X");			PalmTree->GetMesh("Palm.X");			Render->FrameStart();						PalmTree->MoveMesh(0.0f,0.0f,0.0f);			PalmTree1->MoveMesh(10.0f,0.0f,0.0f);			Player->CreatCamera(1.0f,500.0f,0.0f,0.0f,30.0f,0.0f,0.0f,0.0f);			Render->FrameStop();


and thats how i have set it up! and i realy need help whit this!
becus if i solve it im allmost done whit my Game
jollyjeffers
jollyjeffers
Might be advisable to step back and learn the basics of matrix maths [smile]

Your code fragment:
D3DXMatrixTranslation(&Translate, x, y, z);D3DXMatrixRotationY(&Rotate, D3DXToRadian(180.0f));D3DXMatrixIdentity(&Final);pd3dDevice->SetTransform(D3DTS_WORLD, &Final);


Should look like this (off the top of my head):

D3DXMATRIX mTemp;D3DXMATRIX mFinal;D3DXMatrixIdentity( &mFinal );D3DXMatrixTranslation( &mTemp, x, y, z );D3DXMatrixMultiply( &mFinal, &mFinal, &mTemp );D3DXMatrixRotationY( &mTemp, D3DXToRadian( 180.0f ) );D3DXMatrixMultiply( &mFinal, &mFinal, &mTemp );pd3dDevice->SetTransform( D3DTS_WORLD, &mFinal );


hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
snoddas14
snoddas14
Thanks man! freaking love you from now on! (L)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.