Sign in to follow this  

Sprite Matrix

This topic is 4109 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
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

This topic is 4109 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this