Sign in to follow this  
jerrykeating

SetTransform doesn't work?

Recommended Posts

jerrykeating    122
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!

Share this post


Link to post
Share on other sites
Illco    928
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

Share this post


Link to post
Share on other sites
haegarr    7372
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?

Share this post


Link to post
Share on other sites
MePHyst0    232
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?

Share this post


Link to post
Share on other sites
jerrykeating    122
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)

Share this post


Link to post
Share on other sites
Illco    928
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

Share this post


Link to post
Share on other sites
jerrykeating    122
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

Share this post


Link to post
Share on other sites
jerrykeating    122
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
.endw
endm


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]

Share this post


Link to post
Share on other sites
Illco    928
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.

Share this post


Link to post
Share on other sites
jerrykeating    122
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this