Re: ID3DXSprite not stretching correctly.
From: Jack Hoxley (Jack.Hoxley_at_ntlworld.com)
Date: 08/31/04
- Next message: oleg_babyak_at_yahoo.com: "Offscreen rendering with antialiasing"
- Previous message: Jack Hoxley: "Re: Tearing problem in Windowed Mode - Continued...."
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 31 Aug 2004 12:08:49 +0100
I think you might need to look up the general form of a scaling matrix... In
order for it to work correctly as you want you'll need the center of the
sprite to actually be the center of the sprite (seems obvious, but I dont
think thats what you're doing).
For a general scaling transform, you need to translate by -center, scale
then translate by +center (iirc), as the sprite should be around the origin
when scaling occurs. I presume this is what ID3DXSprite does if you give it
the center point.
If the rest of your sprites are messing up when you specify a center point,
then it may well be an indication that other bits of your code are also
incorrect...
hth
Jack
"L. Spiro" <LSpiro@discussions.microsoft.com> wrote in message
news:2E74704B-0A09-4DC9-8212-4BF2D5735AE3@microsoft.com...
> Here is my code:
>
> D3DXMATRIX matTrans;
> D3DXMatrixIdentity( &matTrans );
> D3DXMatrixScaling( &matTrans, XScale, YScale, 1.0f );
> m_pSprite->SetTransform( &matTrans );
>
> m_pSprite->Begin( D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE );
> if ( FAILED( m_pSprite->Draw( m_Texture,
> &Rect, NULL,
> &D3DXVECTOR3( (float)DestX, (float)DestY, 1.0f ),
> Color ) ) ) {
> return FALSE;
> }
> m_pSprite->End();
>
>
> When XScale and YScale are 1.0f, the sprite draws correctly.
> When scaled either way, the sprite is not actually scaled, but instead
just
> moved some number of pixels in the scaled direction, or something? I can
not
> quite tell yet how it decide to place it on the screen when I scale it.
This
> all worked before DirectX® 9.0c so I know the numbers WERE correct.
>
> I installed a breakpoint to show me what the numbers are when XScale is
not
> 1.0f.
>
> Here are ALL the related values:
> XScale: 63.0f
> YScale: 1.0f
>
> Rect.left: 8
> Rect.top: 208
> Rect.right: 16
> Rect.bottom: 216
>
> DestX: 8
> DestY: 0
>
> The Width and Height of the texture from which I am drawing is 256×256.
> The Width and Height of the actual area I am drawing FROM the texture is
> 8×8, starting at (8, 208) (hence the Rect structure).
>
>
> The desired result is an 8×8 sprite that is stretched from (8, 0) to (504,
0).
>
> I have a feeling this has to do with passing NULL as the center of the
> sprite, but any time I change it at all all the rest of the sprites start
> landing in random spots on the screen and the image is still never
stretched
> correctly (though at least sometimes it is stretched somewhat).
>
> What is the actual relationship of the center of the drawing to everything
> else?
> How do I know how to calculate what the center should be for the results I
> want?
> What does the "center of the sprite" actually DO to the transforms?
- Next message: oleg_babyak_at_yahoo.com: "Offscreen rendering with antialiasing"
- Previous message: Jack Hoxley: "Re: Tearing problem in Windowed Mode - Continued...."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|