Jump to content
Posted 11 January 2009 - 04:59 AM
Posted 11 January 2009 - 06:15 AM
Posted 11 January 2009 - 06:27 AM
Posted 11 January 2009 - 09:34 PM
finalMatrix = Matrix.Multiply(Matrix.RotationZ(angle), Matrix.Translation(pos));
then when drawing the sprite,
public void DrawSprite(Sprite sp)
sp.Transform = finalMatrix;
sp.Draw(texture, ctr, Vector3.Empty, unchecked((int)spcolor));
isRotate = false;
sp.Draw(texture, ctr, pos, unchecked((int)spcolor));
Posted 17 January 2009 - 07:50 AM
Posted 19 January 2009 - 09:15 AM
Posted 21 January 2009 - 07:19 PM
Original post by GameFissure
I'm sorry geekman1009, I don't understand what you mean :(. What do you mean when you say don't use rotate in Sprite->Draw?
If possible could someone please provide me with a detailed tutorial? Of fourse there are tutorials online... but most of them do not get in to enough detail for me to understand.
EDIT - I wouldn't mind being recommended a book either :).
Thank you and sorry for the late reply.
Posted 22 January 2009 - 03:07 AM
Original post by geekman1009
What I mean is, don't use
D3DXMatrixTransformation2D(&SpriteM, NULL, 0.0f, NULL, &D3DXVECTOR2(SpriteFocus.x, SpriteFocus.y), Index, NULL);
(I didn't read your original post carefully, and since I'm using XNA Game Studio which, the SpriteBatch have incorporated the transformations into the Draw() method, hence the confusion)
since this function always rotate you sprite around the origin (top left of the screen), regardless of how you set your Sprite Center and Position. The bug I mentioned earlier is, D3D will Translate your sprite to its Position BEFORE the Rotation, resulting in what you have been seeing in your current situation - the sprite is rotating around the screen origin. To avoid this bug, multiply 2 transformation matrices together to achieve the effect of rotating a sprite around it's center at given position, in one matrix, you then apply this composition matrix to the sprite.
In other words, rotate the sprite first (regardless of its position, since D3D will rotate the sprite at the world origin or top left of the screen), then translate the rotated sprite to the desired location. This can be achieved by Multiplying a Rotation-around-Z-axis Matrix (the LEFT matrix) and Translation Matrix (the RIGHT matrix). Apply the resulting Matrix from the multiply above and you will get what you want.
Posted 10 July 2011 - 01:14 AM
No that functions is fine. It will apply scaling first, then rotation, then translation (as indicated in the documentation).
I think the problem might be that he's setting the position in ID3DXSprite::Draw...try setting your position as the pTranslation parameter of D3DXMatrixTransformation2D instead of the pPosition parameter of ID3DXSprite::Draw.
Posted 11 July 2011 - 08:10 AM
Posted 12 July 2011 - 12:18 AM
Draw is not bugged.
I have used many times, with Rotations, Translation and Scaling and it works well.
You have to pay attention to sequence of trasformations... See Mout formula at http://msdn.microsof...6(v=vs.85).aspx
How you can see Traslation is last trasformation ( Mt ).
Mout = (Msc)-1* (Msr)-1* Ms * Msr * Msc * (Mrc)-1* Mr * Mrc * Mt
Remember that Scaling is before Rotation that is before Translation