Exemple #1
0
    private bool CheckChanges(bool hasMotor, Transform parent)
    {
        if (this.hadMotor == hasMotor && !(this.otherParent != parent))
        {
            return(false);
        }
        this.hadMotor            = hasMotor;
        this.groundLocalVelocity = new Vector3G();
        this.groundWorldVelocity = new Vector3G();
        this.localVelocity       = new Vector3G();
        this.worldVelocity       = new Vector3G();
        this.impulseForce        = new HeadBob.VectorAccelSampler();
        this.impulseTorque       = new HeadBob.VectorAccelSampler();
        this.lastPosition        = new HeadBob.VectorStamp();
        this.otherParent         = parent;
        this.raw_pos             = new Vector3G();
        this.raw_rot             = new Vector3G();
        BobEffectStack bobEffectStack = this.predicted.stack;

        this.predicted = new HeadBob.Weight()
        {
            stack = bobEffectStack
        };
        bobEffectStack = this.working.stack;
        this.working   = new HeadBob.Weight()
        {
            stack = bobEffectStack
        };
        return(true);
    }
Exemple #2
0
 public void CopyTo(ref HeadBob.Weight other)
 {
     if ((other.additionalPositions != this.additionalPositions) && (this.additionalPositions != null))
     {
         Array.Copy(this.additionalPositions, other.additionalPositions, this.additionalPositions.Length);
     }
     other.rotation = this.rotation;
     other.position = this.position;
     if ((other.stack != null) && other.stack.IsForkOf(this.stack))
     {
         other.stack.Join();
     }
 }
Exemple #3
0
    private void Solve(ref HeadBob.Weight weight, ref double dt)
    {
        Vector3G vector3G = new Vector3G();
        double   num;

        vector3G.x = dt * this.groundLocalVelocity.x * (double)this.cfg.forceSpeedMultiplier.x;
        vector3G.y = dt * this.groundLocalVelocity.y * (double)this.cfg.forceSpeedMultiplier.y;
        vector3G.z = dt * this.groundLocalVelocity.z * (double)this.cfg.forceSpeedMultiplier.z;
        Vector3G vector3G1 = weight.position.fE;
        Vector3G vector3G2 = weight.rotation.fE;
        Vector3G vector3G3 = new Vector3G();

        weight.position.fE = vector3G3;
        Vector3G vector3G4 = new Vector3G();

        weight.rotation.fE = vector3G4;
        if (this.anyAdditionalCurves)
        {
            for (int i = 0; i < this.additionalCurveCount; i++)
            {
                BobForceCurve bobForceCurve = this.cfg.additionalCurves[i];
                switch (bobForceCurve.source)
                {
                case BobForceCurveSource.LocalMovementMagnitude:
                {
                    num = this.groundLocalVelocityMag;
                    break;
                }

                case BobForceCurveSource.LocalMovementX:
                {
                    num = this.groundLocalVelocity.x;
                    break;
                }

                case BobForceCurveSource.LocalMovementY:
                {
                    num = this.groundLocalVelocity.y;
                    break;
                }

                case BobForceCurveSource.LocalMovementZ:
                {
                    num = this.groundLocalVelocity.z;
                    break;
                }

                case BobForceCurveSource.WorldMovementMagnitude:
                {
                    num = this.groundWorldVelocityMag;
                    break;
                }

                case BobForceCurveSource.WorldMovementX:
                {
                    num = this.groundWorldVelocity.x;
                    break;
                }

                case BobForceCurveSource.WorldMovementY:
                {
                    num = this.groundWorldVelocity.y;
                    break;
                }

                case BobForceCurveSource.WorldMovementZ:
                {
                    num = this.groundWorldVelocity.z;
                    break;
                }

                case BobForceCurveSource.LocalVelocityMagnitude:
                {
                    num = this.localVelocityMag;
                    break;
                }

                case BobForceCurveSource.LocalVelocityX:
                {
                    num = this.localVelocity.x;
                    break;
                }

                case BobForceCurveSource.LocalVelocityY:
                {
                    num = this.localVelocity.y;
                    break;
                }

                case BobForceCurveSource.LocalVelocityZ:
                {
                    num = this.localVelocity.z;
                    break;
                }

                case BobForceCurveSource.WorldVelocityMagnitude:
                {
                    num = this.worldVelocityMag;
                    break;
                }

                case BobForceCurveSource.WorldVelocityX:
                {
                    num = this.worldVelocity.x;
                    break;
                }

                case BobForceCurveSource.WorldVelocityY:
                {
                    num = this.worldVelocity.y;
                    break;
                }

                case BobForceCurveSource.WorldVelocityZ:
                {
                    num = this.worldVelocity.z;
                    break;
                }

                case BobForceCurveSource.RotationMagnitude:
                {
                    num = this.localAngularVelocityMag;
                    break;
                }

                case BobForceCurveSource.RotationPitch:
                {
                    num = this.localAngularVelocity.x;
                    break;
                }

                case BobForceCurveSource.RotationYaw:
                {
                    num = this.localAngularVelocity.y;
                    break;
                }

                case BobForceCurveSource.RotationRoll:
                {
                    num = this.localAngularVelocity.z;
                    break;
                }

                case BobForceCurveSource.TurnMagnitude:
                {
                    num = this.groundLocalAngularVelocityMag;
                    break;
                }

                case BobForceCurveSource.TurnPitch:
                {
                    num = this.groundLocalAngularVelocity.x;
                    break;
                }

                case BobForceCurveSource.TurnYaw:
                {
                    num = this.groundLocalAngularVelocity.y;
                    break;
                }

                case BobForceCurveSource.TurnRoll:
                {
                    num = this.groundLocalAngularVelocity.z;
                    break;
                }

                default:
                {
                    goto case BobForceCurveSource.LocalVelocityZ;
                }
                }
                BobForceCurveTarget bobForceCurveTarget = bobForceCurve.target;
                if (bobForceCurveTarget != BobForceCurveTarget.Position)
                {
                    if (bobForceCurveTarget != BobForceCurveTarget.Rotation)
                    {
                        goto Label3;
                    }
                    bobForceCurve.Calculate(ref weight.additionalPositions[i], ref num, ref dt, ref weight.rotation.fE);
                    goto Label1;
                }
Label3:
                bobForceCurve.Calculate(ref weight.additionalPositions[i], ref num, ref dt, ref weight.position.fE);
Label1:
            }
        }
        if (this.cfg.impulseForceSmooth <= 0f)
        {
            weight.position.fI = this.impulseForce.accel;
        }
        else
        {
            Vector3G.SmoothDamp(ref weight.position.fI, ref this.impulseForce.accel, ref weight.position.fIV, this.cfg.impulseForceSmooth, this.cfg.impulseForceMaxChangeAcceleration, ref dt);
        }
        if (this.cfg.angleImpulseForceSmooth <= 0f)
        {
            weight.rotation.fI = this.impulseTorque.accel;
        }
        else
        {
            Vector3G.SmoothDamp(ref weight.rotation.fI, ref this.impulseTorque.accel, ref weight.rotation.fIV, this.cfg.angleImpulseForceSmooth, this.cfg.angleImpulseForceMaxChangeAcceleration, ref dt);
        }
        weight.position.fE.x = weight.position.fE.x + (this.inputForce.x + weight.position.fI.x * (double)this.cfg.impulseForceScale.x);
        weight.position.fE.y = weight.position.fE.y + (this.inputForce.y + weight.position.fI.y * (double)this.cfg.impulseForceScale.y);
        weight.position.fE.z = weight.position.fE.z + (this.inputForce.z + weight.position.fI.z * (double)this.cfg.impulseForceScale.z);
        weight.rotation.fE.x = weight.rotation.fE.x + weight.rotation.fI.x * (double)this.cfg.angularImpulseForceScale.x;
        weight.rotation.fE.y = weight.rotation.fE.y + weight.rotation.fI.y * (double)this.cfg.angularImpulseForceScale.y;
        weight.rotation.fE.z = weight.rotation.fE.z + weight.rotation.fI.z * (double)this.cfg.angularImpulseForceScale.z;
        Vector3G vector3G5 = weight.position.@value;

        vector3G5.x = vector3G5.x / (double)this.cfg.elipsoidRadii.x;
        vector3G5.y = vector3G5.y / (double)this.cfg.elipsoidRadii.y;
        vector3G5.z = vector3G5.z / (double)this.cfg.elipsoidRadii.z;
        double num1 = vector3G5.x * vector3G5.x + vector3G5.y * vector3G5.y + vector3G5.z * vector3G5.z;

        if (num1 > 1)
        {
            num1        = 1 / Math.Sqrt(num1);
            vector3G5.x = vector3G5.x * num1;
            vector3G5.y = vector3G5.y * num1;
            vector3G5.z = vector3G5.z * num1;
        }
        vector3G5.x = vector3G5.x * (double)this.cfg.elipsoidRadii.x;
        vector3G5.y = vector3G5.y * (double)this.cfg.elipsoidRadii.y;
        vector3G5.z = vector3G5.z * (double)this.cfg.elipsoidRadii.z;
        weight.stack.Simulate(ref dt, ref weight.position.fE, ref weight.rotation.fE);
        weight.position.acceleration.x = weight.position.fE.x - vector3G1.x + (vector3G5.x * (double)(-this.cfg.springConstant.x) - weight.position.velocity.x * (double)this.cfg.springDampen.x) * (double)this.cfg.weightMass;
        weight.position.acceleration.y = weight.position.fE.y - vector3G1.y + (vector3G5.y * (double)(-this.cfg.springConstant.y) - weight.position.velocity.y * (double)this.cfg.springDampen.y) * (double)this.cfg.weightMass;
        weight.position.acceleration.z = weight.position.fE.z - vector3G1.z + (vector3G5.z * (double)(-this.cfg.springConstant.z) - weight.position.velocity.z * (double)this.cfg.springDampen.z) * (double)this.cfg.weightMass;
        weight.position.velocity.x     = weight.position.velocity.x + weight.position.acceleration.x * dt;
        weight.position.velocity.y     = weight.position.velocity.y + weight.position.acceleration.y * dt;
        weight.position.velocity.z     = weight.position.velocity.z + weight.position.acceleration.z * dt;
        if (float.IsInfinity(this.cfg.maxVelocity.x))
        {
            [email protected] = [email protected] + weight.position.velocity.x * dt;
        }
        else if (weight.position.velocity.x < (double)(-this.cfg.maxVelocity.x))
        {
            [email protected] = [email protected] - (double)this.cfg.maxVelocity.x * dt;
        }
        else if (weight.position.velocity.x <= (double)this.cfg.maxVelocity.x)
        {
            [email protected] = [email protected] + weight.position.velocity.x * dt;
        }
        else
        {
            [email protected] = [email protected] + (double)this.cfg.maxVelocity.x * dt;
        }
        if (float.IsInfinity(this.cfg.maxVelocity.y))
        {
            [email protected] = [email protected] + weight.position.velocity.y * dt;
        }
        else if (weight.position.velocity.y < (double)(-this.cfg.maxVelocity.y))
        {
            [email protected] = [email protected] - (double)this.cfg.maxVelocity.y * dt;
        }
        else if (weight.position.velocity.y <= (double)this.cfg.maxVelocity.y)
        {
            [email protected] = [email protected] + weight.position.velocity.y * dt;
        }
        else
        {
            [email protected] = [email protected] + (double)this.cfg.maxVelocity.y * dt;
        }
        if (float.IsInfinity(this.cfg.maxVelocity.z))
        {
            [email protected] = [email protected] + weight.position.velocity.z * dt;
        }
        else if (weight.position.velocity.z < (double)(-this.cfg.maxVelocity.z))
        {
            [email protected] = [email protected] - (double)this.cfg.maxVelocity.z * dt;
        }
        else if (weight.position.velocity.z <= (double)this.cfg.maxVelocity.z)
        {
            [email protected] = [email protected] + weight.position.velocity.z * dt;
        }
        else
        {
            [email protected] = [email protected] + (double)this.cfg.maxVelocity.z * dt;
        }
        weight.rotation.acceleration.x = weight.rotation.fE.x - vector3G2.x + ([email protected] * (double)(-this.cfg.angularSpringConstant.x) - weight.rotation.velocity.x * (double)this.cfg.angularSpringDampen.x) * (double)this.cfg.angularWeightMass;
        weight.rotation.acceleration.y = weight.rotation.fE.y - vector3G2.y + ([email protected] * (double)(-this.cfg.angularSpringConstant.y) - weight.rotation.velocity.y * (double)this.cfg.angularSpringDampen.y) * (double)this.cfg.angularWeightMass;
        weight.rotation.acceleration.z = weight.rotation.fE.z - vector3G2.z + ([email protected] * (double)(-this.cfg.angularSpringConstant.z) - weight.rotation.velocity.z * (double)this.cfg.angularSpringDampen.z) * (double)this.cfg.angularWeightMass;
        weight.rotation.velocity.x     = weight.rotation.velocity.x + weight.rotation.acceleration.x * dt;
        weight.rotation.velocity.y     = weight.rotation.velocity.y + weight.rotation.acceleration.y * dt;
        weight.rotation.velocity.z     = weight.rotation.velocity.z + weight.rotation.acceleration.z * dt;
        [email protected]       = [email protected] + weight.rotation.velocity.x * dt;
        [email protected]       = [email protected] + weight.rotation.velocity.y * dt;
        [email protected]       = [email protected] + weight.rotation.velocity.z * dt;
    }
Exemple #4
0
    private int Step(float dt)
    {
        double  num;
        int     num1    = 0;
        int     num2    = 0;
        HeadBob headBob = this;

        headBob.timeSolve = headBob.timeSolve + (double)dt;
        double num3 = ((double)this.cfg.solveRate >= 0 ? 1 / (double)this.cfg.solveRate : 1 / -(double)this.cfg.solveRate);

        if ((double)this.cfg.intermitRate != 0)
        {
            num = ((double)this.cfg.intermitRate >= 0 ? 1 / (double)this.cfg.intermitRate : 1 / -(double)this.cfg.intermitRate);
        }
        else
        {
            num = 0;
        }
        double num4 = num;

        if (double.IsInfinity(num3) || num3 == 0)
        {
            num3 = this.timeSolve;
        }
        bool   flag = num4 > num3;
        double num5 = num3 * (double)this.cfg.timeScale;

        if (this.timeSolve >= num3)
        {
            do
            {
                HeadBob headBob1 = this;
                headBob1.timeSolve = headBob1.timeSolve - num3;
                if (flag)
                {
                    HeadBob headBob2 = this;
                    headBob2.timeIntermit = headBob2.timeIntermit - num3;
                    if (this.timeIntermit < 0)
                    {
                        this.intermitStart = this.working;
                    }
                }
                this.Solve(ref this.working, ref num5);
                if (flag && this.timeIntermit < 0)
                {
                    this.intermitNext     = this.working;
                    this.intermitFraction = (this.timeIntermit + num3) / num3;
                    HeadBob headBob3 = this;
                    headBob3.timeIntermit = headBob3.timeIntermit + num4;
                    num2++;
                }
                num1++;
            }while (this.timeSolve >= num3);
        }
        if (flag)
        {
            if (num2 > 0)
            {
                if (!this.simStep)
                {
                    this.raw_pos = this.intermitNext.position.@value;
                    this.raw_rot = this.intermitNext.rotation.@value;
                    this.CheckDeadZone();
                }
                else
                {
                    Vector3G.Lerp(ref this.intermitStart.position.@value, ref this.intermitNext.position.@value, ref this.intermitFraction, out this.raw_pos);
                    Vector3G.Lerp(ref this.intermitStart.rotation.@value, ref this.intermitNext.rotation.@value, ref this.intermitFraction, out this.raw_rot);
                    this.CheckDeadZone();
                }
            }
            return(num2);
        }
        if (!this.simStep)
        {
            this.raw_pos = this.working.position.@value;
            this.raw_rot = this.working.rotation.@value;
            this.CheckDeadZone();
        }
        else
        {
            this.working.CopyTo(ref this.predicted);
            this.Solve(ref this.predicted, ref num5);
            num1 = -(num1 + 1);
            double num6 = this.timeSolve / num3;
            Vector3G.Lerp(ref this.working.position.@value, ref this.predicted.position.@value, ref num6, out this.raw_pos);
            Vector3G.Lerp(ref this.working.rotation.@value, ref this.predicted.rotation.@value, ref num6, out this.raw_rot);
            this.CheckDeadZone();
        }
        return(num1);
    }
Exemple #5
0
 private int Step(float dt)
 {
     double num;
     int num1 = 0;
     int num2 = 0;
     HeadBob headBob = this;
     headBob.timeSolve = headBob.timeSolve + (double)dt;
     double num3 = ((double)this.cfg.solveRate >= 0 ? 1 / (double)this.cfg.solveRate : 1 / -(double)this.cfg.solveRate);
     if ((double)this.cfg.intermitRate != 0)
     {
         num = ((double)this.cfg.intermitRate >= 0 ? 1 / (double)this.cfg.intermitRate : 1 / -(double)this.cfg.intermitRate);
     }
     else
     {
         num = 0;
     }
     double num4 = num;
     if (double.IsInfinity(num3) || num3 == 0)
     {
         num3 = this.timeSolve;
     }
     bool flag = num4 > num3;
     double num5 = num3 * (double)this.cfg.timeScale;
     if (this.timeSolve >= num3)
     {
         do
         {
             HeadBob headBob1 = this;
             headBob1.timeSolve = headBob1.timeSolve - num3;
             if (flag)
             {
                 HeadBob headBob2 = this;
                 headBob2.timeIntermit = headBob2.timeIntermit - num3;
                 if (this.timeIntermit < 0)
                 {
                     this.intermitStart = this.working;
                 }
             }
             this.Solve(ref this.working, ref num5);
             if (flag && this.timeIntermit < 0)
             {
                 this.intermitNext = this.working;
                 this.intermitFraction = (this.timeIntermit + num3) / num3;
                 HeadBob headBob3 = this;
                 headBob3.timeIntermit = headBob3.timeIntermit + num4;
                 num2++;
             }
             num1++;
         }
         while (this.timeSolve >= num3);
     }
     if (flag)
     {
         if (num2 > 0)
         {
             if (!this.simStep)
             {
                 this.raw_pos = this.intermitNext.position.@value;
                 this.raw_rot = this.intermitNext.rotation.@value;
                 this.CheckDeadZone();
             }
             else
             {
                 Vector3G.Lerp(ref this.intermitStart.position.@value, ref this.intermitNext.position.@value, ref this.intermitFraction, out this.raw_pos);
                 Vector3G.Lerp(ref this.intermitStart.rotation.@value, ref this.intermitNext.rotation.@value, ref this.intermitFraction, out this.raw_rot);
                 this.CheckDeadZone();
             }
         }
         return num2;
     }
     if (!this.simStep)
     {
         this.raw_pos = this.working.position.@value;
         this.raw_rot = this.working.rotation.@value;
         this.CheckDeadZone();
     }
     else
     {
         this.working.CopyTo(ref this.predicted);
         this.Solve(ref this.predicted, ref num5);
         num1 = -(num1 + 1);
         double num6 = this.timeSolve / num3;
         Vector3G.Lerp(ref this.working.position.@value, ref this.predicted.position.@value, ref num6, out this.raw_pos);
         Vector3G.Lerp(ref this.working.rotation.@value, ref this.predicted.rotation.@value, ref num6, out this.raw_rot);
         this.CheckDeadZone();
     }
     return num1;
 }
Exemple #6
0
 private bool CheckChanges(bool hasMotor, Transform parent)
 {
     if (this.hadMotor == hasMotor && !(this.otherParent != parent))
     {
         return false;
     }
     this.hadMotor = hasMotor;
     this.groundLocalVelocity = new Vector3G();
     this.groundWorldVelocity = new Vector3G();
     this.localVelocity = new Vector3G();
     this.worldVelocity = new Vector3G();
     this.impulseForce = new HeadBob.VectorAccelSampler();
     this.impulseTorque = new HeadBob.VectorAccelSampler();
     this.lastPosition = new HeadBob.VectorStamp();
     this.otherParent = parent;
     this.raw_pos = new Vector3G();
     this.raw_rot = new Vector3G();
     BobEffectStack bobEffectStack = this.predicted.stack;
     this.predicted = new HeadBob.Weight()
     {
         stack = bobEffectStack
     };
     bobEffectStack = this.working.stack;
     this.working = new HeadBob.Weight()
     {
         stack = bobEffectStack
     };
     return true;
 }