private static Vector2 ComputeBuouyancyAcceleration(Rect frogRect, float frogDensity, PondSimState pondState)
        {
            float volumePercentage = (pondState.WaterLevel - frogRect.MinY) / (frogRect.Height);

            volumePercentage = MathExtensions.Clamp01(volumePercentage);
            return((frogDensity - volumePercentage) * PondSimState.kGravity);
        }
        private float ComputeVelocityRotation(float heightAboveWater)
        {
            float relativeHeight = MathExtensions.Clamp01((heightAboveWater - mFlyData.MinHeight) / (mFlyData.MaxHeight - mFlyData.MinHeight));
            float halfRange      = mChangeData.MaxDelta;
            float rangeOffset    = halfRange * (-2f * relativeHeight + 1f);

            return(rangeOffset + mRandom.GetRandomInRange(-halfRange, halfRange));
        }
Exemple #3
0
        private void UpdateLandedFrogs(EntityRegistry registry)
        {
            int count = mLandedFrogs.Frogs.Count;

            for (int i = 0; i < count; ++i)
            {
                Entity           frog         = mLandedFrogs.Frogs[i];
                Landed           landed       = mLandedFrogs.Landed[i];
                FrogControlState controlState = mLandedFrogs.ControlState[i];
                if (controlState.InputDirection.Y >= 0f)
                {
                    if (controlState.JumpSignal)
                    {
                        float newJumpPercentage = landed.RelativeJumpPower + (mTime.DeltaTime / mJumpData.JumpPrepareTime);
                        landed.RelativeJumpPower = MathExtensions.Clamp01(newJumpPercentage);
                    }
                    else if (landed.RelativeJumpPower != 0f)
                    {
                        Facing  facing           = mLandedFrogs.Facing[i]; //For rare cases, should I fetch this from the registry instead?
                        Vector2 blessedDirection = BestBlessedDirection(controlState.InputDirection, facing.CurrentFacing);
                        Vector2 jumpVelocity     = (landed.RelativeJumpPower * mJumpData.JumpSpeed) * blessedDirection;
                        registry.SetComponent(frog, new Velocity(jumpVelocity));
                        mJumpingFrogs.Add(frog);
                    }
                }
                else
                {
                    landed.RelativeJumpPower = 0f;
                }
                registry.SetComponent(frog, landed);
            }
            foreach (Entity frog in mJumpingFrogs)
            {
                registry.RemoveComponent <Landed>(frog);
            }
            mJumpingFrogs.Clear();
        }
Exemple #4
0
 /// <summary>
 /// Creates a new color from the vector.
 /// </summary>
 /// <param name="vector">Vector</param>
 /// <returns></returns>
 public static FloatColor FromVectorSafe(Vector3 vector)
 {
     vector = vector.Normalize();
     vector = new Vector3(MathExtensions.Clamp01(vector.X), MathExtensions.Clamp01(vector.Y), MathExtensions.Clamp01(vector.Z));
     return(new FloatColor(vector.X, vector.Y, vector.Z));
 }
Exemple #5
0
 public static FloatColor Lerp(FloatColor a, FloatColor b, float t)
 {
     t = MathExtensions.Clamp01(t);
     return(LerpUnclamped(a, b, t));
 }