Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » [Feature request] flipable "image"

This thread is locked; no one can reply to it. rss feed Print
[Feature request] flipable "image"
Ariesnl
Member #2,902
November 2002
avatar

I saw this in Qt (cute) an "image" with two sides.. two bitmaps that can be flipped over the X or Y axis .. just like a playing card. It would be a nice addition to Allegro. Should be doable since allegro already uses 3d stuff in orthographic projection.

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

This is actually really easy. If you're drawing a quad, simply draw the same quad with vertices in counter order. You could write a simple function that draws two sided bitmaps no problem. Don't really see why allegro needs it though, as it doesn't have a general use case.

Chris Katko
Member #1,881
January 2002
avatar

al_draw_bitmap(,,,ALLEGRO_FLIP_HORIZONTAL) 
al_draw_bitmap(,,,ALLEGRO_FLIP_VERTICAL)

???

Or do you want a full animation? If so, that's the situation for a custom function written by yourself and not a generic library function.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Ariesnl
Member #2,902
November 2002
avatar

I don't mean a 2d flip.. but a 3d flip of a 2d bitmap.. or two actually..
Like this:
http://doc.qt.io/archives/qt-4.8/qml-flipable.html
See the flipping effect ?

This could be used in a lot of things. Not just cards..
Some games use it in am inventory to switch between character and actual inventory.

Al_rotate_transform rotates around the Z axis wich is usual when doing 2d. 2 more rotation transforms around x and y should do the trick i think

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

No. You literally reverse the winding order of the vertices you pass, and it draws the reverse image. All you do is change the texture.

Or if you're lazy, translate to the center of the image, rotate by PI around whatever axis you prefer, and then translate back.

Ariesnl
Member #2,902
November 2002
avatar

I think I was not clear...

I want an effect of a "card" being turned upside down and vice versa
so one side turns towards the viewer and the otherside turns away from the viewer until only the edge ( or in this case nothing) is visible.. than the other image becomes visible and the effect is reversed. so you litirally see a card being turned "open" or "closed" like with playingcards

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Okay then see the second part of my post just rotate by an angle other than pie. Use transforms.

Say you have a playing card centered on x,y,z, then you do the following :

#SelectExpand
1// draw front 2al_draw_bitmap(frontside , tlx , tly , 0); 3 4ALLEGRO_TRANSFORM t; 5al_identity_transform(&t); 6 7al_translate_transform3d(&t , -x , -y , -z); 8al_rotate_transform3d(&t , vx , vy , vz , 2.0*M_PI*(time/3.0)); 9al_translate_transform3d(&t , x , y , z); 10 11// draw back 12 13al_use_transform(&t); 14 15al_draw_bitmap(backside , tlx , tly , 0);

However, you'll probably have to use a perspective projection and the primitives addon to draw the quads instead of al_draw_bitmap.

Ariesnl
Member #2,902
November 2002
avatar

al_rotate_transform3d..
I didn't know about that function... ???

thnx, I'm gonna try it;)

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: