-
Iron Chef In-Training
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.
-
Senior Member
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
-
Iron Chef In-Training
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.
-
Senior Member
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.
-
Iron Chef In-Training
AW!! I was really hoping I had something going there....
-
Senior Member
-
Senior Member
meh, no different to: var point:Object = {x:200, y:200}
-
Bacon-wrapped closures
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?
-
Iron Chef In-Training
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.
-
Bacon-wrapped closures
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|