Quick ID3DXSPRITE question..

Started by
5 comments, last by ArchangelMorph 17 years, 9 months ago
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]
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.
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?
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.
Sirob Yes.» - status: Work-O-Rama.
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.
Adamhttp://www.allgamedevelopment.com
Ya'll are the best!!

Thnx soo much!!
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]

This topic is closed to new replies.

Advertisement