A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: 3D MC rotation

  1. #1
    Senior Member
    Join Date
    Nov 2000

    Allright, running into a few problems here. Hope someone can steer me in the right direction.
    Ok ill try to explain this the easiest way possible:

    ok i have a mc (say around 16 frames) that, when placed after each other give the apperence of a 3d object.
    i have 2 controls in my main scene,
    the left button rotates the the movie to the left. and the right button rotates the movie to the right.
    easy enough right?

    heres the problem. i want to make the 'rotation method' more interactive.
    and instead of having 2 buttons that rotate the spinning. i want to be able to grab the object and 'throw' it to the right and it rotates to the right. but the harder you throw it the faster it goes. same for the left side.
    here is an excellent example of the rotation method im trying to achieve:


    but, his is totally mathematical, i have no idea how to do the same effect to a movie clip. if anyone could help me out or maybe show me a tutorial or fla they have done before would be GREATLY appreciated.
    Thanks for all your time!!!


  2. #2
    Senior Member
    Join Date
    Jun 2000
    Alright...I'll give you a brief introduction to what you are going to need. I have a link you can check out later if you want more detail...ready? Even if you are not...

    Hopefully you remember something from trigonometry, in particular the Unit Circle and some Trigonometric Identities.

    Whats the unit circle? A unit circle is simply a circle with a radius of one centered at the origin (0,0). You can find the position of any point on the circle by taking the sine and cosine of the angle which the point makes with the origin and the x-axis. Here is an ascii picture of part of a circle:
    |- . P (x, y)
    |   /  '
    |  /     :     < - - supposed to be a quarter of a circle
    | /       .
    t = angle with point P and x-axis
    Usually "theta" is used instead of "t" but I didnt have enough room to put it.

    Anyway...some trigonometry will tell us that we can find the position of point P by taking the sine and cosine of angle theta...something like this:
    Px = cos (theta)
    Py = sin (theta)
    We can even take that further for *any* circle of a radius R:
    Px = R * cos (theta)
    Py = R * sin (theta)
    Well with that said how about learning a few trigonometric identities? The ones that are going to help you with transformations are the Sum Identities for Sine and Cosine. Here is what they state:
    cos (a + b) = cos a cos b - sin a sin b
    sin (a + b) = sin a cos b + cos a sin b
    "a" and "b" are both angles
    So what are those two equations saying? That if you have an angle of "a" and add "b" to it you can find the sine and cosine of the sum with the above. So? Well, thats pretty much all 3d rotations are. You have a point that makes an angle of "a" with the x-axis and origin, and you rotate it by "b" degrees...if you are equiped with the two above equations you can find the sine and cosine of the rotate point (rotated by "b" degrees). Still?...SO? Now its time to tie back in with the unit circle. Remember that the sine and cosine of an angle really represents the ordered pair of a point. How about we substitue a few things in the above identities. Lets assume "a" is the angle the point makes with the x-axis and origin and that "b" is the increment rotation value...you could change the identities to something like this:
    cos (a + b) = x * cos b - y * sin b
    sin (a + b) = y * cos b + x * sin b
    Remember that:
    cos a = x
    sin a = y
    But, there is still even one more thing you can substitute. Look at the left side of the above equations...its basically the sine and cosine of an angle right (well, the sum of two angles but in the end its just one angle right?). We can now say that the sine and cosine of the sum of "a" and "b" equals the rotated point:
    nx = x * cos b - y * sin b
    ny = y * cos b + x * sin b
    That right there is rotation in two dimensions or around the z-axis in particular. How do you extrapolate that to the different axes? Easy...just look at your graph from different sides. Your xy-axis graph becomes a zy-axis graph when looked at from the side. It becomes a xz-graph when looked at from the top. So in conclusion there are a total of six equations that rotate a point around all three axes:
    // Given the ordered triplet of (x, y, z)
    // and given the x, y, and z-axis rotation angles: a, b, c
    // rotation around the x-axis
    ry = y * cos a - z * sin a
    rz = y * sin a + z * cos a
    // rotation around the y-axis
    rx = x * cos b - rz * sin b
    rz = x * sin b + rz * cos b
    // rotation around the z-axis
    rx = rx * cos c - ry * sin c
    ry = rx * sin c + ry * cos c
    // your rotated ordered triplet is now (rx, ry, rz)
    The above you can pretty much just copy and paste into Flash. And thats about it! If you wanted to add a throwing type action in you would obtain your "a" and "b" rotation angles (note: no "c" rotation angle because you cannot drag along the z-axis) by taking the difference of the mouse's x- and y-position when you are pressing the mouse button.

    Cool eh? You can read more in depth articles here.

    Good luck.

  3. #3
    Senior Member
    Join Date
    Nov 2000


    wow. thanks alot. im looking at it right now.
    thats some crazy stuff, but im gonna try and get it.
    thanks so much!!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center