Jump to content
  • Advertisement
Sign in to follow this  
sansured

Sprite Matrix

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!