PDA

View Full Version : How can I rotate and translade a Sprite using Matrix and Vector with Clanlib?



RawArkanis
08-21-2012, 07:48 PM
Hello.

Can I rotate and translade a sprite using Matrixes and Vectors in ClanLib?
In other words, can I abstract the default (x,y) coordenate system and use it directly in ClanLib without having to translate it to (x,y)? Draw a sprite using Matrixes and Vectors directly?

Something like this (in XNA):

private void Paint(SpriteBatch batch, Matrix center)
{
batch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, center);
batch.Draw(image, new Vector2(0, 0), null, Color.White, 0.0f, new Vector2(image.Width / 2.0f, image.Height / 2.0f), 1.0f, SpriteEffects.None, 1);
batch.End();
}

public Matrix Draw(SpriteBatch batch, Matrix center)
{
Matrix world = Matrix.CreateTranslation(distPivot, 0, 0);
world *= Matrix.CreateRotationZ(angle);
world *= Matrix.CreateTranslation(new Vector3(offsetCenter, 0));
world *= center;
Paint(batch, world);
return world;
}

I have a example in Chien2D, a Educational C library, but its methods are in Portugues. If necessary I will post it later.

Well, can I achiev it with ClanLib or I'm locked in the default (x,y) world?

sphair
08-23-2012, 08:48 AM
Do you need to apply the same matrix to many sprites? If so, you have set_modelview (const CL_Mat4f &matrix) on the graphic context.

But if you just want to rotate a sprite, call sprite.set_angle(..)

RawArkanis
08-23-2012, 11:46 AM
Do you need to apply the same matrix to many sprites? If so, you have set_modelview (const CL_Mat4f &matrix) on the graphic context.

But if you just want to rotate a sprite, call sprite.set_angle(..)

No. With matrix I can do a world and camera system, simulate orbitation movement, spawn lasers from the nose of a ship and etc. much more easily.

sphair
08-23-2012, 08:45 PM
Then set_modelview of the gc will probably work fine for your needs.