Skip to content

Commit

Permalink
Use local static variables in X3DViewpointNode.
Browse files Browse the repository at this point in the history
  • Loading branch information
create3000 committed Mar 9, 2018
1 parent 3b9da65 commit 4289088
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 89 deletions.
4 changes: 3 additions & 1 deletion src/standard/Math/Algorithm.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ define (function ()
},
clamp: function (value, min, max)
{
return value < min ? min : (value > max ? max : value);
// http://jsperf.com/math-clamp
// http://jsperf.com/clamping-methods/2
return Math .min (max, Math .max (min, value));
},
interval: function (value, low, high)
{
Expand Down
182 changes: 94 additions & 88 deletions src/x_ite/Components/Navigation/X3DViewpointNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ function (Fields,
{
"use strict";

var
relativePosition = new Vector3 (0, 0, 0),
relativeOrientation = new Rotation4 (0, 0, 1, 0),
relativeScale = new Vector3 (0, 0, 0),
relativeScaleOrientation = new Rotation4 (0, 0, 1, 0);

var
localXAxis = new Vector3 (0, 0, 0),
localZAxis = new Vector3 (0, 0, 0),
vector = new Vector3 (0, 0, 0),
rotation = new Rotation4 (0, 0, 1, 0);

function X3DViewpointNode (executionContext)
{
X3DBindableNode .call (this, executionContext);
Expand Down Expand Up @@ -231,86 +219,95 @@ function (Fields,
{
return 1e5;
},
transitionStart: function (fromViewpoint)
transitionStart: (function ()
{
try
var
relativePosition = new Vector3 (0, 0, 0),
relativeOrientation = new Rotation4 (0, 0, 1, 0),
relativeScale = new Vector3 (0, 0, 0),
relativeScaleOrientation = new Rotation4 (0, 0, 1, 0);

return function (fromViewpoint)
{
if (this .jump_ .getValue ())
try
{
var layers = this .getLayers ();

if (! this .retainUserOffsets_ .getValue ())
this .resetUserOffsets ();

for (var i = 0; i < layers .length; ++ i)
{
var navigationInfo = layers [i] .getNavigationInfo ();

navigationInfo .transitionStart_ = true;

var
transitionType = navigationInfo .getTransitionType (),
transitionTime = navigationInfo .transitionTime_ .getValue ();
}

switch (transitionType)
if (this .jump_ .getValue ())
{
case "TELEPORT":
{
for (var i = 0; i < layers .length; ++ i)
layers [i] .getNavigationInfo () .transitionComplete_ = true;

return;
}
case "ANIMATE":
var layers = this .getLayers ();

if (! this .retainUserOffsets_ .getValue ())
this .resetUserOffsets ();

for (var i = 0; i < layers .length; ++ i)
{
this .easeInEaseOut .easeInEaseOut_ = new Fields .MFVec2f (new Fields .SFVec2f (0, 1), new Fields .SFVec2f (1, 0));
break;
var navigationInfo = layers [i] .getNavigationInfo ();

navigationInfo .transitionStart_ = true;

var
transitionType = navigationInfo .getTransitionType (),
transitionTime = navigationInfo .transitionTime_ .getValue ();
}
default:

switch (transitionType)
{
// LINEAR
this .easeInEaseOut .easeInEaseOut_ = new Fields .MFVec2f (new Fields .SFVec2f (0, 0), new Fields .SFVec2f (0, 0));
break;
case "TELEPORT":
{
for (var i = 0; i < layers .length; ++ i)
layers [i] .getNavigationInfo () .transitionComplete_ = true;

return;
}
case "ANIMATE":
{
this .easeInEaseOut .easeInEaseOut_ = new Fields .MFVec2f (new Fields .SFVec2f (0, 1), new Fields .SFVec2f (1, 0));
break;
}
default:
{
// LINEAR
this .easeInEaseOut .easeInEaseOut_ = new Fields .MFVec2f (new Fields .SFVec2f (0, 0), new Fields .SFVec2f (0, 0));
break;
}
}

this .timeSensor .cycleInterval_ = transitionTime;
this .timeSensor .stopTime_ = this .getBrowser () .getCurrentTime ();
this .timeSensor .startTime_ = this .getBrowser () .getCurrentTime ();
this .timeSensor .isActive_ .addInterest ("set_active__", this);

this .getRelativeTransformation (fromViewpoint, relativePosition, relativeOrientation, relativeScale, relativeScaleOrientation);

this .positionInterpolator .keyValue_ = new Fields .MFVec3f (relativePosition, this .positionOffset_);
this .orientationInterpolator .keyValue_ = new Fields .MFRotation (relativeOrientation, this .orientationOffset_);
this .scaleInterpolator .keyValue_ = new Fields .MFVec3f (relativeScale, this .scaleOffset_);
this .scaleOrientationInterpolator .keyValue_ = new Fields .MFRotation (relativeScaleOrientation, this .scaleOrientationOffset_);

this .positionOffset_ = relativePosition;
this .orientationOffset_ = relativeOrientation;
this .scaleOffset_ = relativeScale;
this .scaleOrientationOffset_ = relativeScaleOrientation;

this .setInterpolators (fromViewpoint);
}
else
{
this .getRelativeTransformation (fromViewpoint, relativePosition, relativeOrientation, relativeScale, relativeScaleOrientation);

this .positionOffset_ = relativePosition;
this .orientationOffset_ = relativeOrientation;
this .scaleOffset_ = relativeScale;
this .scaleOrientationOffset_ = relativeScaleOrientation;

this .setInterpolators (fromViewpoint);
}

this .timeSensor .cycleInterval_ = transitionTime;
this .timeSensor .stopTime_ = this .getBrowser () .getCurrentTime ();
this .timeSensor .startTime_ = this .getBrowser () .getCurrentTime ();
this .timeSensor .isActive_ .addInterest ("set_active__", this);

this .getRelativeTransformation (fromViewpoint, relativePosition, relativeOrientation, relativeScale, relativeScaleOrientation);

this .positionInterpolator .keyValue_ = new Fields .MFVec3f (relativePosition, this .positionOffset_);
this .orientationInterpolator .keyValue_ = new Fields .MFRotation (relativeOrientation, this .orientationOffset_);
this .scaleInterpolator .keyValue_ = new Fields .MFVec3f (relativeScale, this .scaleOffset_);
this .scaleOrientationInterpolator .keyValue_ = new Fields .MFRotation (relativeScaleOrientation, this .scaleOrientationOffset_);

this .positionOffset_ = relativePosition;
this .orientationOffset_ = relativeOrientation;
this .scaleOffset_ = relativeScale;
this .scaleOrientationOffset_ = relativeScaleOrientation;

this .setInterpolators (fromViewpoint);
}
else
catch (error)
{
this .getRelativeTransformation (fromViewpoint, relativePosition, relativeOrientation, relativeScale, relativeScaleOrientation);

this .positionOffset_ = relativePosition;
this .orientationOffset_ = relativeOrientation;
this .scaleOffset_ = relativeScale;
this .scaleOrientationOffset_ = relativeScaleOrientation;

this .setInterpolators (fromViewpoint);
console .log (error);
}
}
catch (error)
{
console .log (error);
}
},
})(),
transitionStop: function ()
{
this .timeSensor .stopTime_ = this .getBrowser () .getCurrentTime ();
Expand All @@ -335,17 +332,26 @@ function (Fields,
relativePosition .subtract (this .getPosition ());
relativeOrientation .assign (this .getOrientation () .copy () .inverse () .multRight (relativeOrientation));
},
straightenHorizon: function (orientation)
straightenHorizon: (function ()
{
orientation .multVecRot (localXAxis .assign (Vector3 .xAxis) .negate ());
orientation .multVecRot (localZAxis .assign (Vector3 .zAxis));

vector .assign (localZAxis) .cross (this .getUpVector ());

rotation .setFromToVec (localXAxis, vector);
var
localXAxis = new Vector3 (0, 0, 0),
localZAxis = new Vector3 (0, 0, 0),
vector = new Vector3 (0, 0, 0),
rotation = new Rotation4 (0, 0, 1, 0);

return orientation .multRight (rotation);
},
return function (orientation)
{
orientation .multVecRot (localXAxis .assign (Vector3 .xAxis) .negate ());
orientation .multVecRot (localZAxis .assign (Vector3 .zAxis));

vector .assign (localZAxis) .cross (this .getUpVector ());

rotation .setFromToVec (localXAxis, vector);

return orientation .multRight (rotation);
}
})(),
lookAtPoint: function (point, factor, straighten)
{
try
Expand Down

0 comments on commit 4289088

Please sign in to comment.