Skip to main content
gamedev.net
🔒 Locked

Sprite Matrix

Started by sansured Sep 13, 2006 at 6:13 PM 3 replies 1.4k views
Original Post
sansured
sansured
Hi, I have a problem about 2D sprite's. I am using CFirstPersonCamera class for fps camera in directx 9. I am setting the matrix of 3d mesh's like the code below.

 mWorld = *g_Camera.GetWorldMatrix();
 mProj = *g_Camera.GetProjMatrix();
 mView = *g_Camera.GetViewMatrix();

 mWorldViewProjection = g_mCenterWorld * mView * mProj;

But it's not working for 2D sprites. After rendering mesh's i am rendering sprites with the code below.

    RECT srcRect;
    srcRect.top    = (( nFrame / 5 ) * 64);
    srcRect.left   = (( nFrame % 5 ) * 64);
    srcRect.bottom = srcRect.top  + 64;
    srcRect.right  = srcRect.left + 64;

// LPD3DXSPRITE object g_pDonutSprite 
g_pDonutSprite->Begin( D3DXSPRITE_ALPHABLEND );

D3DXMatrixTranslation( &m_SpriteCenter, vPosition.x, vPosition.y, vPosition.z );

mWorldViewProjection = m_SpriteCenter * mView * mProj;


g_pDonutSprite->SetTransform(&mWorldViewProjection);

g_pDonutSprite->Draw( g_pDonutTexture, &srcRect, &vCenter, &vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );

g_pDonutSprite->End();

But Sprite is follows my camera and rotating with it.I can't set it to a static position.Does anyone has any idea about it. Thanks.
Toolmaker
Toolmaker
I believe the D3DXSprite interface uses an Ortho view, which means that the position of the sprite is relative to the screen, and not world space.

You should be able to solve this by using Textured Quads(Dump 2 triangles together, texture it and voila, you got a sprite that's sitting on a static posistion in the world).

Toolmaker
 
sirob
sirob
You should be using the D3D_SPRITE_OBJECTSPACE and D3D_SPRITE_BILLBOARD flags.
Also, when using those, you'll need to call ID3DXSprite::SetWorldViewLH().

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
sansured
sansured
Thanks for your advices but i still couldn't work it properly.

D3DXMATRIXA16    m_matBillboardMatrix;D3DXMatrixTranslation( &m_matBillboardMatrix, 2.0f, 0.0f, 0.0f );mWorldViewProjection = m_matBillboardMatrix * mView * mProj;g_pDonutSprite->Begin( D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_BILLBOARD | D3DXSPRITE_ALPHABLEND );g_pDonutSprite->SetWorldViewLH(&mWorld, &mWorldViewProjection);// The rest of the code is same

Can you see the mistake in the code.When i set D3DXSPRITE_OBJECTSPACE the spirite disappears.
streamer
streamer
Quote:
Original post by sansured
Thanks for your advices but i still couldn't work it properly.

*** Source Snippet Removed ***
Can you see the mistake in the code.When i set D3DXSPRITE_OBJECTSPACE the spirite disappears.


Setting D3DXSPRITE_OBJECTSPACE will tell DX that sprite is positioned and transformed in 3D space and not in 2D screen space.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.