Stretching a square image onto a rhombus?

Hi,
First off, I'm a noob (sorry). I tried searching the web for a way to do this but haven't had any luck.

What I want to do is take a square image, say 50x50 pixels, and somehow stretch it onto a rhombus with sides of length 50 pixels, so that it's basically like looking at the 2d image from an angle. Also the angle of viewing needs to be variable.

I was thinking that I could write an algorithm for this, where the color of each pixel is the average of the pixels that it would be overlapping if the image were turned at that angle and didn't lose it's original pixellation. However I don't know how well this would work, and it seems like it would be a complicated algorithm to write.

Is there some function out there that's already been written that can do this? Also is it practical to hope that it will run fast enough to draw, say, one hundred rotating images at 60fps? Because if this isn't practical then it won't be worth the trouble anyway.

Thanks in advance,
-Levi
Wait. Do you want to shear (I'm guessing this is what you meant, since you can't stretch a rectangle into a rhombus), or rotate?
Either way, both can be accomplished using linear transformations, but how you approach it depends on what you're using for graphical output (OpenGL, SDL, images, etc.).
No I mean distort the image so that it fits onto a rhombus. In GML there is a system of functions for doing this, but I don't know what it's C++ counterpart is.

More specifically, the top left corner of your image will be in the top left corner of the rhombus, the top right corner of the image will be in the top right of the rhombus, etc., and all the pixels in between are blended so that you can still recognize the image (at least if your rhombus is somewhat close to being a square).
Last edited on
Sorry, I'm not following. Mainly, I don't understand how what you said is different from a rotation. Can you post a link to the documentation of the functions you're talking about?
Well it would be like rotating a 2d (xy plane) image on the z axis orthogonally, if that's what you mean.

Here's the documentation on the functions:
http://gamemaker.info/en/manual/405_06_advanced
Look for the primitive and texture-related functions.
draw_primitive_begin_texture() and draw_vertex_texture(), right? And this is what you want to do:
http://imageshack.us/photo/my-images/4/rotation.png/
Right?
Ah-ha. Yes, you want to shear.
Like I said, there are many ways to do this. With OpenGL, for example, it would look a lot like the GML code. You'd start drawing a polygon and you'd give vertices to the library.
It's also possible to transform a bitmap into another.
It all depends on what you have available and what exact results you expect.
Is that shearing? I thought shearing was only with regular rotation.

In any case, thanks for your help!! I'll try OpenGL, sounds like it'll do the trick.
Last edited on
Topic archived. No new replies allowed.