Skip to content

Commit

Permalink
Migrate constants to F64
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartl committed Feb 22, 2018
1 parent c75f7ee commit c0a94be
Show file tree
Hide file tree
Showing 180 changed files with 2,762 additions and 2,675 deletions.
12 changes: 6 additions & 6 deletions BEPUik/ActiveSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public Fix64 AutomassUnstressedFalloff
get { return automassUnstressedFalloff; }
set
{
automassUnstressedFalloff = MathHelper.Max(value, 0);
automassUnstressedFalloff = MathHelper.Max(value, F64.C0);
}
}

private Fix64 automassTarget = 1;
private Fix64 automassTarget = F64.C1;
/// <summary>
/// Gets or sets the mass that the heaviest bones will have when automass is enabled.
/// </summary>
Expand All @@ -61,7 +61,7 @@ public Fix64 AutomassTarget
get { return automassTarget; }
set
{
if (value <= 0)
if (value <= F64.C0)
throw new ArgumentException("Mass must be positive.");
automassTarget = value;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ void DistributeMass(Bone bone)
//We distribute a portion of the current bone's total mass to the child bones.
//By applying a multiplier automassUnstressedFalloff, we guarantee that a chain has a certain maximum weight (excluding cycles).
//This is thanks to the convergent geometric series sum(automassUnstressedFalloff^n, 1, infinity).
Fix64 massPerChild = uniqueChildren.Count > 0 ? automassUnstressedFalloff * bone.Mass / uniqueChildren.Count : 0;
Fix64 massPerChild = uniqueChildren.Count > 0 ? automassUnstressedFalloff * bone.Mass / uniqueChildren.Count : F64.C0;

uniqueChildren.Clear();
//(If the number of children is 0, then the only bones which can exist are either bones which were already traversed and will be skipped
Expand Down Expand Up @@ -371,7 +371,7 @@ void DistributeMass(List<Control> controls)
lowestInverseMass = bone.inverseMass;
}

Fix64 inverseMassScale = 1 / (AutomassTarget * lowestInverseMass);
Fix64 inverseMassScale = F64.C1 / (AutomassTarget * lowestInverseMass);

foreach (var bone in bones)
{
Expand Down Expand Up @@ -399,7 +399,7 @@ public void Clear()
bones[i].IsActive = false;
bones[i].stressCount = 0;
bones[i].predecessors.Clear();
bones[i].Mass = Fix64Utils.PointZeroOne;
bones[i].Mass = F64.C0p01;
}
for (int i = 0; i < joints.Count; i++)
{
Expand Down
3 changes: 2 additions & 1 deletion BEPUik/AngularPlaneControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FixMath.NET;
using BEPUutilities;

namespace BEPUik
{
Expand Down Expand Up @@ -31,7 +32,7 @@ public SingleBoneAngularPlaneConstraint AngularMotor
public AngularPlaneControl()
{
AngularMotor = new SingleBoneAngularPlaneConstraint();
AngularMotor.Rigidity = 1;
AngularMotor.Rigidity = F64.C1;
}

protected internal override void Preupdate(Fix64 dt, Fix64 updateRate)
Expand Down
18 changes: 9 additions & 9 deletions BEPUik/Bone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public class Bone
/// </summary>
public Fix64 Mass
{
get { return 1 / inverseMass; }
get { return F64.C1 / inverseMass; }
set
{
//Long chains could produce exceptionally small values.
//Attempting to invert them would result in NaNs.
//Clamp the lowest mass to 1e-7f.
if (value > Toolbox.Epsilon)
inverseMass = 1 / value;
inverseMass = F64.C1 / value;
else
inverseMass = (Fix64)1e7m;
ComputeLocalInertiaTensor();
Expand Down Expand Up @@ -124,10 +124,10 @@ public Fix64 HalfHeight
/// </summary>
public Fix64 Height
{
get { return halfHeight * 2; }
get { return halfHeight * F64.C2; }
set
{
halfHeight = value / 2;
halfHeight = value / F64.C2;
ComputeLocalInertiaTensor();
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public Bone(Vector3 position, Quaternion orientation, Fix64 radius, Fix64 height
/// <param name="height">Height of the bone.</param>
public Bone(Vector3 position, Quaternion orientation, Fix64 radius, Fix64 height)
{
Mass = 1;
Mass = F64.C1;
Position = position;
Orientation = orientation;
Radius = radius;
Expand All @@ -167,9 +167,9 @@ void ComputeLocalInertiaTensor()
{
var localInertiaTensor = new Matrix3x3();
var multiplier = Mass * InertiaTensorScaling;
Fix64 diagValue = (Fix64Utils.PointZeroEightThrees * Height * Height + Fix64Utils.PointTwoFive * Radius * Radius) * multiplier;
Fix64 diagValue = (F64.C0p0833333333 * Height * Height + F64.C0p25 * Radius * Radius) * multiplier;
localInertiaTensor.M11 = diagValue;
localInertiaTensor.M22 = Fix64Utils.PointFive * Radius * Radius * multiplier;
localInertiaTensor.M22 = F64.C0p5 * Radius * Radius * multiplier;
localInertiaTensor.M33 = diagValue;
Matrix3x3.Invert(ref localInertiaTensor, out localInertiaTensorInverse);
}
Expand Down Expand Up @@ -197,8 +197,8 @@ internal void UpdatePosition()

//Update the orientation based on the angular velocity.
Vector3 increment;
Vector3.Multiply(ref angularVelocity, Fix64Utils.PointFive, out increment);
var multiplier = new Quaternion(increment.X, increment.Y, increment.Z, 0);
Vector3.Multiply(ref angularVelocity, F64.C0p5, out increment);
var multiplier = new Quaternion(increment.X, increment.Y, increment.Z, F64.C0);
Quaternion.Multiply(ref multiplier, ref Orientation, out multiplier);
Quaternion.Add(ref Orientation, ref multiplier, out Orientation);
Orientation.Normalize();
Expand Down
3 changes: 2 additions & 1 deletion BEPUik/DragControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FixMath.NET;
using BEPUutilities;

namespace BEPUik
{
Expand Down Expand Up @@ -31,7 +32,7 @@ public SingleBoneLinearMotor LinearMotor
public DragControl()
{
LinearMotor = new SingleBoneLinearMotor();
LinearMotor.Rigidity = 1;
LinearMotor.Rigidity = F64.C1;
}

protected internal override void Preupdate(Fix64 dt, Fix64 updateRate)
Expand Down
2 changes: 1 addition & 1 deletion BEPUik/IKAngularJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public IKAngularJoint(Bone connectionA, Bone connectionB)
protected internal override void UpdateJacobiansAndVelocityBias()
{
linearJacobianA = linearJacobianB = new Matrix3x3();
angularJacobianA = new Matrix3x3 { M11 = 1, M22 = 1, M33 = 1 };
angularJacobianA = new Matrix3x3 { M11 = F64.C1, M22 = F64.C1, M33 = F64.C1 };
angularJacobianB = new Matrix3x3 { M11 = -1, M22 = -1, M33 = -1 };

//The error is computed using this equation:
Expand Down
8 changes: 4 additions & 4 deletions BEPUik/IKConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class IKConstraint
/// </remarks>
private readonly Fix64 StiffnessOverDamping = (Fix64)0.25m;

private Fix64 rigidity = 16;
private Fix64 rigidity = F64.C16;
/// <summary>
/// Gets the rigidity of the constraint. Higher values correspond to more rigid constraints, lower values to less rigid constraints. Must be positive.
/// </summary>
Expand All @@ -37,7 +37,7 @@ public Fix64 Rigidity
}
set
{
if (value <= 0)
if (value <= F64.C0)
throw new ArgumentException("Rigidity must be positive.");
rigidity = value;
}
Expand All @@ -55,7 +55,7 @@ public Fix64 MaximumForce
get { return maximumForce; }
set
{
maximumForce = MathHelper.Max(value, 0);
maximumForce = MathHelper.Max(value, F64.C0);
}
}

Expand All @@ -68,7 +68,7 @@ protected internal void Preupdate(Fix64 dt, Fix64 updateRate)
{
Fix64 stiffness = StiffnessOverDamping * rigidity;
Fix64 damping = rigidity;
Fix64 multiplier = 1 / (dt * stiffness + damping);
Fix64 multiplier = F64.C1 / (dt * stiffness + damping);
errorCorrectionFactor = stiffness * multiplier;
softness = updateRate * multiplier;
maximumImpulse = maximumForce * dt;
Expand Down
4 changes: 2 additions & 2 deletions BEPUik/IKDistanceJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Vector3 AnchorB
public Fix64 Distance
{
get { return distance; }
set { distance = MathHelper.Max(0, value); }
set { distance = MathHelper.Max(F64.C0, value); }
}

/// <summary>
Expand Down Expand Up @@ -87,7 +87,7 @@ protected internal override void UpdateJacobiansAndVelocityBias()
linearA.Y = separation.Y / currentDistance;
linearA.Z = separation.Z / currentDistance;

velocityBias = new Vector3(errorCorrectionFactor * (currentDistance - distance), 0, 0);
velocityBias = new Vector3(errorCorrectionFactor * (currentDistance - distance), F64.C0, F64.C0);
}
else
{
Expand Down
14 changes: 7 additions & 7 deletions BEPUik/IKDistanceLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Vector3 AnchorB
public Fix64 MinimumDistance
{
get { return minimumDistance; }
set { minimumDistance = MathHelper.Max(0, value); }
set { minimumDistance = MathHelper.Max(F64.C0, value); }
}

private Fix64 maximumDistance;
Expand All @@ -53,7 +53,7 @@ public Fix64 MinimumDistance
public Fix64 MaximumDistance
{
get { return maximumDistance; }
set { maximumDistance = MathHelper.Max(0, value); }
set { maximumDistance = MathHelper.Max(F64.C0, value); }
}

/// <summary>
Expand Down Expand Up @@ -103,24 +103,24 @@ protected internal override void UpdateJacobiansAndVelocityBias()
if (currentDistance > maximumDistance)
{
//We are exceeding the maximum limit.
velocityBias = new Vector3(errorCorrectionFactor * (currentDistance - maximumDistance), 0, 0);
velocityBias = new Vector3(errorCorrectionFactor * (currentDistance - maximumDistance), F64.C0, F64.C0);
}
else if (currentDistance < minimumDistance)
{
//We are exceeding the minimum limit.
velocityBias = new Vector3(errorCorrectionFactor * (minimumDistance - currentDistance), 0, 0);
velocityBias = new Vector3(errorCorrectionFactor * (minimumDistance - currentDistance), F64.C0, F64.C0);
//The limit can only push in one direction. Flip the jacobian!
Vector3.Negate(ref linearA, out linearA);
}
else if (currentDistance - minimumDistance > (maximumDistance - minimumDistance) * Fix64Utils.PointFive)
else if (currentDistance - minimumDistance > (maximumDistance - minimumDistance) * F64.C0p5)
{
//The objects are closer to hitting the maximum limit.
velocityBias = new Vector3(currentDistance - maximumDistance, 0, 0);
velocityBias = new Vector3(currentDistance - maximumDistance, F64.C0, F64.C0);
}
else
{
//The objects are closer to hitting the minimum limit.
velocityBias = new Vector3(minimumDistance - currentDistance, 0, 0);
velocityBias = new Vector3(minimumDistance - currentDistance, F64.C0, F64.C0);
//The limit can only push in one direction. Flip the jacobian!
Vector3.Negate(ref linearA, out linearA);
}
Expand Down
6 changes: 3 additions & 3 deletions BEPUik/IKJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ protected internal override void ComputeEffectiveMass()

//Incorporate the constraint softness into the effective mass denominator. This pushes the matrix away from singularity.
//Softness will also be incorporated into the velocity solve iterations to complete the implementation.
if (effectiveMass.M11 != 0)
if (effectiveMass.M11 != F64.C0)
effectiveMass.M11 += softness;
if (effectiveMass.M22 != 0)
if (effectiveMass.M22 != F64.C0)
effectiveMass.M22 += softness;
if (effectiveMass.M33 != 0)
if (effectiveMass.M33 != F64.C0)
effectiveMass.M33 += softness;

//Invert! Takes us from J * M^-1 * JT to 1 / (J * M^-1 * JT).
Expand Down
10 changes: 5 additions & 5 deletions BEPUik/IKLinearAxisLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,24 @@ protected internal override void UpdateJacobiansAndVelocityBias()
if (currentDistance > maximumDistance)
{
//We are exceeding the maximum limit.
velocityBias = new Vector3(errorCorrectionFactor * (currentDistance - maximumDistance), 0, 0);
velocityBias = new Vector3(errorCorrectionFactor * (currentDistance - maximumDistance), F64.C0, F64.C0);
}
else if (currentDistance < minimumDistance)
{
//We are exceeding the minimum limit.
velocityBias = new Vector3(errorCorrectionFactor * (minimumDistance - currentDistance), 0, 0);
velocityBias = new Vector3(errorCorrectionFactor * (minimumDistance - currentDistance), F64.C0, F64.C0);
//The limit can only push in one direction. Flip the jacobian!
Vector3.Negate(ref lineDirection, out lineDirection);
}
else if (currentDistance - minimumDistance > (maximumDistance - minimumDistance) * Fix64Utils.PointFive)
else if (currentDistance - minimumDistance > (maximumDistance - minimumDistance) * F64.C0p5)
{
//The objects are closer to hitting the maximum limit.
velocityBias = new Vector3(currentDistance - maximumDistance, 0, 0);
velocityBias = new Vector3(currentDistance - maximumDistance, F64.C0, F64.C0);
}
else
{
//The objects are closer to hitting the minimum limit.
velocityBias = new Vector3(minimumDistance - currentDistance, 0, 0);
velocityBias = new Vector3(minimumDistance - currentDistance, F64.C0, F64.C0);
//The limit can only push in one direction. Flip the jacobian!
Vector3.Negate(ref lineDirection, out lineDirection);
}
Expand Down
2 changes: 1 addition & 1 deletion BEPUik/IKPointOnPlaneJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected internal override void UpdateJacobiansAndVelocityBias()
//This entire constraint is very similar to the IKDistanceLimit, except the current distance is along an axis.
Fix64 currentDistance;
Vector3.Dot(ref separation, ref lineDirection, out currentDistance);
velocityBias = new Vector3(errorCorrectionFactor * currentDistance, 0, 0);
velocityBias = new Vector3(errorCorrectionFactor * currentDistance, F64.C0, F64.C0);

//Compute jacobians
Vector3 angularA, angularB;
Expand Down
8 changes: 4 additions & 4 deletions BEPUik/IKSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class IKSolver : IDisposable
/// </summary>
public Fix64 AutoscaleControlMaximumForce { get; set; }

private Fix64 timeStepDuration = 1;
private Fix64 timeStepDuration = F64.C1;
/// <summary>
/// Gets or sets the time step duration elapsed by each position iteration.
/// </summary>
Expand All @@ -59,7 +59,7 @@ public Fix64 TimeStepDuration
get { return timeStepDuration; }
set
{
if (value <= 0)
if (value <= F64.C0)
throw new ArgumentException("Time step duration must be positive.");
timeStepDuration = value;
}
Expand Down Expand Up @@ -92,7 +92,7 @@ public void Solve(List<IKJoint> joints)
//Reset the permutation index; every solve should proceed in exactly the same order.
permutationMapper.PermutationIndex = 0;

Fix64 updateRate = 1 / TimeStepDuration;
Fix64 updateRate = F64.C1 / TimeStepDuration;
foreach (var joint in ActiveSet.joints)
{
joint.Preupdate(TimeStepDuration, updateRate);
Expand Down Expand Up @@ -162,7 +162,7 @@ public void Solve(List<Control> controls)
//Reset the permutation index; every solve should proceed in exactly the same order.
permutationMapper.PermutationIndex = 0;

Fix64 updateRate = 1 / TimeStepDuration;
Fix64 updateRate = F64.C1 / TimeStepDuration;
foreach (var joint in ActiveSet.joints)
{
joint.Preupdate(TimeStepDuration, updateRate);
Expand Down
8 changes: 4 additions & 4 deletions BEPUik/IKSwingLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Vector3 AxisB
public Fix64 MaximumAngle
{
get { return maximumAngle; }
set { maximumAngle = MathHelper.Max(0, value); }
set { maximumAngle = MathHelper.Max(F64.C0, value); }
}


Expand Down Expand Up @@ -79,7 +79,7 @@ protected internal override void UpdateJacobiansAndVelocityBias()

//Yes, we could avoid this acos here. Performance is not the highest goal of this system; the less tricks used, the easier it is to understand.
// TODO investigate performance
Fix64 angle = Fix64.Acos(MathHelper.Clamp(dot, -1, 1));
Fix64 angle = Fix64.Acos(MathHelper.Clamp(dot, -1, F64.C1));

//One angular DOF is constrained by this limit.
Vector3 hingeAxis;
Expand All @@ -92,13 +92,13 @@ protected internal override void UpdateJacobiansAndVelocityBias()
//This is to enable 'speculative' limits.
if (angle >= maximumAngle)
{
velocityBias = new Vector3(errorCorrectionFactor * (angle - maximumAngle), 0, 0);
velocityBias = new Vector3(errorCorrectionFactor * (angle - maximumAngle), F64.C0, F64.C0);
}
else
{
//The constraint is not yet violated. But, it may be- allow only as much motion as could occur without violating the constraint.
//Limits can't 'pull,' so this will not result in erroneous sticking.
velocityBias = new Vector3(angle - maximumAngle, 0, 0);
velocityBias = new Vector3(angle - maximumAngle, F64.C0, F64.C0);
}


Expand Down
4 changes: 2 additions & 2 deletions BEPUik/IKSwivelHingeJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ protected internal override void UpdateJacobiansAndVelocityBias()

Fix64 error;
Vector3.Dot(ref worldHingeAxis, ref worldTwistAxis, out error);
error = Fix64.Acos(MathHelper.Clamp(error, -1, 1)) - MathHelper.PiOver2;
error = Fix64.Acos(MathHelper.Clamp(error, -1, F64.C1)) - MathHelper.PiOver2;

velocityBias = new Vector3(errorCorrectionFactor * error, 0, 0);
velocityBias = new Vector3(errorCorrectionFactor * error, F64.C0, F64.C0);


}
Expand Down
Loading

0 comments on commit c0a94be

Please sign in to comment.