Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Transform a bitmap using shear

This thread is locked; no one can reply to it. rss feed Print
Transform a bitmap using shear
Monica
Member #14,350
June 2012

Hi Allegro forumers!
This is my first post, although I've been playing with allegro for a few months. Now that exams are out of the way I have a lot more time for allegro and I'd like to make a small game over summer. I've been experimenting with isometric views and some pseudo-3D stuff.

I'm struggling because I cannot find a way to shear bitmaps. What I mean by shear is if you have a square, and move the top two corners either left or right, creating a rhombus. I've attached a picture for clarity. Is there an allegro function that can do this, or will I have to write my own?

Best regards
M

J-Gamer
Member #12,491
January 2011
avatar

AFAIK, there isn't an allegro function for that. Although it might be possible using transformations, but I'm not altogether sure of that.
(and I also thought that it was called skewing, not shearing)

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Stas B.
Member #9,615
March 2008

The transformation you want looks like this:

X' = X + S * Y
Y' = Y
Z' = Z

Or in matrix form:

[1 s 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]

I don't use A5 so I can't give you all the details, but you can probably find the relevant info here:
http://alleg.sourceforge.net/a5docs/5.0.6/transformations.html#TOC

J-Gamer
Member #12,491
January 2011
avatar

The code:

ALLEGRO_TRANSFORM trans;
al_identity_transform(&trans);
trans.m[0][1] = s;

There isn't a function that can lead to that matrix, so you'll have to use the underlying float matrix.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Ashteth
Member #3,310
March 2003
avatar

It might be simpler to just draw it as a primitive. Thats how I do it anyways.

Stas B.
Member #9,615
March 2008

Ashteth said:

It might be simpler to just draw it as a primitive.

I don't think it really gets any simpler. You can do everything as if you're working with a regular grid, apply the matrix and everything gets automatically skewed.

Monica
Member #14,350
June 2012

Thanks for pointing me in the right direction. I'm going to look into transformations and let you know if I run into problems. Awesome quick reply, cheers!

Go to: