Original Post
I am using DirectX's ID3DXSprite interface to render and translate 2D sprites on screen. So far that part of the code looks as follows:
D3DXMatrixIdentity( &d3dMat );
D3DXMatrixScaling( &d3dScalingMat, att.scaleX, att.scaleY, 1.0f );
float radians = att.rotation*(PI/180);
D3DXMatrixRotationZ( &d3dRotMat, radians );
D3DXMatrixTranslation( &d3dTransMat, att.x, att.y, 0.0f );
D3DXMatrixMultiply( &d3dMat, &d3dMat, &d3dRotMat );
D3DXMatrixMultiply( &d3dMat, &d3dMat, &d3dScalingMat );
D3DXMatrixMultiply( &d3dMat, &d3dMat, &d3dTransMat );
pD3DXSprite->SetTransform( &d3dMat );
D3DXVECTOR3 d3dCenterPos;
d3dCenterPos.x = att.centerX;
d3dCenterPos.y = att.centerY;
d3dCenterPos.z = 0;
if( FAILED( pD3DXSprite->Draw( pD3DTexture9, &renderRect, &d3dCenterPos, NULL, D3DCOLOR_ARGB( att.alpha, att.red, att.green, att.blue ) ) ) )
where the att struct contains my sprite's attributes.
My knowledge of matrices is enough to know what they do but not enough to know how they work
(except for that they are a 3x3 or 4x4 grid of numbers which can multiply by each other to combine or by a vector to transform that vector by the matrix).
So far, this code has been fine for rotating, scaling and translating,
but recently I need to transform a bunch of points (collision points, btw) by the same matrix as my sprite is translated by.
The problem is that in the Draw() function I set the position to rotate from (centre of sprite),
and when I translate my points by d3dMat, they do not transform the same as the sprite. How do I go about this?
Do I need to translate d3dMat before I rotate, and simply set the 3rd parameter of Draw() to NULL?
I am using the D3DX library function D3DXVec2TransformCoord(), is this the correct function to use to transform a vector by a given matrix?
Thanks for the help!
Stay Clausal,
Red Sodium
[edited by - red_sodium on April 11, 2004 11:24:37 AM]
[edited by - red_sodium on April 11, 2004 11:25:20 AM]
[edited by - red_sodium on April 11, 2004 11:26:16 AM]