Sign in to follow this  
echoredriot

DX9 SetTransform() Matrix bug?

Recommended Posts

echoredriot    122
I'm curious if anyone else has had an experience where SetTransform() simply stops functioning for View, Projection, and Transform matrix changes. The odd part is, Set Transform works perfectly fine in most of my programs, however it seems to have effectively 'disabled' itself in another one of my programs, even if it's the exact code copy and pasted. It doesn't throw an error, it just doesn't function: Take this code for example, the only difference between two programs I have is that one is split up more effeciently between header & CPP files, compiles fine, however it draws the triangles with no transformations applied (2 triangles overlapping) and the default projection and view matrixes. D3DXMATRIX matRotateY; // a matrix to store the rotation information static float index = 15.5f; index+=0.05f; // an ever-increasing float value D3DXMatrixRotationY(&matRotateY, index); d3ddev->SetTransform(D3DTS_WORLD, &matRotateY); d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); D3DXMATRIX matTransA; D3DXMatrixTranslation(&matTransA, 50.0f, 50.0f, 0.0f); d3ddev->SetTransform(D3DTS_WORLD, &matTransA); d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); I've been researching the problem for 2 days and there seems to be no documentation on what could cause set transformations to stop working outside of custom vertex shaders which i'm not using. Has anyone experienced a similar problem? DX9 C++ Microsoft Visual Studios. I have beginner level experience, Have made Pong, Space invaders ect using X files, however going back to CustomVertex style drawing It's wierd that SetTransform no longer works.

Share this post


Link to post
Share on other sites
Peter5897    212
My gut reaction is that something else is wrong. You can pretty much guarantee that SetTranform is going to work as advertised.

Are you sure the code is being called and in the order you expect it to? I know it's a simple thing but I'm guessing that it's going to be where your problem lies.

My suggestion would be to post more code (Note: use source tags) to get more specific help, and while you wait for the help try stepping through all your code as it runs. Line by line.

Share this post


Link to post
Share on other sites
superpig    1825
Using pretransformed vertices (D3DFVF_XYZRHW) would also cause transformations to stop working.

Anyway, I'd recommend (A) using the Direct3D debug runtime to check for error output, and (B) taking a PIX capture to examine how the device is actually behaving.

Share this post


Link to post
Share on other sites
echoredriot    122
Thank you, I'll look into these things.

I do use custom vertex:
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

And in other programs I've seen been able to use SetTransform() after applying
Matrix calculations, but somethign just seems fishy.

Thanks for the help!

Share this post


Link to post
Share on other sites
jpetrie    13103
You use D3DFVF_XYZRHW, which indicates that the vertices are pretransformed. The world/view/projection matrix is not used to transform them. So, yes, the behavior you're seeing is in fact correct and expected.

Share this post


Link to post
Share on other sites
echoredriot    122
Ah, and thus the reason for the rabbit hole, time to start a new story me'thinks.
Sounds good, I'll look into alternative custom vertex formats for drawing and transformations.

Share this post


Link to post
Share on other sites
echoredriot    122
Conclusion, would like to describe my fix, what caused it, and problems for anyone else that comes down these steps:

Was using a custom vertex format: #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
which is for screen coord 2D already transformed coords. In other words they don't go down the 3d pipeline, and thus are not affected by matrix transformations. If you plan on doing custom vertex with transformations you need to use [b]CUSTOM FVF (D3DFVF_XYZ) which denotes pre transformation. Another mistake I made after fixing this is to make sure your camera can see what you're really drawing, so double check that once you're done.

The difference between D3DFVFRHW and D3DFVF is simply that RHW is drawing directly to the screen, in 2D, with no 3d calculations done.

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