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.\ |
|/__________\|
It depends on how the "rectangle" is represented in your program. Few options:
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.
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.
Another option would be to use Papervision3D - which is using the above rendering method as a base.
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.
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 ...
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.
Related
I am using Flash CC.
I have drawn 7 rectangles using the Rectangle Tool.
I then converted the 7 as one movie clip (By hitting F8).
The Problem:
I want to be able to iterate through these shapes and move each individually.
However the 7 rectangles seem to be encapsulated into the ONE shape and I can't access them.?
If I use .numChildren on the movie clip, it returns 1.
If I use .getChildAt("anything > 0") its a null reference exception.
Please help,
I don't understand how this is so difficult.
I have searched for ages to find the solution to this and for the life of me I can't.
Thanks in advance.
(P.s) Instantiating the rectangles in code works, but I need to be able to do this via Flash CC as I will be importing artist material for manipulation.
Your best choice is to make every shape in your made movie clip a movie clip as well.
In Flash go into your made MovieClip (I will call it containerMC for easier understanding) and make every shape a MovieClip by hitting F8. You can also give them instance names, if you want, just make sure they're unique.
Then your containerMC will return numChildren value 7 in your case.
You can move/access your shapes in the containerMC via getChildAt(), or by using their instance names that you've provided via containerMC.instance1 or containerMC["instance1"].
i'm new to libgdx, I'm trying to make a sprite move to particular target. I can make the sprite move perfectly in x position. i`d move to target position without inputprocess like a enemy. I've tried a few different things but at this point its just guessing and checking.
o(actor) render to target from any position of screen.
/*
o((qx,qy)actor)
|
|
v
((lx,ly)actor)o--->target(tx,ty)<------o((rx,ry)actor)
*/
pls helpme ...
I suggest you take a look at Universal Tween Engine. It's perhabs some overkill to just linealy progress a value across time but it will handle all the things you need. Just read the GetStarted page on the GoogleCode project of it to learn the basics.
Also, you can run a demoApp that showcase it's potential.
Here it's in HTML5
Here it's in Desktop
And here it's in Android
All three are done in LibGDX by the way.
I need to be able to draw a thick patterend line between 2 points in AS3, I can't use the draw API because it doesn't all me to actually put detail (pattern etc) into the thickness of the line, I thought about perhaps using the line to create a bitmap version and then using that as a mask, but I remember many years ago seeing some examples that use a movieclip as a source for a line, but I can't find examples of that now at all, any ideas?
I've attached an example image of how I want the line to look.
I suspect Graphics.lineBitmapStyle() will do the trick. If you want to use a Sprite or MovieClip as the source, you'll have to draw() it to a BitmapData first. The example code on that later link should get you up and running with that.
Hey, this is really annoying me.
I have a big code, but essentially, this part comes to transformation of a BitmapData to triangle points, using affine transformation.
Also - I know that BitmapData is rectangular - the last, fourth point of the transformation is just the first one reflected over the axis defined by the other two points.
A small thing so you can see which point is which one:
1........2
. / / / /|
./ / / /
. / / / |
./ / /
. / / |
./ /
. / |
./
3 - - - -4 - 4th point reflected
This whole process would come to scaling, rotating and skewing the BitmapData based on the angles between the points...
But somehow my code still does not work.
Looking at a similar thing in PaperVision 3D - still didn't work?
Can anybody please post a code, or a link to code for this?
Thanks.
have a look at this, might help:
triangles and uvs in flash
I want to create a 3D cylinder, sphere, cone using Actionscript for Flash Player 10. Is there any available class?
I also want to know how to paint gradient, wrap text and texture around them. It would be nice if these class have these functions. I can't use non DisplayObject in this project so PV3D is not an option
As Cameron says, you should probably use a framework like PV3D or Away3D. That said, all those frameworks are written in AS so you could roll your own.
Here are a few examples I created using only the fp10 3d engine:
http://actionsnippet.com/?p=1726
http://actionsnippet.com/?p=2092
http://actionsnippet.com/?p=2097
http://actionsnippet.com/?p=2158
You can create primative shapes using parametric equations:
sphere :
x = r sin(u) cos(v)
y = r cos(u) cos(v)
z = r sin(v)
For a cylinder you can just use the equation for a circle and extrude it:
x = r cos(t)
y = r sin(t)
z = increase at some interval to the height of the cylinder
I can post some additional information about this topic if your interested.
There are 3D drawing functions for Flash 10, but I don't think they support wrapping text around a 3D object. It sounds like you need a 3D framework. Some popular ones (there's lots):
Sandy3D
Papervision3D
Away3D
Keep mind that Adobe has announced that it will soon be releasing a new version of Flash with built-in hardware-accelerated 3D rendering APIs (codenamed "molehill").