Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

SetTransform doesn't work?

Started by jerrykeating Nov 27, 2005 at 2:48 AM 12 replies 2.2k views
Original Post
jerrykeating
jerrykeating
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!
Illco
Illco
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
jerrykeating
jerrykeating
yes,they are rendered at the origin position
i just want to scale them
haegarr
haegarr
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?
MePHyst0
MePHyst0
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?
jerrykeating
jerrykeating
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)
jerrykeating
jerrykeating
i accually wrote my programe in asm
the code above is what they should look like when writting in C++
Illco
Illco
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
jerrykeating
jerrykeating
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
jerrykeating
jerrykeating
sorry i didn't post my code clearly,this problem can not be solved by guessing
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]
Illco
Illco
Sorry, I can't help you as my knowledge of ASM is too little. The only thing I can think of is that some calls might overwrite registers you use later -- you enter the material and texture pointers first and then make some calls for example. Perhaps they are screwed up in the meantime? But then again, I guess you'd know better than I do.

Good luck. Illco.
jerrykeating
jerrykeating
i haven't figured out what's going on with my transformation
but thank you guys,i'll keep trying!
kovacsp
kovacsp
Hi,

could you please show us your g_matWorld?

kp
------------------------------------------------------------Neo, the Matrix should be 16-byte aligned for better performance!
jerrykeating
jerrykeating
thanks for asking!
this problem has been solved,i made a silly mistake
because i use asm,i have to do the head files myself,the mistake was there
i defined D3DTS_WORLD to a wrong value,that's why the world transfrom doesn't work,the way to do the transformation is right
thanks again!

Topic Locked

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

Sign in to reply to this topic.