Re: ID3DXSprite not stretching correctly.

From: Jack Hoxley (Jack.Hoxley_at_ntlworld.com)
Date: 08/31/04


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?



Relevant Pages

  • Re: draw2d + rotate
    ... I can't find a way to rotate around a different center either. ... the Transform property to set a scaling and rotation matrix. ... rotates four sprites around the center of the screen with oscillating sprite ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: SNES to Genesis games
    ... It looks like true scaling since the sprite gets real pixelated as it ... flies torward the screen. ... It's just not smooth scaling, ...
    (rec.games.video.sega)
  • Re: I need advices to make a game with delphi 7.
    ... > around with the mouse (sprite: movable element of the picture, ... > message queue, instead a new message replaces the last one still in the ... If your drawing is too slow the movement will not be smooth since ... > to redraw on every point of the mouse trajectory. ...
    (borland.public.delphi.language.objectpascal)
  • Re: Multplexing sprites
    ... If you change the Y-coord after the sprite has started drawing, ... for zero comes free. ...
    (comp.sys.cbm)
  • Re: Multplexing sprites
    ... sprite will finish drawing where it is, then restart at the new Y-coord. ... If the new start position is inside where the old one was drawing, it won't redraw, because sprites are only in a "drawing" or "not drawing mode", triggered on the first line of the sprite matching the Y-coord. ...
    (comp.sys.cbm)