View Matrix for Dx9 Sprites

This topic is 1425 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

So I have some sprites, and I just want to move the camera,and leave the sprite's positions unchanged.

I created a matrix like:

D3DXMATRIX m;
D3DXMatrixLookAtLH(&m, &D3DXVECTOR3(-150, 0, 0), &D3DXVECTOR3(-150, 0, 0), &D3DXVECTOR3(0, 1, 0));

And set it as the view matrix for dx(nothing happened). Then I set it as the view matrix for the sprite's component(nothing happened),i tried setting it up for both,and still,nothing happened.

I did try other values but apparently the camera just won't move. What am I doing wrong?

Share on other sites

How do you render the sprites? With the LPD3DXSPRITE-interface, or with vertex buffers, shaders, etc... ? In the latter case, one possibility that comes to mind is that in your vertex declaration you set position to D3DDECLUSAGE_POSITIONT (mind the T, it doesn't appear bold here even though I marked it so to draw attention to it), which means sprites are pre-transformed and the vertex shader is skipped. I'm just quessing and can't tell much without more information (like what I asked before, possibly some code/shader code would be nice to), but this is something that happend to me once and left me wondering why my vertex shader transforms had no effect on sprites too.

Edited by Juliean

Share on other sites

I'm using the D3DXSPRITE interface

Share on other sites

I'm using the D3DXSPRITE interface

Can you then show the code where you set the view-matrix to the sprite-interface?

Share on other sites
        D3DXMATRIX m;
D3DXMatrixLookAtLH(&m, &D3DXVECTOR3(-150, 50, 0), &D3DXVECTOR3(-149, 50, 0), &D3DXVECTOR3(0, 1, 0));
D3DXMATRIX w;
D3DXMatrixIdentity(&w);

ppSprite->SetWorldViewLH(&w, &m);

Direct3DManager::getInstance()->d3d_Device->BeginScene();

// drawing the sprite begins here


There it is

Share on other sites

I never really used the SetWorldViewLH-method, what happens if you use the SetTransform-method with only the view-matrix instead? Or, if all you want to do is simulate a movement of the sprites due to camera, you could eigther try SetTransform with just a D3DXMatrixTranslation with negative camera position, or use this as world matrix for SetWorldViewLH. Does any of the above work, or at least result in a change of appearance in some way or form?

As a small side-note, you can just pass nullptr as the first parameter for the world matrix if it is identity in SetWorldViewLH.

Edited by Juliean

Share on other sites

If I just use SetTransform(with the sprite's method), the sprite completely goes away(which it shouldn't cause it's texture is between -250 and 250).

And just using translation would make things a little bit more complicated since i have to export the positions of the sprites.

Share on other sites

If I just use SetTransform(with the sprite's method), the sprite completely goes away(which it shouldn't cause it's texture is between -250 and 250).

Does it also go away if you set the camera position to something smaller (like -25 or so)? probably -150/50 has a bigger effect than expected.

And just using translation would make things a little bit more complicated since i have to export the positions of the sprites.

Whether you use LookAt or Translation doesn't make any difference, both create a matrix, that matrix is multiplied with the sprites vertex positions, so it doesn't matter, if a Translation-matrix works, you can use that ;)

Edited by Juliean