|
From: <ma...@us...> - 2012-01-08 15:02:10
|
Revision: 643
http://openautomation.svn.sourceforge.net/openautomation/?rev=643&view=rev
Author: mayerch
Date: 2012-01-08 15:02:04 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
More stable moveTo during rapidly following requests
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-08 14:14:38 UTC (rev 642)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-08 15:02:04 UTC (rev 643)
@@ -196,6 +196,14 @@
var noSetup = true;
/**
+ * Status if currently an animation is running
+ * @property inAnimation
+ * @type Bool
+ * @private
+ */
+ JSFloorPlan3D.inAnimation = false;
+
+ /**
* Constant representing the ID of an ELEMENT_NODE
* @property ELEMENT_NODE
* @private
@@ -1000,28 +1008,43 @@
// speed of the changing
var steps = 100;
- var rate = {
- azimut: ( azimut - showStates.currentAzimut ) / steps,
- elevation: ( elevation - showStates.currentElevation ) / steps,
- height: ( height - showStates.currentHeight ) / steps
- };
+ var rate = { azimut: 0.0, elevation: 0.0, height: 0.0 };
+ function calcRate()
+ {
+ rate = {
+ azimut: ( azimut - showStates.currentAzimut ) / steps,
+ elevation: ( elevation - showStates.currentElevation ) / steps,
+ height: ( height - showStates.currentHeight ) / steps
+ };
+ }
+
function doMove()
{
+ JSFloorPlan3D.inAnimation = true;
var done = true;
if( Math.abs( azimut - showStates.currentAzimut ) > Math.abs( rate.azimut ) )
{
+ if( rate.azimut == 0.0 ) calcRate();
showStates.currentAzimut += rate.azimut;
+ if( Math.abs( azimut - showStates.currentAzimut ) < 1e-5 ) // clamp if close enough
+ showStates.currentAzimut = azimut;
done = false;
}
if( Math.abs( elevation - showStates.currenteElevation ) > Math.abs( rate.elevation ) )
{
+ if( rate.elevation == 0.0 ) calcRate();
showStates.currentElevation += rate.elevation;
+ if( Math.abs( elevation - showStates.currenteElevation ) < 1e-5 ) // clamp if close enough
+ showStates.currenteElevation = elevation;
done = false;
}
if( Math.abs( height - showStates.currentHeight ) > Math.abs( rate.height ) )
{
+ if( rate.height == 0.0 ) calcRate();
showStates.currentHeight += rate.height;
+ if( Math.abs( height - showStates.currentHeight ) < 1e-4 ) // clamp if close enough
+ showStates.currentHeight = height;
done = false;
}
@@ -1030,10 +1053,16 @@
render();
if( !done )
window.requestAnimationFrame( doMove );
- else if( delayedFn )
- delayedFn();
+ else {
+ JSFloorPlan3D.inAnimation = false;
+ if( delayedFn )
+ delayedFn();
+ }
}
- doMove();
+ if( JSFloorPlan3D.inAnimation )
+ calcRate();
+ else
+ doMove();
}
};//());
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|