Flip/mirror the moving image horizontally

Problems with Canvas, OpenGL, etc...

Flip/mirror the moving image horizontally

Postby b2063046 » Wed Oct 20, 2010 9:09 pm

Hi all!

Need some help, don't know some function..

I'trying to flip one image horizontally, so something like this:

Image
It'll be depending from the direction of moving of the char, "face forward" :D

I've found some methods with canvas and with matrix, but I allways have some problems with coordinates.
So I wanted to use a Matrix methods, to transpose the matrix of the image and then rotate 90°. Rotate method is clear but I can't find the transpose method. (Transpose at wikipedia)

Matrix operations were at school for a long time ago, I've forgot this all stuff :)

Please advice me the right method!
Last edited by b2063046 on Thu Oct 21, 2010 1:59 pm, edited 1 time in total.
b2063046
Freshman
Freshman
 
Posts: 7
Joined: Wed Oct 20, 2010 7:24 pm

Top

Re: Flip/mirror horizontally a image with motion

Postby b2063046 » Thu Oct 21, 2010 1:57 pm

one more time the main problem - I want to flip not the whole canvas, but only the "jumping" image, wich have dynamical coordinates x, y


any advice?


UPD:

I've found such a post, but the problem is the same - they are flipping the whole canvas and I need to flip only the single image, without background images

the app from that post:

Image
b2063046
Freshman
Freshman
 
Posts: 7
Joined: Wed Oct 20, 2010 7:24 pm

Re: Flip/mirror the moving image horizontally

Postby b2063046 » Thu Oct 21, 2010 4:54 pm

OK, I've found the solution.. It's so simple... :?

1. set some matrix scale: matrix.setScale(-1.0f, 1.0f);
2. create new Bitmap with this matrix
3. show the Bitmap

Example from doDraw() method:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         c.save();
  2.                 matrix.setScale(PIG_FLYING_DIRECTION, 1.0f);
  3.                 pigPaintFlip = Bitmap.createBitmap(pigPaint, 0, 0, pigPaint.getWidth(),pigPaint.getHeight(), matrix, true);
  4.                 c.drawBitmap(pigPaintFlip, pigX, pigY, new Paint());
  5.                 pigPaintFlip = null;
  6.         c.restore();
  7.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



PIG_FLYING_DIRECTION is a float -1.0f or 1.0f for left or right flipping of image

pigPaint is a initial image Bitmap instance; c - Canvas; pigX, pigY - coordinates
b2063046
Freshman
Freshman
 
Posts: 7
Joined: Wed Oct 20, 2010 7:24 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests