SetTransform doesn't work?
hi,everyone!
i load 2 meshes and render them,there's no problem
but i want to scale them by setting up 2 scale matrix and calling SetTransform before drawsubset,but it doesn't work!they look excactly the same as not using SetTransform
D3DXMatrixScaling(&g_matWorld,0.5,0.5,0.5);
g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld);
g_pMesh1->DrawSubset(0);
D3DXMatrixScaling(&g_matWorld,2.0,2.0,2.0);
g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld);
g_pMesh2->DrawSubset(0);
is there somthing wrong with the code above?what should i do to transform before rendering?
thanks!
No this code should work as far as I can tell. Note, though, that you render two meshes at the same position (origin) -- is this the intent? Otherwise post some more code and information about what you want to do.
Greetz,
Illco
Greetz,
Illco
The code seems ok also to me.
Does also the use of a translation instead of a scaling fail? If so, perhaps the problem is at a very different location. Maybe absurd, but possibly the mesh uses another device than those the matrix is set of?
Does also the use of a translation instead of a scaling fail? If so, perhaps the problem is at a very different location. Maybe absurd, but possibly the mesh uses another device than those the matrix is set of?
Hmm, strange, this code should work. Maybe the bug is somewhere else in your code :) Could you probably post the whole rendering routine(render states..etc)? Are you using FFP?
i use only one device,and i am using Fix Functino Pipeline
when load mesh,i use D3DXLoadMeshFromX,where the 3rd parameter is specified "g_pd3dDevice",same to what i used to SetTransform or SetRenderState
the render states:
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE,TRUE)
before drawsubset:
g_pd3dDevice->SetMaterial(&pMeshMaterial)
g_pd3dDevice->SetTexture(&pMeshTexture)
D3DXMatrixScaling(&g_matWorld,0.2f,0.2f,0.2f)
g_pd3dDevice->SetTransform(D3DTS_WORLD,&g_matWorld)
when load mesh,i use D3DXLoadMeshFromX,where the 3rd parameter is specified "g_pd3dDevice",same to what i used to SetTransform or SetRenderState
the render states:
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE,TRUE)
before drawsubset:
g_pd3dDevice->SetMaterial(&pMeshMaterial)
g_pd3dDevice->SetTexture(&pMeshTexture)
D3DXMatrixScaling(&g_matWorld,0.2f,0.2f,0.2f)
g_pd3dDevice->SetTransform(D3DTS_WORLD,&g_matWorld)
i accually wrote my programe in asm
the code above is what they should look like when writting in C++
the code above is what they should look like when writting in C++
Now that is some important information I guess. The C++ code seems fine. How do you ensure the ASM code says the same? There is probably a mismatch somewhere.
Now I don't know much ASM but could it be that if you mismatch parameters to functions this influences the following calls? Because SetTexture() takes two parameters instead of one AND the second parameter should be a single pointer and not a double one.
Illco
Now I don't know much ASM but could it be that if you mismatch parameters to functions this influences the following calls? Because SetTexture() takes two parameters instead of one AND the second parameter should be a single pointer and not a double one.
Illco
my code works when rendring two meshes
SetTexture does take 2 parameters,sorry i missed one when i posted my code
the SetTransform is used elsewhere in my programe,such as when setting the view and projection matrix,it works.i don't know why it doesn't when i do the world transformation
SetTexture does take 2 parameters,sorry i missed one when i posted my code
the SetTransform is used elsewhere in my programe,such as when setting the view and projection matrix,it works.i don't know why it doesn't when i do the world transformation
sorry i didn't post my code clearly,this problem can not be solved by guessing
here is my code:
the matWorld is the address of matrix previously setup for transformation
the 2 meshed could be rendered correctly,but no transformation happend
[Edited by - Muhammad Haggag on November 27, 2005 7:55:18 AM]
here is my code:
DrawMesh macro pMesh,pMeshMaterial,pMeshTexture,dwNumMaterial,matWorld; Meshes are divided into subsets, one for each material. Render them in; a loop mov edi, pMeshMaterial mov esi, pMeshTexture mov ebx, 0 .while ebx<dwNumMaterial mov eax,g_pd3dDevice mov eax,[eax] push edi push g_pd3dDevice call dword ptr [eax+IDirect3DDevice9_SetMaterial] mov eax,g_pd3dDevice mov eax,[eax] push [esi] push 0 push g_pd3dDevice call dword ptr [eax+IDirect3DDevice9_SetTexture] ;transform mov eax,g_pd3dDevice mov eax,[eax] push matWorld push D3DTS_WORLD push g_pd3dDevice call dword ptr [eax+IDirect3DDevice9_SetTransform] ;Draw the mesh subset mov eax,pMesh mov eax,[eax] push ebx push pMesh call dword ptr [eax+ID3DXBaseMesh_DrawSubset] add esi, 4 add edi, sizeof D3DMATERIAL9 inc ebx .endwendm
the matWorld is the address of matrix previously setup for transformation
Render macro ;Clear the backbuffer mov eax, g_pd3dDevice mov eax,[eax] push 0 push fpt1 ;have to use float number push 000000ffh push D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER push NULL push 0 push g_pd3dDevice call dword ptr [eax+IDirect3DDevice9_Clear] ;Begin the scene. mov eax,g_pd3dDevice mov eax,[eax] push g_pd3dDevice call dword ptr [eax+IDirect3DDevice9_BeginScene] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; The Render part ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; invoke D3DXMatrixScaling,addr g_matWorld,fpt05,fpt05,fpt05 DrawMesh g_pFighter,g_pFighterMaterials,g_pFighterTextures,g_dwFighterNum,offset g_matWorld invoke D3DXMatrixScaling,addr g_matWorld,fpt2,fpt2,fpt2 DrawMesh g_pTerrain,g_pTerrainMaterials,g_pTerrainTextures,g_dwTerrainNum,offset g_matWorld DrawFPS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;End the scene. mov eax,g_pd3dDevice mov eax,[eax] push g_pd3dDevice call dword ptr [eax+IDirect3DDevice9_EndScene] ;Present the backbuffer contents to the display. mov eax,g_pd3dDevice mov eax,[eax] push NULL push NULL push NULL push NULL push g_pd3dDevice call dword ptr [eax+IDirect3DDevice9_Present]endm
the 2 meshed could be rendered correctly,but no transformation happend
[Edited by - Muhammad Haggag on November 27, 2005 7:55:18 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement