good stuff guys, thanks ;)
On 6/21/07, Sergei Nikiforovski <[EMAIL PROTECTED]> wrote:
interval is Ok, quick fix:
var MouseX;
var MouseY;
setInterval( determineVelocity, 20 );
function determineVelocity():Void
{
var newMouseX:Number = _root._xmouse;
var newMouseY:Number = _root._ymouse;
var deltaX = Math.abs(MouseX - newMouseX)
var deltaY = Math.abs(MouseY - newMouseY)
var dist = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY))
velocity = dist*31; // 31 = fps
if (!isNaN(velocity) && velocity !=0) {
//trace( _root._xmouse + ", " +MouseX+ ", " + deltaX );
trace( Math.floor(velocity) + ", (" +deltaX+ ", " + deltaY +")");
}
MouseX = newMouseX;
MouseY = newMouseY;
};
----- Original Message -----
From: "Joshua Sera" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[email protected]>
Sent: Thursday, June 21, 2007 1:37 PM
Subject: Re: [Flashcoders] Mouse Velocity?
> Well yeah. If you're doing a verlet integration-style
> thing where all you store about a particle is it's
> last position, and it's current position, and you're
> not using a constant time step, you have to do that.
> Storing the last 5 updates is a seperate thing.
>
> This is just to overcome the difference in time
> between the interval firing and the mouse moving. If
> the mouse is updated every 10 milliseconds, and your
> interval fires every 7, you're going to get intervals
> where the mouse position hasn't changed.
>
> The solutions, really, are to slow down your interval,
> or just average things.
>
>
> --- Ron Wheeler <[EMAIL PROTECTED]>
> wrote:
>
>> Would you not eliminate the whole problem by keeping
>> track of the time
>> that the previous position was taken along with its
>> coordinates and use
>> that to calculate the time between the readings and
>> divide that into the
>> distance?
>> Then you do not care if the set interval or on enter
>> frame come at
>> equally spaced intervals.
>>
>> Ron
>>
>> Joshua Sera wrote:
>> > It's indeed a setInterval problem, as the interval
>> and
>> > mouse movement won't necessarily match up.
>> >
>> > onMouseMove can also be a problem, as you'll wind
>> up
>> > with a lot of readings going straight
>> > up/down/right/left, rather than in the direction
>> > you're moving.
>> >
>> > What I've done for this problem is to average the
>> > mouse movement over 5 or so updates to get a more
>> > accurate reading. Demo here:
>> >
>> > http://www.yourmomsa.com/springexp/springexp2.swf
>> >
>> > Pick the guy up by the wheel to toss him.
>> >
>> >
>> > --- "eric e. dolecki" <[EMAIL PROTECTED]> wrote:
>> >
>> >
>> >> I am calculating mouse velocity, but every now
>> and
>> >> then you get a 0 for
>> >> velocity eventhough its not 0 (setInterval prob I
>> >> suspect). Any better
>> >> approach?
>> >>
>> >> var MouseX;
>> >> var MouseY;
>> >>
>> >> function determineVelocity():Void
>> >> {
>> >> MouseX = _root._xmouse
>> >> MouseY = _root._ymouse
>> >> setTimeout( calc, 9 );
>> >> };
>> >>
>> >> setInterval( determineVelocity, 20 );
>> >>
>> >> function calc():Void
>> >> {
>> >> var newMouseX:Number = _root._xmouse;
>> >> var newMouseY:Number = _root._ymouse;
>> >>
>> >> var deltaX = Math.abs(MouseX - newMouseX)
>> >> deltaY = Math.abs(MouseY - newMouseY)
>> >> dist = Math.sqrt((deltaX * deltaX) + (deltaY
>> *
>> >> deltaY))
>> >> velocity = dist*31; // 31 = fps
>> >> trace( velocity );
>> >> };
>> >> _______________________________________________
>> >> [email protected]
>> >> To change your subscription options or search the
>> >> archive:
>> >>
>> >>
>> >
>>
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>> >
>> >> Brought to you by Fig Leaf Software
>> >> Premier Authorized Adobe Consulting and Training
>> >> http://www.figleaf.com
>> >> http://training.figleaf.com
>> >>
>> >>
>> >
>> >
>> >
>> >
>> >
>>
> ____________________________________________________________
________________________
>> > Sick sense of humor? Visit Yahoo! TV's
>> > Comedy with an Edge to see what's on, when.
>> > http://tv.yahoo.com/collections/222
>> > _______________________________________________
>> > [email protected]
>> > To change your subscription options or search the
>> archive:
>> >
>>
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>> >
>> > Brought to you by Fig Leaf Software
>> > Premier Authorized Adobe Consulting and Training
>> > http://www.figleaf.com
>> > http://training.figleaf.com
>> >
>> >
>> >
>> _______________________________________________
>> [email protected]
>> To change your subscription options or search the
>> archive:
>>
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>> Brought to you by Fig Leaf Software
>> Premier Authorized Adobe Consulting and Training
>> http://www.figleaf.com
>> http://training.figleaf.com
>>
>
>
>
>
> ____________________________________________________________
________________________
> Get the free Yahoo! toolbar and rest assured with the added security of
> spyware protection.
> http://new.toolbar.yahoo.com/toolbar/features/norton/index.php
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
--
eric e. dolecki
senior interactive engineer
http://www.ericd.net
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com