2D Transformations in 3D
I want to write a 2D game in Direct3D 8. I''m having a problem understanding how to make the transformations in 3D. I know that I setup my perspective as Orthogonal to do 2D games in 3D. But when I transformed with DirectDraw it was like:
if(object.x < 640)
{
object.x+=vel * fTimeDelta;
}
if(object.y < 480)
{
object.y+=vely * fTimeDelta;
}
How do I do the same types of transformations using a D3DXMATRIX with DirectGraphics 8?
Thanks!
knine
Look at the docs for D3DXMatrixTranslation
Build a translation matrix, pass it to the device, and render.
Also, check out the "Tutorial" samples in the SDK. There is one that handles VERy basic matrix stuff.
Build a translation matrix, pass it to the device, and render.
Also, check out the "Tutorial" samples in the SDK. There is one that handles VERy basic matrix stuff.
Okay. I''m setting things up like so:
and when I do my transformation to move the sprite I do so like this:
does that look right? It seems to be running okay, except for the fact that I can''t see my sprite.
Thanks in advance for your help!
knine
D3DXMATRIX matOrtho2D;D3DXMATRIX matIdentity;D3DXMatrixOrthoLH(&matOrtho2D, 640.0f, 480.0f, 0.0, 1.0);D3DXMatrixIdentity(&matIdentity);m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matOrtho2D);m_pd3dDevice->SetTransform(D3DTS_WORLD, &matIdentity);m_pd3dDevice->SetTransform(D3DTS_VIEW, &matIdentity);
and when I do my transformation to move the sprite I do so like this:
D3DXMATRIX matPosition; D3DXMatrixTranslation(&matPosition, m_vPos.x, m_vPos.y, 0.0f);m_pd3dDevice->SetTransform(D3DTS_WORLD, &matPosition);
does that look right? It seems to be running okay, except for the fact that I can''t see my sprite.
Thanks in advance for your help!
knine
You could also use pre-transformed and lit vertices,
Then just define the x,y in screen space (0,0 is top left), set z to 1, and rhw to 1. (between 0 and 1 for depth if you are going to use a zbuffer )
Of course you''ll have to manage the sprite and modify its x,y''s when it moves.
/////////////////////////////////////////// sprite vert structure#define D3DFVF_SPRITEVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)struct SPRITE_VERTEX{ f32 x, y, z, rhw; // The transformed position for the vertex. u32 ARGB; // The vertex color. f32 tu, tv; // tex coords};/////////////////////////////////////////
Then just define the x,y in screen space (0,0 is top left), set z to 1, and rhw to 1. (between 0 and 1 for depth if you are going to use a zbuffer )
Of course you''ll have to manage the sprite and modify its x,y''s when it moves.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement