A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Possible Verlet assistance in Flash 8!

  1. #1
    Iron Chef In-Training OpethRockr55's Avatar
    Join Date
    Sep 2005
    Location
    Kitchen Stadium
    Posts
    313

    Possible Verlet assistance in Flash 8!

    I downloaded the Flash 8 demo version not 30 minutes ago and was quite impressed with all the brand spankin' new things, but something caught my eye when I was going through my ragdoll code that really surprised me.

    When I was ready to begin coding some collision detection, I found that one of my defined variables had become highlighted, like it was already in Flash:

    this.x

    When I right-clicked and viewed help, I felt like I found the holy grail of Flash Verlet. Apparently, Flash 8 has included a new object called a Point! It allows for offsets, vector-like subtraction and addition (would be useful if you know intercepting points along a vector line), polar rotation (could be good for angular constraints), and a distance function, plug two points in, get a distance for free.

    I haven't got into the nitty-gritty of it all, so I'm not sure if it's compatible, but I think it would save loads of CPU to alter a Flash Point object rather than create a user-defined Particle object.

    This stuff really is blowing my mind!
    Last edited by OpethRockr55; 02-15-2006 at 07:38 PM.

  2. #2
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    you know, i was wondering the same thing myself about the point object...
    i'll try running a few tests and see if it's actually better

    also, u prob. know this, but you can use 'x' and such in your objects even if it turns blue

  3. #3
    Iron Chef In-Training OpethRockr55's Avatar
    Join Date
    Sep 2005
    Location
    Kitchen Stadium
    Posts
    313
    Yeah, I knew that, but I didn't know it before I actually looked the code. I tested the MC with and without BitMap Caching, different effects, etc., and it worked fine.

  4. #4
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    alright, i did some testing and the results are in.....

    :::drum roll please:::

    i'm sorry to say that getting a distance from the Point function is not exactly "Free"

    the Point.distance function is about 3.5 times worse than good old Math.sqrt(deltaX*deltaX+deltaY*deltaY)

    here's some code if u want to test it out on your machine

    Code:
    import flash.geom.Point
    
    p1 = new Point(10.3,10.12)
    p2 = new Point(20.34,11.3)
    
    //----------------------------------------\\
    //Point Method
    startTime = getTimer()
    for(i=0;i<1000;i++){
    	Point.distance(p1,p2)
    }
    compTime = getTimer()-startTime
    trace("Flash method: " + compTime)
    
    //-----------------------------------------\\
    //Good old method
    startTime = getTimer()
    for(i=0;i<1000;i++){
    	dist(p1,p2)
    }
    compTime = getTimer()-startTime
    trace("Regular method: " + compTime)
    
    //function
    function dist(p1,p2){
    	xD=p1.x-p2.x
    	yD=p1.y-p2.y
    	return Math.sqrt(xD*xD+yD*yD)
    }
    the distance function is the only one i tested, but i guess that if that's slower, then so are all the other ones

    ..its kinda disappointing.. i expected better from flash
    Last edited by ozmic66; 02-15-2006 at 11:25 PM.

  5. #5
    Iron Chef In-Training OpethRockr55's Avatar
    Join Date
    Sep 2005
    Location
    Kitchen Stadium
    Posts
    313
    AW!! I was really hoping I had something going there....

  6. #6
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I made some tests with it too when Flash8 came out:
    http://www.flashkit.com/board/showthread.php?t=650303

  7. #7
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    meh, no different to: var point:Object = {x:200, y:200}
    New sig soon

  8. #8
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    Sorry to be ignorant but what does verlet mean in the context you're giving it? I looked it up on wikipedia but everything there made it look like something used strictly with calculus, which is something I don't know. However, all the stuff you're talking about in this post looks like plain old 2D algebra. I'm making a game where objects' movements are processed as spatial vectors for better collision. Would learning this stuff help me?

  9. #9
    Iron Chef In-Training OpethRockr55's Avatar
    Join Date
    Sep 2005
    Location
    Kitchen Stadium
    Posts
    313
    Verlet Integration is a method introduced by Jakobsen (I forgot his first name) of simulating particles, rigid-bodies, etcs. through simple points. Basically, all it takes to move a point is its vector 'speed' along is axes and moving it along those points every timestep, or, for Flash, keyframe or function call. That's really all it is. For simuating rigid bodies, there is a method outlined in the Jakobsen article that I'm guessing you read in which you simply displace two particles that you want to connect a defined distance. This method is used for simple physics simulation because of the accuracy you recieve for the CPU used.

  10. #10
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    Thanks! Sounds useful. I'll have to go do some more research.

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