Jump to content
  • Advertisement
Sign in to follow this  
ArchangelMorph

Quick ID3DXSPRITE question..

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

I'm new to the interface and want to use it for my new engine.. I'm trying to understand how it works properly before diving in and trying to implement it which would probably cause problems for me if I didn't do it properly.. I'm trying to understand two things: 1) when you call SetTransform and send a matrix with a specified translation for example, does it translate the co-ordinates of the sprite in screen space? 2) if so, then what format would I have to use to setup a decent matrix to move a sprite around the screen in x, y co-ordinates? Hope you can help.. :) UPDATE: This problem was solved but I seem to have a new problem detailed below.. [Edited by - ArchangelMorph on July 12, 2006 7:44:37 AM]

Share this post


Link to post
Share on other sites
Advertisement
The matrix provided to ID3DXSprite::SetTransform will affect the world transformation.

In a 2D system you could do something like this...

D3DXMATRIX matWorld, matScale, matRot, matTrans;
D3DXMatrixRotation( &matRot, fSpriteOrientationInRadians );
D3DXMatrixTranslation( &matTrans, fSpriteXLoc, fSpriteYLoc, 0.0f ); //2d, no Z
D3DXMatrixScaling( &matScale, fSpriteWidth, fSpriteHeight, 1.0f );

//the total world transformation would then be
matWorld = matScale * matRot * matTrans

pSprite->SetTransform( &matWorld );

As far as where that will appear on the screen, that all depends on the world volume set in the Projection transformation.

Hope that's what you were looking for.

Share this post


Link to post
Share on other sites
This would work but wouldn't it cause problems for me when lets say, the camera moves its position to view the world from a different position/orientation?

What I really wanna do is use the ID3DXSPRITE interface to draw HUD and GUI elements on screen and using the screen co-ordinate frame..

How best would I achieve this goal and is the use of the ID3DXSPRITE interface the best solution for the problem?

Share this post


Link to post
Share on other sites
Unless you specify the D3DSPRITE_OBJECTSPACE flag specificly, anything drawn with ID3DXSprite will not be affected by the Projection, View, or World matrices. If this flag isn't specified, anything drawn is in Screen Space and coordinates are in Pixels.

Also, if you're drawing sprites and don't require rotation and scaling, which I don't think would be needed for most of the HUD, you don't need to call SetTranform at all. Just call Draw as many times as you need in order to complete your HUD, giving it the coordinates where you want it drawn.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
Unless you specify the D3DSPRITE_OBJECTSPACE flag specificly, anything drawn with ID3DXSprite will not be affected by the Projection, View, or World matrices. If this flag isn't specified, anything drawn is in Screen Space and coordinates are in Pixels.

Also, if you're drawing sprites and don't require rotation and scaling, which I don't think would be needed for most of the HUD, you don't need to call SetTranform at all. Just call Draw as many times as you need in order to complete your HUD, giving it the coordinates where you want it drawn.

Hope this helps.



This is exactly right, just use a D3DXVector3 that has the position of the Sprite and call Draw, you don't need to transform anything.

Share this post


Link to post
Share on other sites
OK

I've got in my hands another funny problem..

I'm using ID3DXSPRITE and when I tried to call the Draw function it wouldn't compile telling me the function doesn't take 5 parameters..

I checked both the SDK docs, msdn.com and a few tutorials online and they all seem to be consistent with the belief that the function DOES take only 5 parameters..

Anyways when I checked the definition of the function in visual studio 6.0 it seems to take 7..

I'm using the october 2005 version of dx 9 btw..

So why is it the case that the function was changed without the documentation being updated??

[Edited by - ArchangelMorph on July 12, 2006 7:54:25 AM]

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!