Results 1 to 4 of 4

Thread: How can I rotate and translade a Sprite using Matrix and Vector with Clanlib?

  1. #1

    Question How can I rotate and translade a Sprite using Matrix and Vector with Clanlib?

    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):
    Code:
            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?

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    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(..)

  3. #3

    Default

    Quote Originally Posted by sphair View Post
    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.

  4. #4
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Then set_modelview of the gc will probably work fine for your needs.

Similar Threads

  1. Replies: 7
    Last Post: 05-31-2012, 12:23 PM
  2. ClanLib 2.4 (SVN) - Matrix Multiplication Reversal
    By rombust in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 01-24-2012, 01:54 PM
  3. How to rotate my sprite?
    By klanpaia in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 01-12-2011, 03:26 AM
  4. Support for Scalable Vector Graphics
    By fdaniels in forum Novashell Game Creation System
    Replies: 2
    Last Post: 03-23-2010, 04:35 AM
  5. How to use the vector data from CL_Raw ?
    By ARme in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 12-21-2006, 08:35 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •