
Page 4 of 4
Cody Lindley
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org.
View all articles by Cody LindleyWe now need to add some dimension to our code in order to achieve the third dimension. This involves adding another axis to our coordinate system. This axis would be the z axis. So all together now we have 3 axis. They are the x axis, the y axis, and the z axis. The best way to think of the z axis is like this, if some one shot an arrow strait at your head (eye level) the axis the arrow is traveling on is the z axis. If the person who shot the arrow was standing 500 feet away directly in front of you the arrow would go from a very tiny dot to a large arrow stuck between your eyes. This would be considered perspective, because as the arrow travels closer to your head your eyes enlarge the arrow to a realistic size. With that said, image now the Cartesian coordinate system with an axis headed strait for your head. This axis of course would be going through the exact center of the coordinate system which would be (0,0) and extruding towards you. On a monitor think of the z axis as the axis extruding strait out of the screen and coming towards us.
If you look at the animation's below the first example is a ball rotating around the y axis. Really quick before we go on here is a visual to understand what I mean by rotate around the y axis. This image shows how an orange circle could rotate around any of the three different axis.
In the swf below I am faking the rotation around the y axis by using perspective to make the ball larger then smaller as it moves along the x axis. The ball of course is smaller the farther it gets from our view and big the closer it gets to our view. Check out the code and see how it differs from the pervious code. I would like to note that this is still not true perspective because I am only changing the scale of the circle. For true perspective I must also add perspective to the path the ball follows. I am not going to go into detail about this in this example but I will show you the difference by providing two examples. Consider that the first example does not show the ball crossing over to the -z axis. It only looks like it is going away from you down the +z axis. The gray ball however does rotate into the negative side of the z axis. See the difference? For a full explanation check out Flash 5 Studio from friends of Ed, chapter 15 - page 469.
The perspective problem is simple really. You are trying to get a 3 dimensional point in flash, but you must do that by taking what is called an ordered triplet and turn it in to an ordered pair. this is an ordered triplet: (x,y,z) this is an ordered pair: (x,y) What you want to do is drop one of the coordinates so you have an ordered pair and then let flash fake the third coordinate by using perspective. Meaning that flash will be changing the scale of an object while it is rotating around a particular axis according to a perspective variable. look at these examples and see if you can figure out what I mean. If you want to duplicate these examples in flash just drop the code you see in the example on a movie clip. Make sure you have some graphic on the timeline of that movie clip or it will be blank, I've used an orange circle. You will also need another movie clip name "center_cross_hairs". This clip has to be center in the middle of the stage in order for flash to see the origin of the rotation as the center of the swf (or stage). Don't forget to give name it. For a further explanation of the math below reference the book Flash 5 Studio from friends of Ed, chapter 15 rotation points around the z axis = setting the x and y coordinate of a point using sine and cosine. (dropped z)The action script for this movie does not use the distance equation because we are not using the z axis to find any coordinates.
1. ActionScript the Definitive Guide, Colin Moock 2. Super Samurai (http://www.supersamuraiflash.com/) 3. Flash Studio 5, Friends of ed (http://www.friendsofed.com/) 4. Flash Game Studio, Friends of ed (http://www.friendsofed.com/) 5. Visual QuickPro Guide Flash Advanced, Russel Chun Contact: cody@o-positive.com |
Spread The Word
4 Responses to "trigonometry and flash" 
|
said this on 21 Jul 2007 10:59:06 AM CST
This tutorial helped he a
|
|
said this on 11 Jun 2009 9:32:26 AM CST
hi this is very good for
|





Author/Admin)