Hi all,
I'm writing a 2D, top-down game. I'm using ID3DXSprite to draw sprites, but instead of using screen coordinates, I'm using a 3D camera in "object space." I think this will be more useful in the long run, but I'm struggling to get the camera set up correctly: right now, my test texture is mirrored vertically.
Here's a picture:
Orientation problem
And here's the camera set-up/drawing code. mSprite is my ID3DXSprite*, and gDevice is the IDirect3DDevice9*.
D3DXMATRIX V;
D3DXVECTOR3 pos(0.0f, 0.0f, -500.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXMatrixLookAtLH(&V, &pos, &target, &up);
gDevice->SetTransform(D3DTS_VIEW, &V);
D3DXMATRIX P;
float width = (float)mClientWidth;
float height = (float)mClientHeight;
D3DXMatrixPerspectiveFovLH(&P,
D3DX_PI * 0.25f,
width/height,
1.0f,
5000.0f);
gDevice->SetTransform(D3DTS_PROJECTION, &P);
// Clear the back and depth buffers, and send the start signals.
gDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 0, 255), 1.0f, 0);
gDevice->BeginScene();
mSprite->Begin(D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_DONOTMODIFY_RENDERSTATE);
gDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true);
mSprite->Draw(mTex, 0, 0, 0, D3DCOLOR_XRGB(255, 255, 255));
// End the scene.
gDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false);
mSprite->End();
gDevice->EndScene();
// Present the back buffer.
gDevice->Present(0, 0, 0, 0);
Is there something wrong with the way I'm setting up the camera?