Sign in to follow this  
derek7

sprite draw function

Recommended Posts

HRESULT Draw(LPDIRECT3DTEXTURE9 pSrcTexture, CONST RECT *pSrcRect, D3DXVECTOR3 *center, CONST D3DVECTOR3 *pTranslation, D3DCOLOR Color ); pSrcTexture - a pointer to the texture to be used, see textures pSrcRect - pointer to a rectangle defining the area of the texture to use or NULL for the whole texture pCenter- pointer to a 3D vector specifying the position in the sprite around which it can be rotated or NULL for top left pTranslation - pointer to a 3D vector defining the screen position of the sprite. Note: in Direct3D 0,0 is the top left of the screen. Color - colour value that can be used to modulate the texture colours. A value of 0xFFFFFFFF maintains the colour from the texture. Note: you can use the D3DCOLOR_COLORVALUE macro to create a D3DCOLOR from RGB values. why is there a pCenter in a draw function ? in the draw function ,no need and no parameter to indicate a value to rotate sprite. however in SetTransform function ,we can rotate a sprite . BTW in SetTransform ,Is the center parameter center of sprite ? or center of screen?

Share this post


Link to post
Share on other sites
It can be used as the center of the object the sprite represents.
Say you have a hammer in your game, and you want the hammer to rotate around its balance point, not around the sprite center, and definetly not around the sprites top-left corner ^^

Share this post


Link to post
Share on other sites
Quote:
Original post by pulpfist
It can be used as the center of the object the sprite represents.
Say you have a hammer in your game, and you want the hammer to rotate around its balance point, not around the sprite center, and definetly not around the sprites top-left corner ^^


I found sprite->Draw(t,0,&D3DXVECTOR3(222,0,0), &D3DXVECTOR3(-222,0,0), 0xFFFFFFFF);

the 3nd and 4nd parameter just have a opposite effect. if you set above,and the effect equal set them all 0. It seem 3nd and 4nd parameter just translate sprite . why call it rotate center?

Share this post


Link to post
Share on other sites

Yes I remeber using this function to implement "smooth" scrollig.
The structure of the program was something like

center.x = (the x component of the upper left tile that is outside the screen)
center.y = (the y component of the upper left tile that is outside the screen)

for(i=0, i<n_vert_tiles; i++)
for(j=0, j<n_horz_tiles; j++)
{
pTranslation.x = j * tile_width
pTranslation.y = i * tile_height

Draw(pSrcTexture, pSrcRect, center, pTranslation, Color );
}


Im not sure if there is any technical difference between the vectors, but this example shows that having them both is useful.

Share this post


Link to post
Share on other sites
Quote:

why call it rotate center?

I guess that the rotation algotithms in the rotation function uses it to get the rotation right.

PS. If that is the case, it also means that there IS a technical difference between them

Share this post


Link to post
Share on other sites

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