A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: chain effect connecting 2 mcs? Help.

Hybrid View

  1. #1
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976

    chain effect connecting 2 mcs? Help.

    Hey guys/gals never posted here, i was wondering if you could help me out.

    My problem is that i have a mc called screen which is a large computer screen. And i have 3 pipes which i want to make a chane type effect between a ground mc and the screen mc. But i dont know the math. The screen sort of floats around and i want the screen mc to be connected using these pipes to the ground mc and rotate and place the pole mcs accordinly. It's sort of hard to describe so i made a pic of what im getting at. Hopefully some one knows how its done. Ive seen it before.

    Thanks in Advance
    Attached Images Attached Images

  2. #2
    Senior Member
    Join Date
    Jul 2000
    Location
    Sydney, Australia
    Posts
    486
    i've tried this before but wasn't able to do it but it should be quite simple. do a search on chaos theory and the double or dual pendulum

    i'll give it a try and post it for you if i get it

  3. #3
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Thanks a_slosh ill give it a search. But it would be much appretiated if you could post it if you work it out. I will do the same if i work it out first. Thanks

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    In you illustration, how is movement imparted? Can you drag the big square?

    Is this supposed to behave like a desk lamp? Which points are fixed?

    One way to model this is as masses connected by springs - but in this case you would use a very stiff spring with a lot of damping, so that the length stays more or less constant.

    For example on this page:

    http://krazydad.com/bestiary/bestiar...ngBuilder.html

    Try setting gravity to 0
    air resistance to .49
    and stiffness to .4

    Be careful to raise resistance first

    The problem with that model is that it is still a little too springy. If you add even more damping, you can get rid of more of the springiness. The advantage of the model is that it relatively simple, mathematically.

    What you probably *really* want is something called inverse kinematics, but this requires more mathematical sophistication than the spring model.

    - Jim
    Last edited by jbum; 12-09-2004 at 03:20 AM.

  5. #5
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    The only problem i see me facing using this model is that i am using premade connecting pole images which i dont want to resize at all. And the yes it behave's like a lamp the fixed points are to the base and the lamp head. I just cant see how i will achieve this properly.

    PS. Nice useful site by the way.
    Last edited by hooligan2001; 12-09-2004 at 07:16 PM.

  6. #6
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    If you use spring-physics method to provide you with the endpoints of each segment, then once you know the endpoints, you can position each segment to match. The endpoints would be where the masses (the dots) are in the spring model.

    Let's say you have calculated that a particular segment has endpoints x1,y1 and x2,y2.

    You set up the movieclip so that it's registration point (it's pivot point) corresponds to x1,y1.

    code:

    segment._x = x1;
    segment._y = x2;



    Then you rotate it into place, by computing the angle between the two endpoints. This code assumes that each segment lies flag, pointing to the right when it is drawn without rotation (0 degrees).

    code:

    var angle = Math.atan2(y2-y1,x2-x1);
    segment._rotation = angle * 180/Math.PI;



    As long as you minimize the springiness of the model, and you assign 'resting' lengths that correspond to the length of your movieclip segments, it should be close enough.

    * * *

    Finally, if you want to do it in a more rigorous way, here are some articles on inverse kinematics - a technique often used to animate articulated models.

    http://freespace.virgin.net/hugo.elias/models/m_ik.htm

    http://www.euclideanspace.com/physic...matics/joints/

    Hope this helps...

    - Jim
    Last edited by jbum; 12-10-2004 at 02:39 AM.

  7. #7
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    After writing my last post, I decided to try it out. I was able to cobble this together in about an hour using my SpringSim class.

    Here is the demo - it shows the virtues and the flaws of this model. You can reposition the lamp by moving the joints. More on the flaws below.

    Desk Lamp Demo


    And here is the source code.

    Desk Lamp Source Code (zip)

    The source code I added reads as follows (most of the hard work occurs inside the spring phsyics library).

    code:

    // Desk lamp simulation using spring phsyics
    // -- Jim Bumgardner, 2004

    #include "SpringSim.as"

    // Setup the spring simulatoin
    // gravity, stiffness, friction
    ss = new SpringSim(this, 0.0, 0.5, 0.99);

    // define the connections between the joints
    joint1.pointAt = joint2; ss.addSpring(joint1, joint2);
    joint2.pointAt = joint3; ss.addSpring(joint2, joint3);
    joint3.pointAt = lamp; ss.addSpring(joint3, lamp);

    // Anchor the base and disallow it to be pulled off
    joint1.setDotProps(true, false);
    delete joint1.onPress;

    // Set up each joint to point in the right direction.
    for (var i = 1; i <= 3; ++i)
    {
    this['joint'+i].onEnterFrame= function()
    {
    var a = Math.atan2(this.pointAt._y - this._y, this.pointAt._x - this._x);
    this._rotation = a*180/Math.PI;
    }
    }




    As you maniuplate the lamp, you'll notice that the joints tend to pull apart. This is because I'm using a very simple dragging function that places no restrictions on where you can drag things, and allows you to drag to illegal positions, where the length of the joints is exceeded.


    Like I said earlier, this isn't as good as inverse kinematics, but it's easier...
    Last edited by jbum; 12-10-2004 at 03:52 AM.

  8. #8
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Wow thats exactly what i want . You dont happen to have it in mx format though do you. Had a look at your SpringSim.as and it pure genious. How long have you been working on that ? Thanks alot for your help.

  9. #9
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    I worked on the SpringSim class for a couple of weeks about six months ago. My original intent was to add some additional stuff to it so it could be used for creating armatures for character animation.

    One day...

    Here's an MX version of the .fla file.

    If you take a look at the invididual movieclips for the joints, you'll see that they are all FLAT - the pivot point on the left and the connecting point on the right . This corresponds to 'zero degrees' rotation.

    - Jim
    Attached Files Attached Files
    Last edited by jbum; 12-10-2004 at 08:21 PM.

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