public void Init(Intension intension, Perception perception, FishBody body)
        {
            this.motorControllers.Clear();

            var focusser = perception.GetFocuser();

            var normal = body.modelData.Normal;
            var left   = body.modelData.Left;
            var dir    = focusser.target.obj.obj.Position - body.modelData.GeometryCenter;

            var motorType = focusser.motorPreference.MaxValue.type;

            if (motorType == Focusser.MotorPreference.Type.MoveForward)
            {
                if (this.smc == null)
                {
                    this.smc    = new SwimMC();
                    this.curves = this.smc.ActivationData.ToAnimationCurves();
                }
                if (focusser.target.obj != null)
                {
                    this.smc.UpdateSpeed(focusser.target.obj.distance);
                }
                this.motorControllers.Add(this.smc);
            }
            else if (motorType == Focusser.MotorPreference.Type.TurnLeft)
            {
                if (this.tlmc == null)
                {
                    this.tlmc   = new TurnLeftMC();
                    this.curves = this.tlmc.ActivationData.ToAnimationCurves();
                }
                var angle = this.GetAngleInFish(dir, normal, left);
                this.tlmc.UpdateAngle(angle);
                this.motorControllers.Add(this.tlmc);

                this.smc?.UpdateSpeed(0);
            }
            else if (motorType == Focusser.MotorPreference.Type.TurnRight)
            {
                if (this.trmc == null)
                {
                    this.trmc   = new TurnRightMC();
                    this.curves = this.trmc.ActivationData.ToAnimationCurves();
                }
                var angle = this.GetAngleInFish(dir, normal, left);
                this.trmc.UpdateAngle(angle);
                this.motorControllers.Add(this.trmc);

                this.smc?.UpdateSpeed(0);
            }


            var balance = new BalanceMC();

            balance.UpdateBalance(left, normal);
            this.motorControllers.Add(balance);
        }
        protected void ApplyBehaviorRoutine(FishSimulator.Delta delta)
        {
            var types = new List <Spring.Type>()
            {
                Spring.Type.MuscleFront, Spring.Type.MuscleMiddle, Spring.Type.MuscleBack
            };

            // foreach (var mc in this.muscleMCs)
            var mc = this.muscleMCs.FirstOrDefault();

            if (mc != null)
            {
                var data = mc.ActivationData;

                foreach (var type in types)
                {
                    //get motor controller from brain
                    var parameter = mc.GetParameter(type);

                    data.ApplyActivation(delta.local, type, this.body.modelData, parameter);
                }
                if (data.IsDone)
                {
                    delta.local = 0;
                    this.muscleMCs.RemoveFirst();
                }
            }

            if (this.balanceMC != null)
            {
                var lfin = this.body.modelData.FishPectoralFins[0];
                var rfin = this.body.modelData.FishPectoralFins[1];

                lfin.Angle = math.lerp(lfin.Angle, this.balanceMC.lFin, 0.1f);
                rfin.Angle = math.lerp(rfin.Angle, this.balanceMC.rFin, 0.1f);
            }

            //Debug data
            var fmc = this.muscleMCs.FirstOrDefault();

            if (fmc != null)
            {
                if (fmc is SwimMC)
                {
                    this.swim = fmc as SwimMC;
                }
                if (fmc is TurnLeftMC)
                {
                    this.turn = fmc as TurnLeftMC;
                }
                this.currentMC = fmc.ToString();
            }
            else
            {
                this.currentMC = "None";
            }
        }
 protected void InitActivations()
 {
     this.smc = new SwimMC();
     this.lmc = new TurnLeftMC();
     this.rmc = new TurnRightMC();
 }