views:

415

answers:

5

Hi, how can i transform rectangle into trapezoid with ActionScript3

my trapezoid is a floor of 3D room, and i want to texturize it (bitmap tile).

 _____________
|  |     |   |
|  |_____|   |
|  /      \  |
| / trapez.\ |
|/__________\|
+3  A: 

It depends on how the "rectangle" is represented in your program. Few options:

  1. If your rectangle is vector, and you have access to the anchor points:

    ---> o------o <---
         |      |
         |      |
         o------o
    

    Becomes:

           o--o
          /    \
         /      \
         o------o
    

    Simply translate the two top points and condense them to each other.

  2. If that 'rectangle' is actually a DisplayObject, you will need to 'stitch' two of the same DisplayObject to create a new one. This page has examples of what you want along with example code.

  3. Another option would be to use Papervision3D - which is using the above rendering method as a base.

  4. This one's a bit tricky, but it's an option. You can use displacement maps as described here. The code is AS2, but it should be fairly simple to "port".


EDIT

As par this answer, I suggest you use Papervision3D (see 3rd option) to do that, as you might want to move the camera around the "room". It will also take care of the other walls as well.

LiraNuna
Sorry, didn't notice your Papervision reference before posting my remarks. Regards, AlecMcE
alecmce
@alecmce: You did bring out Flash10's 3D options, though. I forgot about that one.
LiraNuna
+1  A: 

my rectangle is bitmap tiled and i want to transform it into trapezoid. Or are there any way to tile trapezoid?

Armen Mkrtchyan
A: 

If you're targetting FlashPlayer 10 you can do it by rotating the clip's rotation values, see This post form Mike Chambers for details.

Otherwise you're going to need a 3D engine like Papervision. There's no simple way to do non-affine transformations in Flash Player 9.

Good luck.

alecmce
Ah! I knew I forgot one item in my list...
LiraNuna
+1  A: 

the idea is to divide it into triangles and then perform an affine transformation (using Matrix) on them ... senocular provided sample code (for AS2) ...

there's also a handful of libs online, but I can't find any right now ...

greetz

back2dos

back2dos
That's essentially how Papervision does it. Might as well use that, it's the de-facto standard these days, but any other 3D engine would do it too.
alecmce
every now and then, filesize does matter in flash developement ... but yes, you can also extract the code from a 3d engine of course ... :)
back2dos
Just don't see the need to reinvent the wheel! If the question's being asked how to do it, then the questioner probably isn't going to do it for themselves any time soon. Development time is also sometimes a factor in software projects! ;)
alecmce
A: 

My trapezoid is a floor of 3D room, and i want to texturize it (bitmap tile).

 _____________
|  |     |   |
|  |_____|   |
|  /      \  |
| / trapez.\ |
|/__________\|
Armen Mkrtchyan
add this information to your original post, don't do it as answers.
grapefrukt
either that, or ask a new question, if you feel, it's a new/different problem
back2dos