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 UpdateMotorController(FishSimulator.Delta delta) { var behaviorRoutine = this.GenerateBehaviorRoutine(this.brain.CurrentIntension, this.perception); foreach (var mc in behaviorRoutine.ToMC()) { if (mc is MuscleMC) { var mmc = mc as MuscleMC; if (this.muscleMCs.Count > 1) { this.muscleMCs.RemoveLast(); } this.muscleMCs.AddLast(mmc); } if (mc is BalanceMC) { this.balanceMC = mc as BalanceMC; } } this.ApplyBehaviorRoutine(delta); }